abtonmoy commited on
Commit
d46e9f5
·
verified ·
1 Parent(s): 35e98a2

inference: prefer model.safetensors

Browse files
Files changed (1) hide show
  1. inference.py +12 -7
inference.py CHANGED
@@ -164,14 +164,19 @@ class K3VisionEmbedder:
164
  return cls(repo_or_path, device=device, **kw)
165
  from huggingface_hub import hf_hub_download
166
  from huggingface_hub.utils import EntryNotFoundError
167
- try: # prefer safetensors
168
- path = hf_hub_download(repo_or_path, "k3vit2fe2_proj.safetensors", revision=revision)
 
 
 
 
169
  try:
170
- hf_hub_download(repo_or_path, "config.json", revision=revision) # sibling config
171
- except Exception: # noqa: BLE001
172
- pass
173
- except EntryNotFoundError:
174
- path = hf_hub_download(repo_or_path, "k3vit2fe2_proj.pt", revision=revision)
 
175
  return cls(path, device=device, **kw)
176
 
177
  @torch.no_grad()
 
164
  return cls(repo_or_path, device=device, **kw)
165
  from huggingface_hub import hf_hub_download
166
  from huggingface_hub.utils import EntryNotFoundError
167
+ try:
168
+ hf_hub_download(repo_or_path, "config.json", revision=revision) # sibling config
169
+ except Exception: # noqa: BLE001
170
+ pass
171
+ path = None
172
+ for name in ("model.safetensors", "k3vit2fe2_proj.safetensors", "k3vit2fe2_proj.pt"):
173
  try:
174
+ path = hf_hub_download(repo_or_path, name, revision=revision)
175
+ break
176
+ except EntryNotFoundError:
177
+ continue
178
+ if path is None:
179
+ raise FileNotFoundError(f"no projector checkpoint found in {repo_or_path}")
180
  return cls(path, device=device, **kw)
181
 
182
  @torch.no_grad()