onnx-mlir icon indicating copy to clipboard operation
onnx-mlir copied to clipboard

PyCompileAndRuntime produces different results when running multiple times

Open anonymoususer-12 opened this issue 1 year ago • 4 comments

Hi , I want to use PyCompileAndRuntime to CompileAndRun a onnx model (e.g. model.onnx) and print the output of the model.onnx. However, this will produce different results when I repeatedly run the code. The onnx-mlir used in my experiment is a prebuild verion in onnxmlir/onnx-mlir-dev.

OnnxRuntime4Validate.py

import pickle
from PyCompileAndRuntime import OMCompileExecutionSession
import json
import numpy as np
import os

def run_lib():

    session = OMCompileExecutionSession( 'model.onnx',"-O3",use_default_entry_point=False )
    # Query entry points in the model.
    entry_points = session.entry_points()
    for entry_point in entry_points:
        session.set_entry_point(name=entry_point)
        print(f'Run at {entry_point}')
        # print("input signature in json", session.input_signature())
        # print("output signature in json", session.output_signature())
        inputs = json.loads(session.input_signature())
        input_names = [item['name'] for item in inputs]
        data = {}
        with open('oracle.pkl', 'rb') as file:
            data = pickle.load(file)
        inputs = [data['input'][input_name] for input_name in input_names]
        outputs1 = session.run(inputs)
        print(outputs1)

if __name__ == "__main__":
    run_lib()

model.onnx and oralce.pkl are in model.zip

'python3 OnnxRuntime4Validate.py' image

anonymoususer-12 avatar Sep 26 '24 14:09 anonymoususer-12

Would it make sense to also print the inputs, so that we are sure they are the same?

AlexandreEichenberger avatar Sep 27 '24 14:09 AlexandreEichenberger

Would it make sense to also print the inputs, so that we are sure they are the same?

I cannot have a complete printscreen because the inputs are large. The print results including inputs and outputs have been exported to two files: tmp1 and tmp2. The diff results shows that the outputs are different given the same inputs. image The tmp1 and tmp2 can be found in tmp.zip The specific inputs and model can be found in model.zip

anonymoususer-12 avatar Sep 27 '24 18:09 anonymoususer-12

Have you tried to compile the model with -O0 to see if it works?

tungld avatar Oct 02 '24 13:10 tungld

Have you tried to compile the model with -O0 to see if it works?

Yes, the cases are the same (the results are different when running multiple times) from '-O0' to '-O2'

anonymoususer-12 avatar Oct 09 '24 06:10 anonymoususer-12