propagate dtype to internal module when loading for inference

This commit is contained in:
electroglyph 2025-12-30 19:46:10 -08:00
commit 2e8340fddd

View file

@ -702,10 +702,28 @@ class FastSentenceTransformer(FastModel):
isinstance(st_device, str) and st_device in ["auto", "sequential"]
):
st_device = None
# this was added because when loading for inference it was defaulting to float32
# propagate dtype to model_kwargs, default to "auto"
model_kwargs = kwargs.get("model_kwargs", {})
model_kwargs["dtype"] = dtype if dtype is not None else "auto"
# filter kwargs for SentenceTransformer
st_kwargs = {
"device": st_device,
"trust_remote_code": trust_remote_code,
"token": token,
"revision": revision,
"model_kwargs": model_kwargs,
}
# add other known kwargs if present
known_keys = ["cache_folder", "truncate_dim", "tokenizer_kwargs", "config_kwargs"]
for k in known_keys:
if k in kwargs:
st_kwargs[k] = kwargs[k]
st_model = SentenceTransformer(
model_name, device = st_device, trust_remote_code = trust_remote_code
)
st_model = SentenceTransformer(model_name, **st_kwargs)
return st_model
if "auto_model" not in kwargs: