30
30
from optimum .exporters .onnx import MODEL_TYPES_REQUIRING_POSITION_IDS
31
31
from optimum .intel import (
32
32
IPEXModel ,
33
+ IPEXModelForAudioClassification ,
33
34
IPEXModelForCausalLM ,
35
+ IPEXModelForImageClassification ,
36
+ IPEXModelForMaskedLM ,
34
37
IPEXModelForQuestionAnswering ,
35
38
IPEXModelForSequenceClassification ,
36
39
IPEXModelForTokenClassification ,
@@ -110,7 +113,9 @@ def test_compare_to_transformers(self, model_arch):
110
113
transformers_outputs = transformers_model (** tokens )
111
114
outputs = ipex_model (** tokens )
112
115
# Compare tensor outputs
113
- self .assertTrue (torch .allclose (outputs .logits , transformers_outputs .logits , atol = 1e-4 ))
116
+ for output_name in {"logits" , "last_hidden_state" }:
117
+ if output_name in transformers_outputs :
118
+ self .assertTrue (torch .allclose (outputs [output_name ], transformers_outputs [output_name ], atol = 1e-4 ))
114
119
115
120
@parameterized .expand (SUPPORTED_ARCHITECTURES )
116
121
def test_pipeline (self , model_arch ):
@@ -119,7 +124,7 @@ def test_pipeline(self, model_arch):
119
124
tokenizer = AutoTokenizer .from_pretrained (model_id )
120
125
pipe = pipeline (self .IPEX_MODEL_CLASS .export_feature , model = model , tokenizer = tokenizer )
121
126
text = "This restaurant is awesome"
122
- outputs = pipe (text )
127
+ _ = pipe (text )
123
128
124
129
self .assertEqual (pipe .device , model .device )
125
130
@@ -132,44 +137,8 @@ class IPEXModelForTokenClassificationTest(IPEXModelTest):
132
137
IPEX_MODEL_CLASS = IPEXModelForSequenceClassification
133
138
134
139
135
- class IPEXModelForQuestionAnsweringTest (unittest .TestCase ):
136
- SUPPORTED_ARCHITECTURES = (
137
- "bert" ,
138
- "distilbert" ,
139
- "roberta" ,
140
- )
141
-
142
- @parameterized .expand (SUPPORTED_ARCHITECTURES )
143
- def test_compare_to_transformers (self , model_arch ):
144
- model_id = MODEL_NAMES [model_arch ]
145
- set_seed (SEED )
146
- ipex_model = IPEXModelForQuestionAnswering .from_pretrained (model_id , export = True )
147
- self .assertIsInstance (ipex_model .config , PretrainedConfig )
148
- transformers_model = AutoModelForQuestionAnswering .from_pretrained (model_id )
149
- tokenizer = AutoTokenizer .from_pretrained (model_id )
150
- inputs = "This is a sample input"
151
- tokens = tokenizer (inputs , return_tensors = "pt" )
152
- with torch .no_grad ():
153
- transformers_outputs = transformers_model (** tokens )
154
- outputs = ipex_model (** tokens )
155
- self .assertIn ("start_logits" , outputs )
156
- self .assertIn ("end_logits" , outputs )
157
- # Compare tensor outputs
158
- self .assertTrue (torch .allclose (outputs .start_logits , transformers_outputs .start_logits , atol = 1e-4 ))
159
- self .assertTrue (torch .allclose (outputs .end_logits , transformers_outputs .end_logits , atol = 1e-4 ))
160
-
161
- @parameterized .expand (SUPPORTED_ARCHITECTURES )
162
- def test_pipeline (self , model_arch ):
163
- model_id = MODEL_NAMES [model_arch ]
164
- model = IPEXModelForQuestionAnswering .from_pretrained (model_id , export = True )
165
- tokenizer = AutoTokenizer .from_pretrained (model_id )
166
- pipe = pipeline ("question-answering" , model = model , tokenizer = tokenizer )
167
- question = "What's my name?"
168
- context = "My Name is Sasha and I live in Lyon."
169
- outputs = pipe (question , context )
170
- self .assertEqual (pipe .device , model .device )
171
- self .assertGreaterEqual (outputs ["score" ], 0.0 )
172
- self .assertIsInstance (outputs ["answer" ], str )
140
+ class IPEXModelForMaskedLMTest (IPEXModelTest ):
141
+ IPEX_MODEL_CLASS = IPEXModelForMaskedLM
173
142
174
143
175
144
class IPEXModelForQuestionAnsweringTest (unittest .TestCase ):
0 commit comments