claude_refactor_v2: temp changes before src changes

This commit is contained in:
pikaliov
2026-04-29 11:55:38 +03:00
parent 0d8c82acc3
commit 5c48b6c8fd
14 changed files with 1461 additions and 0 deletions

79
src/conf/training_conf.py Normal file
View File

@@ -0,0 +1,79 @@
from __future__ import annotations
import gin
@gin.configurable
class TrainingConfig:
"""Training recipe: loss + optimizer + sampler.
These three move together when you tune learning. Changing tau usually
pairs with changing lr; switching sampler_type usually pairs with
re-tuning loss weights. Keeping them in one config matches the actual
workflow of running ablations.
"""
def __init__(
self,
# --- Loss ---
loss_type: str = "symmetric",
tau_init: float = 0.07,
tau_min: float = 0.01,
tau_max: float = 0.1,
learnable_temperature: bool = True,
label_smoothing: float = 0.1,
weight_q2g: float = 0.6,
weight_g2q: float = 0.4,
hard_mining_k: int = 0,
neg_bank_size: int = 0,
# --- Optimizer ---
learning_rate: float = 1e-4,
text_lr_factor: float = 0.1,
stripnet_backbone_lr_factor: float = 0.1,
weight_decay: float = 1e-4,
grad_clip: float = 1.0,
# --- Sampler ---
sampler_type: str = "mutex",
dss_warmup_epochs: int = 1,
dss_reembed_every: int = 1,
dss_knn_device: str = "cuda",
dss_use_lsh: bool = False,
dss_lsh_num_tables: int = 8,
dss_lsh_num_bits: int = 14,
dss_cache_dir: str | None = None,
) -> None:
# Loss.
self.loss_type = loss_type
self.tau_init = tau_init
self.tau_min = tau_min
self.tau_max = tau_max
self.learnable_temperature = learnable_temperature
self.label_smoothing = label_smoothing
self.weight_q2g = weight_q2g
self.weight_g2q = weight_g2q
self.hard_mining_k = hard_mining_k
self.neg_bank_size = neg_bank_size
# Optimizer.
self.learning_rate = learning_rate
self.text_lr_factor = text_lr_factor
self.stripnet_backbone_lr_factor = stripnet_backbone_lr_factor
self.weight_decay = weight_decay
self.grad_clip = grad_clip
# Sampler.
self.sampler_type = sampler_type
self.dss_warmup_epochs = dss_warmup_epochs
self.dss_reembed_every = dss_reembed_every
self.dss_knn_device = dss_knn_device
self.dss_use_lsh = dss_use_lsh
self.dss_lsh_num_tables = dss_lsh_num_tables
self.dss_lsh_num_bits = dss_lsh_num_bits
self.dss_cache_dir = dss_cache_dir
def get_training_cfg(path2cfg: str) -> TrainingConfig:
"""Load ONLY training config (TESTING ONLY — use load_all_configs in production)."""
gin.clear_config()
gin.parse_config_file(f"{path2cfg}training.gin")
return TrainingConfig()