New `hard_mining_k` parameter on InfoNCELoss. When >0 and queue is non-empty, each query row keeps only its K highest-similarity queue entries (via `torch.topk`) as negatives, instead of the full queue. Fully vectorized — no Python loop, no extra forward pass. Rationale: the memory bank grows to 4096 detached gallery embeddings, but most are easy negatives that contribute almost nothing to the gradient. Hard mining focuses compute on the small subset that actually shapes the decision boundary. +2-3% R@1 in similar contrastive setups. Edge cases: - K=0: mining disabled, full queue used (original behavior). - K >= queue size: falls back to full queue (e.g. warmup when queue is small). - Queue empty: in-batch only, no changes. Default in `gtauav_balanced.gin`: K=512 (1/8 of queue). Smoke-train updated to exercise the full memory-bank + mining path. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
60 lines
1.9 KiB
Plaintext
60 lines
1.9 KiB
Plaintext
# GTA-UAV Balanced: Asymmetric DINOv3 (WEB+SAT) with L1/L2/L3 captions.
|
|
# Symmetric InfoNCE + MutuallyExclusiveSampler (no false negatives).
|
|
# 10 epochs, MONA all 24 blocks, 1024-dim retrieval, hard negative bank.
|
|
|
|
import src.losses.multi_infonce
|
|
|
|
# ---- Training ----
|
|
TrainConfigGTAUAV.epochs = 10
|
|
TrainConfigGTAUAV.batch_size = 8
|
|
TrainConfigGTAUAV.num_workers = 4
|
|
TrainConfigGTAUAV.learning_rate = 1e-4
|
|
TrainConfigGTAUAV.text_lr_factor = 0.1
|
|
TrainConfigGTAUAV.weight_decay = 1e-4
|
|
TrainConfigGTAUAV.grad_clip = 1.0
|
|
TrainConfigGTAUAV.grad_accum_steps = 8
|
|
TrainConfigGTAUAV.use_amp = True
|
|
TrainConfigGTAUAV.eval_every = 1
|
|
TrainConfigGTAUAV.warmup_epochs = 2
|
|
TrainConfigGTAUAV.seed = 42
|
|
TrainConfigGTAUAV.device = "cuda"
|
|
|
|
# ---- Model ----
|
|
TrainConfigGTAUAV.init_gate = 0.7
|
|
TrainConfigGTAUAV.baseline_mode = False
|
|
TrainConfigGTAUAV.shared_encoder = False
|
|
TrainConfigGTAUAV.gradient_checkpointing = True
|
|
|
|
# ---- Loss ----
|
|
TrainConfigGTAUAV.loss_type = "symmetric"
|
|
TrainConfigGTAUAV.tau_init = 0.07
|
|
TrainConfigGTAUAV.label_smoothing = 0.1
|
|
TrainConfigGTAUAV.learnable_temperature = True
|
|
TrainConfigGTAUAV.weight_q2g = 0.6
|
|
TrainConfigGTAUAV.weight_g2q = 0.4
|
|
TrainConfigGTAUAV.neg_bank_size = 4096
|
|
|
|
# ---- Sampling ----
|
|
TrainConfigGTAUAV.use_mutex_sampler = True
|
|
|
|
# ---- Output ----
|
|
TrainConfigGTAUAV.output_dir = "out/gtauav/with_text"
|
|
|
|
# ---- Tracking ----
|
|
TrainConfigGTAUAV.use_wandb = False
|
|
TrainConfigGTAUAV.use_tb = True
|
|
TrainConfigGTAUAV.use_gradcam = True
|
|
TrainConfigGTAUAV.gradcam_every = 5
|
|
TrainConfigGTAUAV.use_profiler = False
|
|
TrainConfigGTAUAV.log_grad_norms = True
|
|
|
|
# ---- InfoNCELoss (gin-configurable) ----
|
|
InfoNCELoss.temperature_init = 0.07
|
|
InfoNCELoss.learnable_temperature = True
|
|
InfoNCELoss.label_smoothing = 0.1
|
|
InfoNCELoss.weight_q2g = 0.6
|
|
InfoNCELoss.weight_g2q = 0.4
|
|
InfoNCELoss.tau_min = 0.01
|
|
InfoNCELoss.tau_max = 0.1
|
|
InfoNCELoss.hard_mining_k = 512 # 0 = use whole queue (disable mining)
|