propagate dtype to internal module when loading for inference
This commit is contained in:
parent
10543ecf86
commit
2e8340fddd
1 changed files with 22 additions and 4 deletions
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue