InvalidArgument: [ONNXRuntimeError] : 2 : INVALID_ARGUMENT : Unexpected input data type. Actual: (tensor(int32)) , expected: (tensor(int64)

I have trained and saved a model in lunx/ubuntu. Now when i tried to run it on windows, it throw following error

InvalidArgument                           Traceback (most recent call last)
Input In [19], in <cell line: 12>()
      9     return tokenizer(ex["sentence"])
     11 tokenized_ds = ds.map(partial(preprocess_fn, tokenizer=quantizer.tokenizer))
---> 12 ort_outputs = ort_model.evaluation_loop(tokenized_ds)
     13 # Extract logits!
     14 pred=ort_outputs.predictions

File e:\fiverr\upwork\venv\lib\site-packages\optimum\onnxruntime\model.py:98, in ORTModel.evaluation_loop(self, dataset)
     96     labels = None
     97 onnx_inputs = {key: np.array([inputs[key]]) for key in self.onnx_config.inputs if key in inputs}
---> 98 preds = session.run(self.onnx_named_outputs, onnx_inputs)
     99 if len(preds) == 1:
    100     preds = preds[0]

File e:\fiverr\upwork\venv\lib\site-packages\onnxruntime\capi\onnxruntime_inference_collection.py:192, in Session.run(self, output_names, input_feed, run_options)
    190     output_names = [output.name for output in self._outputs_meta]
    191 try:
--> 192     return self._sess.run(output_names, input_feed, run_options)
    193 except C.EPFail as err:
    194     if self._enable_fallback:

InvalidArgument: [ONNXRuntimeError] : 2 : INVALID_ARGUMENT : Unexpected input data type. Actual: (tensor(int32)) , expected: (tensor(int64))

Code is as follow and working on linux

# %%time
from time import time
start=time()

# Create a dataset or load one from the Hub
ds = Dataset.from_dict({"sentence": list(val_df.tweet)})
# Tokenize the inputs
def preprocess_fn(ex, tokenizer):
    return tokenizer(ex["sentence"])

tokenized_ds = ds.map(partial(preprocess_fn, tokenizer=quantizer.tokenizer))
ort_outputs = ort_model.evaluation_loop(tokenized_ds)
# Extract logits!
pred=ort_outputs.predictions
end=time()
total_time=end-start
print(total_time)

Hi @Talha,

Did you check the data type of the array’s elements of onnx_inputs ?
Can you try :

onnx_inputs = {key: np.array([inputs[key]], dtype=np.int64) for key in self.onnx_config.inputs if key in inputs}

Also ORTModel was a class added for users to be able to obtain the evaluation results in order to compare their original model with the resulting optimized / quantized model, and was meant to be temporary. This class is now depreciated and we encourage users to use our new classes ORTModelForXxx.