Skip to content

Conversation

@tungld
Copy link
Collaborator

@tungld tungld commented Oct 21, 2025

I have tried to run an example torch_compile_add.py that uses torch.compile(mod, backend=onnxmlirtorch.onnxmlir_backend. Compilation is done in the local environment, not a docker image. I found some errors such as:

[2/6] Tue Oct 21 01:33:42 2025 (0s) Compiling and Optimizing MLIR Module
[3/6] Tue Oct 21 01:33:42 2025 (0s) Translating MLIR Module to LLVM and Generating LLVM Optimized Bitcode
/tmp/tmparp0v4to/model3.unoptimized.bc: No such file or directory

and

TypeError: InferenceSession.run() takes 2 positional arguments but 3 were given

This patch is to fix such errors and now torch_compile_add.py is runnable in my environment.

add_custom_target(OMCreateONNXMLIRTorchPackage
COMMAND cp -r ${CMAKE_CURRENT_SOURCE_DIR}/onnxmlirtorch ${CMAKE_CURRENT_BINARY_DIR}
COMMAND cp ${ONNX_MLIR_BIN_ROOT}/${CMAKE_BUILD_TYPE}/lib/PyRuntimeC.*.so ${CMAKE_CURRENT_BINARY_DIR}/onnxmlirtorch/src/onnxmlirtorch/
COMMAND cp ${ONNX_MLIR_BIN_ROOT}/${CMAKE_BUILD_TYPE}/lib/PyRuntimeC.*.so ${CMAKE_CURRENT_BINARY_DIR}/onnxmlirtorch/src/onnxmlirtorch/libs
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing libs folder so that OMExecutionSession was not found.

def __init__(self, model_path, **kwargs):
self.debug = False
self.session = None
self.output_dir = tempfile.TemporaryDirectory()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to keep this temp folder, so move it to the class member. Otherwise, the temp folder is cleaned up automatically.

@tungld tungld requested a review from chentong319 October 21, 2025 06:28
@tungld
Copy link
Collaborator Author

tungld commented Oct 23, 2025

Jenkins s390x sometimes failed because of a bug that is fixed in #3302.

cache_size = 3


glocalSessionCache = SessionCache(config.cache_size)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make it global. Otherwise, the cache is local to each pytorch call to the backend.

Copy link
Collaborator

@chentong319 chentong319 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@tungld tungld merged commit a8aaa1b into onnx:main Oct 30, 2025
6 checks passed
@jenkins-droid
Copy link
Collaborator

Jenkins Linux s390x Build #17586 [push] Fix some bugs in onnxmli... started at 01:01

@jenkins-droid
Copy link
Collaborator

Jenkins Linux amd64 Build #17579 [push] Fix some bugs in onnxmli... started at 00:01

@jenkins-droid
Copy link
Collaborator

Jenkins Linux s390x Build #17586 [push] Fix some bugs in onnxmli... passed after 1 hr 33 min

@jenkins-droid
Copy link
Collaborator

Jenkins Linux amd64 Build #17579 [push] Fix some bugs in onnxmli... passed after 1 hr 42 min

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants