Skip to content

Commit 8b25d27

Browse files
voorhsclaude
andcommitted
fix(_bert): pin revision on transformers v5 PEFT adapter probe
When PEFT is installed, transformers v5 calls find_adapter_config_file on every AutoModelForSequenceClassification.from_pretrained. The auto_factory only propagates `_commit_hash` (used for the cache lookup) but NOT the outer `revision` to the fall-through hf_hub_download. On a cold cache — i.e. our CI warm-cache job, which populates model files but no negative marker for adapter_config.json — that probe fires `hf_hub_download(repo_id, adapter_config.json, revision=None)` and our test guard rightly flagged it as unpinned. Pass `adapter_kwargs={"revision": revision}` so the adapter probe inherits the pin. The first run still writes a `.no_exist` marker, but all subsequent runs (and CI's pinned-only contract) stay clean. Reproduces with: rm -rf ~/.cache/huggingface/hub/models--prajjwal1--bert-tiny/.no_exist then pytest tests/pipeline/test_inference.py::test_inference_from_config[multiclass]. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 35e6394 commit 8b25d27

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

src/autointent/modules/scoring/_bert.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,21 @@ def _initialize_model(self) -> Any: # noqa: ANN401
136136
label2id = {str(i): i for i in range(self._n_classes)}
137137
id2label = {i: str(i) for i in range(self._n_classes)}
138138

139+
# transformers v5 + PEFT triggers find_adapter_config_file on every
140+
# from_pretrained; it propagates _commit_hash for the cache lookup but
141+
# NOT the outer `revision` to the fall-through hf_hub_download
142+
# (auto_factory.py:308 only forwards adapter_kwargs). Set revision
143+
# explicitly via adapter_kwargs so the adapter probe stays pinned.
144+
revision = self.classification_model_config.revision
139145
return AutoModelForSequenceClassification.from_pretrained(
140146
self.classification_model_config.model_name,
141147
trust_remote_code=self.classification_model_config.trust_remote_code,
142-
revision=self.classification_model_config.revision,
148+
revision=revision,
143149
num_labels=self._n_classes,
144150
label2id=label2id,
145151
id2label=id2label,
146152
problem_type="multi_label_classification" if self._multilabel else "single_label_classification",
153+
adapter_kwargs={"revision": revision} if revision is not None else None,
147154
)
148155

149156
def fit(

0 commit comments

Comments
 (0)