Skip to content

Commit 14f9576

Browse files
voorhsclaude
andcommitted
fix(deps): address review findings on transformers v5 migration
- Bump sentence-transformers lower bound 5.2.0 → 5.4.0. The new ranker / embedder paths (cross_encoder[0] subscript, sentence_transformers. sentence_transformer subpackage, get_embedding_dimension) all landed in 5.4.0; the previous floor would have ModuleNotFoundError'd / AttributeError'd anyone resolving 5.2.x–5.3.x. - Constrain EmbedderFineTuningConfig.warmup_ratio to (0, 1). v5 TrainingArguments interprets warmup_steps>=1 as a raw step count and <1 as a fraction, so a stray warmup_ratio=1.0 would silently produce one warmup step instead of full-training warmup. - Refresh tests/test_deps.py synthetic metadata fixtures to v5 version strings so the resolver tests exercise the version range we ship, not the v4 range we just left behind. - Trim the v4→v5 narrating comments down to the WHY of the current code; per-line migration history belongs in the commit log. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 2b5ea8f commit 14f9576

5 files changed

Lines changed: 12 additions & 15 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ dependencies = [
5252
catboost = ["catboost (>=1.2.8,<2.0.0)"]
5353
peft = ["peft (>= 0.10.0, !=0.15.0, !=0.15.1, <1.0.0)"]
5454
transformers = ["transformers[torch] (>=5.0.0,<6.0.0)"]
55-
sentence-transformers = ["sentence-transformers (>=5.2.0,<6.0.0)"]
55+
sentence-transformers = ["sentence-transformers (>=5.4.0,<6.0.0)"]
5656
dspy = [
5757
"dspy (>=2.6.5,<3.0.0)",
5858
]

src/autointent/_wrappers/embedder/sentence_transformers.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,7 @@ def train(self, utterances: list[str], labels: ListOfLabels, config: EmbedderFin
323323
per_device_train_batch_size=config.batch_size,
324324
per_device_eval_batch_size=config.batch_size,
325325
learning_rate=config.learning_rate,
326-
# transformers v5 deprecated `warmup_ratio` in favor of `warmup_steps`,
327-
# which now accepts a float < 1.0 as a fraction of total training steps.
326+
# warmup_steps accepts a float < 1 as a fraction of total steps.
328327
warmup_steps=config.warmup_ratio,
329328
fp16=config.fp16,
330329
bf16=config.bf16,

src/autointent/_wrappers/ranker.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,8 @@ def __init__(
136136
if classifier_head is not None or self.config.train_head:
137137
self._train_head = True
138138
self._activations_list: list[npt.NDArray[Any]] = []
139-
# sentence-transformers v5 restructured CrossEncoder into a nn.Sequential
140-
# of modules: cross_encoder[0] is a Transformer wrapping the underlying
141-
# AutoModelForSequenceClassification (exposed as .auto_model). The
142-
# classifier head still lives on that HF model.
139+
# CrossEncoder is a nn.Sequential of modules; [0] is the Transformer
140+
# wrapping the HF model exposed as .auto_model.
143141
self._hook_handler = self.cross_encoder[0].auto_model.classifier.register_forward_hook(
144142
self._classifier_hook
145143
)
@@ -317,9 +315,6 @@ def load(cls, path: Path, override_config: CrossEncoderConfig | None = None) ->
317315

318316
def clear_ram(self) -> None:
319317
"""Clear model from RAM and GPU memory."""
320-
# sentence-transformers v5 CrossEncoder is itself a nn.Sequential, so we
321-
# call .cpu() on the wrapper directly instead of the (now-absent)
322-
# underlying `.model` attribute.
323318
self.cross_encoder.cpu()
324319
del self.cross_encoder
325320
gc.collect()

src/autointent/configs/_transformers.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ class EmbedderFineTuningConfig(BaseModel):
2828
batch_size: int
2929
margin: float = Field(default=0.5)
3030
learning_rate: float = Field(default=2e-5)
31-
warmup_ratio: float = Field(default=0.1)
31+
# Fed to TrainingArguments.warmup_steps in v5, which interprets float<1 as
32+
# a fraction of total steps and float>=1 as a raw step count. Restrict to
33+
# (0, 1) so warmup_ratio=1.0 doesn't silently become a single step.
34+
warmup_ratio: float = Field(default=0.1, gt=0, lt=1)
3235
early_stopping_patience: int = Field(default=1)
3336
early_stopping_threshold: float = Field(default=0.0)
3437
val_fraction: float = Field(default=0.2)

tests/test_deps.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def test_resolve_recurses_into_nested_extra(monkeypatch: pytest.MonkeyPatch) ->
104104
_patch_metadata(
105105
monkeypatch,
106106
{
107-
"autointent": ["transformers[torch]>=4.49.0,<5.0.0 ; extra == 'transformers'"],
107+
"autointent": ["transformers[torch]>=5.0.0,<6.0.0 ; extra == 'transformers'"],
108108
"transformers": [
109109
"torch>=2.2 ; extra == 'torch'",
110110
"accelerate>=0.26.0 ; extra == 'torch'",
@@ -180,13 +180,13 @@ def test_require_detects_missing_nested_accelerate(monkeypatch: pytest.MonkeyPat
180180
_patch_metadata(
181181
monkeypatch,
182182
{
183-
"autointent": ["transformers[torch]>=4.49.0,<5.0.0 ; extra == 'transformers'"],
183+
"autointent": ["transformers[torch]>=5.0.0,<6.0.0 ; extra == 'transformers'"],
184184
"transformers": [
185185
"torch>=2.2 ; extra == 'torch'",
186186
"accelerate>=0.26.0 ; extra == 'torch'",
187187
],
188188
},
189-
{"transformers": "4.49.0", "torch": "2.2.0"}, # accelerate absent
189+
{"transformers": "5.0.0", "torch": "2.2.0"}, # accelerate absent
190190
)
191191
with pytest.raises(ImportError) as exc:
192192
deps.require("transformers")
@@ -200,7 +200,7 @@ def test_require_reports_extra_package_entirely_missing(monkeypatch: pytest.Monk
200200
# `transformers[torch]` requirement is flagged as missing with the install hint.
201201
_patch_metadata(
202202
monkeypatch,
203-
{"autointent": ["transformers[torch]>=4.49.0,<5.0.0 ; extra == 'transformers'"]},
203+
{"autointent": ["transformers[torch]>=5.0.0,<6.0.0 ; extra == 'transformers'"]},
204204
{}, # transformers (and everything else) absent
205205
)
206206
with pytest.raises(ImportError) as exc:

0 commit comments

Comments
 (0)