Skip to content

Commit

Permalink
[warn] Throw a warning if compute_metrics is set, as it's not used (#…
Browse files Browse the repository at this point in the history
…3002)

* Throw a warning if compute_metrics is set, as it's not used

* Remove "this will become a fatal error"

* Remove unneeded comma
  • Loading branch information
tomaarsen authored Oct 21, 2024
1 parent dc79f13 commit a028b58
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions sentence_transformers/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import logging
import os
import warnings
from collections import OrderedDict
from contextlib import nullcontext
from typing import TYPE_CHECKING, Any, Callable
Expand Down Expand Up @@ -156,14 +155,19 @@ def __init__(
raise RuntimeError("`Trainer` requires either a `model` or `model_init` argument")
else:
if model_init is not None:
warnings.warn(
logger.warning(
"`Trainer` requires either a `model` or `model_init` argument, but not both. `model_init` will"
" overwrite your model when calling the `train` method. This will become a fatal error in the next"
" release.",
FutureWarning,
" overwrite your model when calling the `train` method."
)
self.model_init = model_init

if compute_metrics is not None:
logger.warning(
"`compute_metrics` is currently not compatible with the SentenceTransformerTrainer. Please use the "
"`evaluator` argument instead for detailed evaluation metrics, or the `eval_dataset` argument for "
"the evaluation loss."
)

# Get a dictionary of the default training arguments, so we can determine which arguments have been changed
# for the model card
default_args_dict = SentenceTransformerTrainingArguments(output_dir="unused").to_dict()
Expand Down

0 comments on commit a028b58

Please sign in to comment.