Skip to content

fix: apply GROUP_BY_LABEL sampler for in-batch embedding losses - #644

Closed
tonycoder-hub wants to merge 1 commit into
huggingface:mainfrom
tonycoder-hub:cursor/fix-group-by-label-batch-sampler-1db7
Closed

fix: apply GROUP_BY_LABEL sampler for in-batch embedding losses#644
tonycoder-hub wants to merge 1 commit into
huggingface:mainfrom
tonycoder-hub:cursor/fix-group-by-label-batch-sampler-1db7

Conversation

@tonycoder-hub

Copy link
Copy Markdown

train_embeddings compared an instantiated loss module against loss classes, so loss in (BatchAllTripletLoss, ..., SupConLoss) was always False and GROUP_BY_LABEL never applied. Compare args.loss (the class) and reset the sampler between train() calls. Tests: python -m pytest tests/test_trainer.py -k batch_sampler or non_default_loss -v --no-cov -> 9 passed. Distinct from #643/#620/#579/#627.

`train_embeddings` compared the instantiated loss module against the loss
classes, so the condition never held and `BatchSamplers.GROUP_BY_LABEL` was
never applied. Compare `args.loss` instead, and reset the batch sampler to the
default for other losses so it does not leak between training calls.

Co-authored-by: Tony Coder <407243179@qq.com>
@tonycoder-hub

Copy link
Copy Markdown
Author

Closing as stale — opened on or before 2026-08-17 and still unmerged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants