Skip to content

fix: handle INFONCE_HARD_NEGATIVES as integer if provided #4545

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 10, 2025

Conversation

dlutwy
Copy link
Contributor

@dlutwy dlutwy commented Jun 10, 2025

PR type

  • Bug Fix
  • New Feature
  • Document Updates
  • More Models or Datasets Support

PR information

在训练 GME Embedding 时,有可能需要在环境变量中提供 INFONCE_HARD_NEGATIVES。原本的代码遗漏了将其转换为 int 类型。

In the training of GME Embedding, it may be necessary to provide INFONCE_HARD_NEGATIVES via environment variables. The original code missed converting this value to an integer.


Experiment results

如果没有这段修改,在 validation 完成后计算 metrics 时将会报错:

If this modification is not included, an error will occur when computing metrics after validation:

[rank0]:     output = eval_loop(
[rank0]:   File "/home/tuozhi.wy/.conda/envs/gme/lib/python3.10/site-packages/transformers/trainer.py", line 4463, in evaluation_loop
[rank0]:     metrics = self.compute_metrics(
[rank0]:   File "/home/tuozhi.wy/.conda/envs/gme/lib/python3.10/site-packages/swift/trainers/trainers.py", line 75, in calculate_metric
[rank0]:     return calculate_infonce_metrics(eval_prediction.predictions, eval_prediction.label_ids)
[rank0]:   File "/home/tuozhi.wy/.conda/envs/gme/lib/python3.10/site-packages/swift/plugin/loss.py", line 173, in calculate_infonce_metrics
[rank0]:     split_tensors = _parse_multi_negative_sentences(torch.tensor(embeddings), torch.tensor(labels), hard_negatives)
[rank0]:   File "/home/tuozhi.wy/.conda/envs/gme/lib/python3.10/site-packages/swift/plugin/loss.py", line 255, in _parse_multi_negative_sentences
[rank0]:     if negatives > hard_negatives:
[rank0]: TypeError: '>' not supported between instances of 'int' and 'str'

@dlutwy
Copy link
Contributor Author

dlutwy commented Jun 10, 2025

#3019 来看,我想此处可以 @tastelikefeet

@tastelikefeet tastelikefeet merged commit 89fe048 into modelscope:main Jun 10, 2025
2 checks passed
@tastelikefeet
Copy link
Collaborator

感谢PR😁

@dlutwy dlutwy deleted the infonce_hard_negatives_fix branch June 10, 2025 08:25
Jintao-Huang pushed a commit that referenced this pull request Jun 13, 2025
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