Reduce AutoWeightsLoader kwargs (#53106)
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user