Skip to content

armgit / txtai

Public Imported from GitHub
0

💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows

Fix incompatibility with ONNX models and transformers>=4.41.0, closes #720

davidmezzettic4080a348a2f
diff --git a/src/python/txtai/models/onnx.py b/src/python/txtai/models/onnx.py
index 5c2ea0c9..4abba63a 100644
--- a/src/python/txtai/models/onnx.py
+++ b/src/python/txtai/models/onnx.py
@@ -48,6 +48,17 @@ class OnnxModel(PreTrainedModel):
# Add references for this class to supported AutoModel classes
Registry.register(self)
+ @property
+ def device(self):
+ """
+ Returns model device id.
+
+ Returns:
+ model device id
+ """
+
+ return -1
+
def providers(self):
"""
Returns a list of available and usable providers.
diff --git a/test/python/testpipeline/testonnx.py b/test/python/testpipeline/testonnx.py
index 15e76db7..3658d64a 100644
--- a/test/python/testpipeline/testonnx.py
+++ b/test/python/testpipeline/testonnx.py
@@ -13,6 +13,7 @@ from sklearn.linear_model import LogisticRegression
from sklearn.pipeline import Pipeline
from txtai.embeddings import Embeddings
+from txtai.models import OnnxModel
from txtai.pipeline import HFOnnx, HFTrainer, Labels, MLOnnx, Questions
@@ -41,6 +42,9 @@ class TestOnnx(unittest.TestCase):
# Validate model has data
self.assertGreater(len(model), 0)
+ # Validate model device properly works
+ self.assertEqual(OnnxModel(model).device, -1)
+
def testClassification(self):
"""
Test exporting a classification model to ONNX and running inference