Skip to content

Revert changes to multi-GPU evaluator calls#3463

Merged
tomaarsen merged 2 commits into
huggingface:masterfrom
tomaarsen:revert/eval_on_one_gpu
Jul 25, 2025
Merged

Revert changes to multi-GPU evaluator calls#3463
tomaarsen merged 2 commits into
huggingface:masterfrom
tomaarsen:revert/eval_on_one_gpu

Conversation

@tomaarsen

Copy link
Copy Markdown
Member

Hello!

Pull Request overview

  • Revert changes to multi-GPU evaluator calls

Details

Reverts part of #3442. According to experiments by @arthurbr11, this introduced a crash. I haven't had a chance to test it myself yet, will do so later.

cc @NohTow

  • Tom Aarsen

@NohTow

NohTow commented Jul 25, 2025

Copy link
Copy Markdown
Contributor

happy to discuss to find better solutions!

@tomaarsen

Copy link
Copy Markdown
Member Author

This is the crux of the error at the moment:

Traceback (most recent call last):
  File "[...]/splade/train_multi_gpu_eval_test.py", line 158, in <module>
    main()
  File "[...]/splade/train_multi_gpu_eval_test.py", line 136, in main
    trainer.train()
  File "[...]/lib/python3.10/site-packages/transformers/trainer.py", line 2240, in train
    return inner_training_loop(
  File "[...]/lib/python3.10/site-packages/transformers/trainer.py", line 2622, in _inner_training_loop
    self._maybe_log_save_evaluate(
  File "[...]/lib/python3.10/site-packages/transformers/trainer.py", line 3096, in _maybe_log_save_evaluate
    is_new_best_metric = self._determine_best_metric(metrics=metrics, trial=trial)
  File "[...]/lib/python3.10/site-packages/transformers/trainer.py", line 3166, in _determine_best_metric
    raise KeyError(
KeyError: "The `metric_for_best_model` training argument is set to 'eval_NanoBEIR_mean_dot_ndcg@10', which is not found in the evaluation metrics. The available evaluation metrics are: [...]. Consider changing the `metric_for_best_model` via the TrainingArguments."

In short, each individual device seems to check for the best metric deep in transformers for some reason (I'd think that only the first device has to do that), so it's incompatible with metric_for_best_model.

The best solution is full multi-GPU evaluation support, and the second best is merging this PR so that all GPUs evaluate again (even if that's mostly a waste of GPU time). I'll merge this now to avoid the master from being broken in this setting.

  • Tom Aarsen

@tomaarsen
tomaarsen marked this pull request as ready for review July 25, 2025 08:01
@tomaarsen
tomaarsen requested a review from Copilot July 25, 2025 08:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR reverts changes to multi-GPU evaluator calls that were introduced in PR #3442, which reportedly caused crashes during experiments. The main purpose is to restore the previous behavior by re-adding a logging suppression mechanism for non-primary processes during evaluation.

Key changes:

  • Adds back the disable_logging context manager utility function
  • Restores conditional logging suppression for non-primary processes during evaluation
  • Reverts the evaluator execution condition to run on all processes instead of only the primary process

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
sentence_transformers/util/misc.py Adds the disable_logging context manager function
sentence_transformers/util/init.py Exports the disable_logging function
sentence_transformers/trainer.py Reverts evaluator execution logic and adds logging suppression for non-primary processes

Comment thread sentence_transformers/trainer.py
@tomaarsen
tomaarsen merged commit 2f4041b into huggingface:master Jul 25, 2025
7 of 9 checks passed
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.

3 participants