abdoelsayed commited on
Commit
830ed92
·
verified ·
1 Parent(s): 895bd48

Load dense_branch.safetensors from the Hub when the model is given by repository id

Browse files
Files changed (1) hide show
  1. branched_transformer.py +10 -0
branched_transformer.py CHANGED
@@ -41,6 +41,16 @@ class BranchedTransformer(Transformer):
41
  if hasattr(module, "config"):
42
  module.config = model.config
43
  path = os.path.join(model_name_or_path, BRANCH_FILE)
 
 
 
 
 
 
 
 
 
 
44
  if os.path.exists(path):
45
  self.load_dense_branch(load_file(path))
46
 
 
41
  if hasattr(module, "config"):
42
  module.config = model.config
43
  path = os.path.join(model_name_or_path, BRANCH_FILE)
44
+ if not os.path.exists(path) and not os.path.isdir(model_name_or_path):
45
+ # a Hub repository id: the wrapped model's weights came from the Hub, so the dense branch must too
46
+ # (without it the dense top would silently stay a copy of the ColBERT top)
47
+ from huggingface_hub import hf_hub_download
48
+
49
+ hub = kwargs.get("model_args") or {}
50
+ path = hf_hub_download(model_name_or_path, BRANCH_FILE, subfolder=hub.get("subfolder") or None,
51
+ revision=hub.get("revision"), token=hub.get("token"),
52
+ cache_dir=kwargs.get("cache_dir"),
53
+ local_files_only=bool(hub.get("local_files_only", False)))
54
  if os.path.exists(path):
55
  self.load_dense_branch(load_file(path))
56