Skip to content

Commit bf2fe03

Browse files
authored
4.53.0 Transformers Pin (#421)
* higher transfomers pin * unit tests fix
1 parent aa1bb58 commit bf2fe03

File tree

5 files changed

+17
-4
lines changed

5 files changed

+17
-4
lines changed

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
spacy>=3.5.0,<4.1.0
22
numpy>=1.15.0
3-
transformers[sentencepiece]>=3.4.0,<4.42.0
3+
transformers[sentencepiece]>=3.4.0,<4.53.3
44
torch>=1.8.0
55
srsly>=2.4.0,<3.0.0
66
dataclasses>=0.6,<1.0; python_version < "3.7"

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ install_requires =
3333
spacy>=3.5.0,<4.1.0
3434
numpy>=1.15.0; python_version < "3.9"
3535
numpy>=1.19.0; python_version >= "3.9"
36-
transformers>=3.4.0,<4.50.0
36+
transformers>=3.4.0,< 4.53.3
3737
torch>=1.8.0
3838
srsly>=2.4.0,<3.0.0
3939
dataclasses>=0.6,<1.0; python_version < "3.7"

spacy_transformers/tests/regression/test_spacy_issue6401.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,8 @@ def test_transformer_pipeline_textcat():
6666
nlp2 = spacy.load(file_path)
6767
doc2 = nlp2("We're interested at underwater basket weaving.")
6868
cats2 = doc2.cats
69-
assert cats1 == cats2
69+
# Compare floating point values with tolerance for small numerical differences
70+
assert len(cats1) == len(cats2)
71+
for key in cats1:
72+
assert key in cats2
73+
assert abs(cats1[key] - cats2[key]) < 1e-5, f"Values for '{key}' differ: {cats1[key]} vs {cats2[key]}"

spacy_transformers/tests/test_serialize.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ def test_transformer_pipeline_todisk_settings():
141141
# clobbered, so do both for this test
142142
trf.model.tokenizer.model_max_length = 499
143143
# add attentions on-the-fly
144+
# Need to set attn_implementation to "eager" to support output_attentions=True
145+
trf.model.transformer.config._attn_implementation = "eager"
144146
trf.model.transformer.config.output_attentions = True
145147
assert nlp("test")._.trf_data.model_output.attentions is not None
146148
with make_tempdir() as d:

spacy_transformers/tests/util.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,14 @@ def _assert_equal_tensors(tensors1, tensors2):
1818
for i in range(len(tensors1)):
1919
t1 = ops.asarray(tensors1[i])
2020
t2 = ops.asarray(tensors2[i])
21-
assert_array_equal(ops.to_numpy(t1), ops.to_numpy(t2))
21+
# Use assert_allclose for floating point comparison with tolerance
22+
# to handle tiny numerical differences between runs
23+
numpy.testing.assert_allclose(
24+
ops.to_numpy(t1),
25+
ops.to_numpy(t2),
26+
rtol=1e-4,
27+
atol=1e-5
28+
)
2229

2330

2431
class DummyTokenizer:

0 commit comments

Comments
 (0)