Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
matrix:
os: [ubuntu-latest]
python: ['3.10', '3.11', '3.12', '3.13']
transformers: ['4.48.3', '4.51.3', '4.52.4', '4.53.3', '4.55.4', '4.56.0', 'main']
transformers: ['4.48.3', '4.51.3', '4.52.4', '4.53.3', '4.55.4', '4.56.1', 'main']
torch: ['2.8', 'main']
exclude:
- python: '3.10'
Expand All @@ -30,7 +30,7 @@ jobs:
- python: '3.10'
transformers: '4.55.4'
- python: '3.10'
transformers: '4.56.0'
transformers: '4.56.1'
- python: '3.11'
torch: 'main'
- python: '3.11'
Expand All @@ -40,7 +40,7 @@ jobs:
- python: '3.11'
transformers: '4.55.4'
- python: '3.11'
transformers: '4.56.0'
transformers: '4.56.1'
- python: '3.13'
torch: '2.8'
- python: '3.13'
Expand Down
36 changes: 36 additions & 0 deletions _unittests/ut_tasks/try_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,42 @@ def test_imagetext2text_generation_zai_glm(self):
)
print(output_text)

@never_test()
def test_sentence_similary_alibaba_nlp_gte(self):
"""
clear&&NEVERTEST=1 python _unittests/ut_tasks/try_tasks.py -k alibaba
"""
import torch.nn.functional as F
from transformers import AutoModel, AutoTokenizer

input_texts = [
"what is the capital of China?",
"how to implement quick sort in python?",
"Beijing",
"sorting algorithms",
]

model_path = "Alibaba-NLP/gte-large-en-v1.5"
tokenizer = AutoTokenizer.from_pretrained(model_path)
model = AutoModel.from_pretrained(model_path, trust_remote_code=True)

# Tokenize the input texts
batch_dict = tokenizer(
input_texts, max_length=8192, padding=True, truncation=True, return_tensors="pt"
)

print("-- type:", type(model))
print("-- subclasses:", type(model).__subclasses__())
print("-- inputs:", self.string_type(batch_dict, with_shape=True))
outputs = model(**batch_dict)
print("-- outputs:", self.string_type(outputs, with_shape=True))
embeddings = outputs.last_hidden_state[:, 0]

# (Optionally) normalize embeddings
embeddings = F.normalize(embeddings, p=2, dim=1)
scores = (embeddings[:1] @ embeddings[1:].T) * 100
print(scores.tolist())


if __name__ == "__main__":
unittest.main(verbosity=2)
8 changes: 8 additions & 0 deletions onnx_diagnostic/helpers/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,14 @@ def string_type(
return f"{obj.__class__.__name__}(**{s})"
if obj.__class__.__name__ in {"TorchModelContainer", "InferenceSession"}:
return f"{obj.__class__.__name__}(...)"
if obj.__class__.__name__ == "Results":
import ultralytics

assert isinstance(
obj, ultralytics.engine.results.Results
), f"Unexpected type={type(obj)}"
return f"ultralytics.{obj.__class__.__name__}(...)"

if verbose:
print(f"[string_type] END:{type(obj)}")
raise AssertionError(f"Unsupported type {type(obj).__name__!r} - {type(obj)}")
Expand Down
14 changes: 12 additions & 2 deletions onnx_diagnostic/helpers/torch_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,9 +721,10 @@ def to_any(value: Any, to_value: Union[torch.dtype, torch.device, str]) -> Any:
return {to_any(t, to_value) for t in value}
if type(value) is dict:
return {k: to_any(t, to_value) for k, t in value.items()}
if value.__class__.__name__ == "DynamicCache":
if value.__class__.__name__ in {"DynamicCache", "HybridCache"}:
make = dict(DynamicCache=make_dynamic_cache, HybridCache=make_hybrid_cache)
cc = CacheKeyValue(value)
return make_dynamic_cache(
return make[value.__class__.__name__]( # type: ignore[operator]
list(
zip(
[t.to(to_value) if t is not None else t for t in cc.key_cache],
Expand Down Expand Up @@ -822,6 +823,15 @@ def torch_deepcopy(value: Any) -> Any:
new_args = torch_deepcopy(args)
return torch.utils._pytree.tree_unflatten(new_args, spec)

if value.__class__.__name__ == "Results":
import copy
import ultralytics

assert isinstance(
value, ultralytics.engine.results.Results
), f"Unexpected type={type(value)}"
return copy.deepcopy(value)

# We should have a code using serialization, deserialization assuming a model
# cannot be exported without them.
raise NotImplementedError(f"torch_deepcopy not implemented for type {type(value)}")
Expand Down
2 changes: 2 additions & 0 deletions onnx_diagnostic/torch_models/hghub/hub_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"""
architecture,task
ASTModel,feature-extraction
AutoencoderKL,image-to-image
AlbertModel,feature-extraction
BeitForImageClassification,image-classification
BartForConditionalGeneration,summarization
Expand Down Expand Up @@ -154,6 +155,7 @@
Wav2Vec2ForCTC,automatic-speech-recognition
YolosForObjectDetection,object-detection
YolosModel,image-feature-extraction
Alibaba-NLP/gte-large-en-v1.5,sentence-similarity
emilyalsentzer/Bio_ClinicalBERT,fill-mask"""
)

Expand Down
Loading
Loading