ndemirdemir commited on
Commit
cf5df64
·
verified ·
1 Parent(s): f78d5a7

Support anonymous and cached AutoModel loading

Browse files

Accept the matching authentication option Transformers forwards through adapter kwargs. Continue rejecting external adapter overrides. Model weights and inference computations are unchanged.

Files changed (1) hide show
  1. modeling_branchone.py +11 -2
modeling_branchone.py CHANGED
@@ -48,8 +48,17 @@ class BranchOneModel(PreTrainedModel):
48
  raise TypeError("BranchOne takes no positional model arguments")
49
  for key in ("_from_auto", "_commit_hash", "trust_remote_code"):
50
  kwargs.pop(key, None)
51
- if kwargs.pop("adapter_kwargs", None):
52
- raise ValueError("External adapter overrides are not supported")
 
 
 
 
 
 
 
 
 
53
  if kwargs.pop("subfolder", ""):
54
  raise ValueError("Load the root of the BranchOne model repository")
55
  if kwargs:
 
48
  raise TypeError("BranchOne takes no positional model arguments")
49
  for key in ("_from_auto", "_commit_hash", "trust_remote_code"):
50
  kwargs.pop(key, None)
51
+ adapter_kwargs = kwargs.pop("adapter_kwargs", None)
52
+ if adapter_kwargs:
53
+ # AutoModel copies its Hub authentication option here when PEFT is
54
+ # installed, including token=False for anonymous/offline loading.
55
+ # It does not select a different adapter; reject actual overrides.
56
+ if (
57
+ not isinstance(adapter_kwargs, dict)
58
+ or set(adapter_kwargs) != {"token"}
59
+ or adapter_kwargs["token"] != token
60
+ ):
61
+ raise ValueError("External adapter overrides are not supported")
62
  if kwargs.pop("subfolder", ""):
63
  raise ValueError("Load the root of the BranchOne model repository")
64
  if kwargs: