Reduce AutoWeightsLoader kwargs (#53106)

Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
This commit is contained in:
Harry Mellor
2026-08-20 15:40:11 +00:00
committed by GitHub
parent 2dd17225c6
commit 1fe3a1571a
84 changed files with 577 additions and 568 deletions
+5 -3
View File
@@ -147,19 +147,21 @@ class RobertaEmbeddingModel(BertEmbeddingModel):
def load_weights(self, weights: Iterable[tuple[str, torch.Tensor]]):
weights_list = list(weights)
orig_to_new_prefix: dict[str, str | None] = {"lm_head.": None}
has_roberta_prefix = any(
name.startswith("roberta.") for name, _ in weights_list
)
if has_roberta_prefix:
# For models with the `roberta.` prefix e.g.
# `FacebookAI/roberta-base`
mapper = WeightsMapper(orig_to_new_prefix={"roberta.": "model."})
orig_to_new_prefix["roberta."] = "model."
else:
# For models without the `roberta.` prefix e.g.
# `sentence-transformers/stsb-roberta-base-v2`
mapper = WeightsMapper(orig_to_new_prefix={"": "model."})
orig_to_new_prefix[""] = "model."
mapper = WeightsMapper(orig_to_new_prefix=orig_to_new_prefix)
loader = AutoWeightsLoader(self, skip_prefixes=["lm_head."])
loader = AutoWeightsLoader(self)
return loader.load_weights(weights_list, mapper=mapper)