diff --git a/sentence_transformers/trainer.py b/sentence_transformers/trainer.py index ef36d922f..b10083cb8 100644 --- a/sentence_transformers/trainer.py +++ b/sentence_transformers/trainer.py @@ -2,6 +2,7 @@ import logging import os +import warnings from collections import OrderedDict from contextlib import nullcontext from functools import partial @@ -497,6 +498,19 @@ def _load_best_model(self) -> None: if not isinstance(self.model[0], Transformer): logger.info("Could not load best model, as the model is not a `transformers`-based model.") return + + try: + if len(self.model[0].auto_model.active_adapters()): + warn_msg = "Could not load best model, as the model has at least one adapter set. Please wait for an update of the transformers library to enable this feature." + warnings.warn( + warn_msg, + UserWarning, # No need to import UserWarning; it's already available + stacklevel=2 + ) + logger.info(warn_msg) + return + except ValueError: + pass try: if checkpoint := self.state.best_model_checkpoint: