Skip to content

Commit 20e7f28

Browse files
authored
Switches to 4.56.1 and other changes (#216)
* switch to 4.56.1 and other changes * fix
1 parent a424179 commit 20e7f28

File tree

7 files changed

+249
-131
lines changed

7 files changed

+249
-131
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
matrix:
1717
os: [ubuntu-latest]
1818
python: ['3.10', '3.11', '3.12', '3.13']
19-
transformers: ['4.48.3', '4.51.3', '4.52.4', '4.53.3', '4.55.4', '4.56.0', 'main']
19+
transformers: ['4.48.3', '4.51.3', '4.52.4', '4.53.3', '4.55.4', '4.56.1', 'main']
2020
torch: ['2.8', 'main']
2121
exclude:
2222
- python: '3.10'
@@ -30,7 +30,7 @@ jobs:
3030
- python: '3.10'
3131
transformers: '4.55.4'
3232
- python: '3.10'
33-
transformers: '4.56.0'
33+
transformers: '4.56.1'
3434
- python: '3.11'
3535
torch: 'main'
3636
- python: '3.11'
@@ -40,7 +40,7 @@ jobs:
4040
- python: '3.11'
4141
transformers: '4.55.4'
4242
- python: '3.11'
43-
transformers: '4.56.0'
43+
transformers: '4.56.1'
4444
- python: '3.13'
4545
torch: '2.8'
4646
- python: '3.13'

_unittests/ut_tasks/try_tasks.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,42 @@ def test_imagetext2text_generation_zai_glm(self):
755755
)
756756
print(output_text)
757757

758+
@never_test()
759+
def test_sentence_similary_alibaba_nlp_gte(self):
760+
"""
761+
clear&&NEVERTEST=1 python _unittests/ut_tasks/try_tasks.py -k alibaba
762+
"""
763+
import torch.nn.functional as F
764+
from transformers import AutoModel, AutoTokenizer
765+
766+
input_texts = [
767+
"what is the capital of China?",
768+
"how to implement quick sort in python?",
769+
"Beijing",
770+
"sorting algorithms",
771+
]
772+
773+
model_path = "Alibaba-NLP/gte-large-en-v1.5"
774+
tokenizer = AutoTokenizer.from_pretrained(model_path)
775+
model = AutoModel.from_pretrained(model_path, trust_remote_code=True)
776+
777+
# Tokenize the input texts
778+
batch_dict = tokenizer(
779+
input_texts, max_length=8192, padding=True, truncation=True, return_tensors="pt"
780+
)
781+
782+
print("-- type:", type(model))
783+
print("-- subclasses:", type(model).__subclasses__())
784+
print("-- inputs:", self.string_type(batch_dict, with_shape=True))
785+
outputs = model(**batch_dict)
786+
print("-- outputs:", self.string_type(outputs, with_shape=True))
787+
embeddings = outputs.last_hidden_state[:, 0]
788+
789+
# (Optionally) normalize embeddings
790+
embeddings = F.normalize(embeddings, p=2, dim=1)
791+
scores = (embeddings[:1] @ embeddings[1:].T) * 100
792+
print(scores.tolist())
793+
758794

759795
if __name__ == "__main__":
760796
unittest.main(verbosity=2)

onnx_diagnostic/helpers/helper.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,14 @@ def string_type(
774774
return f"{obj.__class__.__name__}(**{s})"
775775
if obj.__class__.__name__ in {"TorchModelContainer", "InferenceSession"}:
776776
return f"{obj.__class__.__name__}(...)"
777+
if obj.__class__.__name__ == "Results":
778+
import ultralytics
779+
780+
assert isinstance(
781+
obj, ultralytics.engine.results.Results
782+
), f"Unexpected type={type(obj)}"
783+
return f"ultralytics.{obj.__class__.__name__}(...)"
784+
777785
if verbose:
778786
print(f"[string_type] END:{type(obj)}")
779787
raise AssertionError(f"Unsupported type {type(obj).__name__!r} - {type(obj)}")

onnx_diagnostic/helpers/torch_helper.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -721,9 +721,10 @@ def to_any(value: Any, to_value: Union[torch.dtype, torch.device, str]) -> Any:
721721
return {to_any(t, to_value) for t in value}
722722
if type(value) is dict:
723723
return {k: to_any(t, to_value) for k, t in value.items()}
724-
if value.__class__.__name__ == "DynamicCache":
724+
if value.__class__.__name__ in {"DynamicCache", "HybridCache"}:
725+
make = dict(DynamicCache=make_dynamic_cache, HybridCache=make_hybrid_cache)
725726
cc = CacheKeyValue(value)
726-
return make_dynamic_cache(
727+
return make[value.__class__.__name__]( # type: ignore[operator]
727728
list(
728729
zip(
729730
[t.to(to_value) if t is not None else t for t in cc.key_cache],
@@ -822,6 +823,15 @@ def torch_deepcopy(value: Any) -> Any:
822823
new_args = torch_deepcopy(args)
823824
return torch.utils._pytree.tree_unflatten(new_args, spec)
824825

826+
if value.__class__.__name__ == "Results":
827+
import copy
828+
import ultralytics
829+
830+
assert isinstance(
831+
value, ultralytics.engine.results.Results
832+
), f"Unexpected type={type(value)}"
833+
return copy.deepcopy(value)
834+
825835
# We should have a code using serialization, deserialization assuming a model
826836
# cannot be exported without them.
827837
raise NotImplementedError(f"torch_deepcopy not implemented for type {type(value)}")

onnx_diagnostic/torch_models/hghub/hub_data.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"""
1212
architecture,task
1313
ASTModel,feature-extraction
14+
AutoencoderKL,image-to-image
1415
AlbertModel,feature-extraction
1516
BeitForImageClassification,image-classification
1617
BartForConditionalGeneration,summarization
@@ -154,6 +155,7 @@
154155
Wav2Vec2ForCTC,automatic-speech-recognition
155156
YolosForObjectDetection,object-detection
156157
YolosModel,image-feature-extraction
158+
Alibaba-NLP/gte-large-en-v1.5,sentence-similarity
157159
emilyalsentzer/Bio_ClinicalBERT,fill-mask"""
158160
)
159161

0 commit comments

Comments
 (0)