-
Notifications
You must be signed in to change notification settings - Fork 418
Create package of OMPyCompile #3399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
chentong319
wants to merge
5
commits into
onnx:main
Choose a base branch
from
chentong319:OMPyCompile
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # Ignore directories for build or install with -e | ||
| dist/ | ||
| src/OMPyCompile/__pycache__/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| <!--- SPDX-License-Identifier: Apache-2.0 --> | ||
| # OMPyCompile | ||
| This package provides a python driver to compile a ONNX model with onnx-mlir. | ||
| The compilation can be done with onnx-mlir compiler at local directory or in | ||
| a container. | ||
| To use | ||
| ``` | ||
| import numpy as np | ||
| import OMPyInfer | ||
|
|
||
| # Initialize the inference session | ||
| # The onnx model simply performs tensor add on two 3x4x5xf32 tensors | ||
| # It is compiled into test_add.so with zDLC | ||
| sess = OMPyInfer.InferenceSession("./test_add.so") | ||
|
|
||
| # Prepare the inputs | ||
| a = np.arange(3 * 4 * 5, dtype=np.float32).reshape((3, 4, 5)) | ||
| b = a + 4 | ||
|
|
||
| # Run inference | ||
| r = sess.run([a, b]) | ||
|
|
||
| # Print output | ||
| print(r) | ||
| ``` | ||
|
|
||
| ## Compile onnx model to shared library | ||
| TBD | ||
|
|
||
|
|
||
| ## Pre-requisites for OMPyInfer | ||
| These pre-requisities are currently provided as part of the OMPyInfer package for Python versions 3.9 until 3.13. | ||
| Prebuilt libraries for Linux on Z is provided. | ||
| Follow these instructions (TBD) to build the libraries for your own system. | ||
|
|
||
| ## Install | ||
| Currently, only local installation is supported. | ||
| Suppose you have onnx-mlir cloned on your machine. Install OMPyInfer with the following command: | ||
| ``` | ||
| python onnx-mlir/src/Runtime/python/OMPyInfer | ||
| ``` | ||
|
|
||
|
|
||
| ## Verify | ||
| ``` | ||
| cd OMPyInfer/tests | ||
| python helloworld.py | ||
| ``` | ||
|
|
||
| ## VERSIONS | ||
| Version 1.0.0 supports the model copied with onnx-mlir before 29bde823f, 2026-02-04. | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| <!--- SPDX-License-Identifier: Apache-2.0 --> | ||
|
|
||
| 1.0.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| [build-system] | ||
| requires = ["hatchling"] | ||
| build-backend = "hatchling.build" | ||
| [project] | ||
| name = "OMPyCompile" | ||
| version = "1.0.0" | ||
| authors = [ | ||
| { name="Tong Chen", email="chentong@us.ibm.com" }, | ||
| { name="Sunny Anand", email="sunny.anand79@ibm.com" }, | ||
| ] | ||
| description = "Python driver to run inference on onnx model compiled with zdlc" | ||
| readme = "README.md" | ||
| requires-python = ">=3.9" | ||
| license = "Apache-2.0" | ||
| classifiers = [ | ||
| "Programming Language :: Python :: 3", | ||
| "Operating System :: POSIX :: Linux", | ||
| ] | ||
|
|
||
| dependencies = [ | ||
| "docker" | ||
| ] | ||
|
|
||
| [project.urls] | ||
| Homepage = "https://github.com/onnx/onnx-mlir" | ||
| Issues = "https://github.com/onnx/onnx-mlir/issues" | ||
|
|
||
| [tool.hatch.build.targets.wheel] | ||
| packages = ["src/OMPyCompile"] | ||
|
|
||
| [tool.hatch.build] | ||
| include = [ | ||
| "src/OMPyCompile/libs/*" | ||
| ] | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| from .onnxmlirdockercompile import compile | ||
|
|
||
| __all__ = ["compile"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| from .cli import main | ||
|
|
||
| if __name__ == "__main__": | ||
| raise SystemExit(main()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import argparse | ||
| from .onnxmlirdockercompile import compile | ||
|
|
||
|
|
||
| def build_parser() -> argparse.ArgumentParser: | ||
| parser = argparse.ArgumentParser( | ||
| prog="python -m OMPyCompile", | ||
| description="Command-line interface for package OMPyCompile.", | ||
| ) | ||
| parser.add_argument( | ||
| "model", | ||
| type=str, | ||
| help="model file", | ||
| ) | ||
| parser.add_argument( | ||
| "--debug", | ||
| action="store_true", | ||
| default=False, | ||
| help="Enable debug output (default: False)", | ||
| ) | ||
| parser.add_argument( | ||
| "--compile_tag", | ||
| type=str, | ||
| default="NONE", | ||
| help="Tag to pass to the compiler via --tag= (default: NONE)", | ||
| ) | ||
| parser.add_argument( | ||
| "--compile_options", | ||
| type=str, | ||
| default="", | ||
| help="Additional options to pass to the onnx-mlir compiler (default: '')", | ||
| ) | ||
| parser.add_argument( | ||
| "--compiler_image_name", | ||
| type=str, | ||
| default="ghcr.io/onnxmlir/onnx-mlir-dev", | ||
| help="Container image name to use for compilation", | ||
| ) | ||
| parser.add_argument( | ||
| "--container_engine", | ||
| type=str, | ||
| default=None, | ||
| choices=["docker", "podman", None], | ||
| help=( | ||
| "Container engine to use: 'docker', 'podman', or None to auto-detect " | ||
| "(default: None)" | ||
| ), | ||
| ) | ||
| parser.add_argument( | ||
| "--compiler_path", | ||
| type=str, | ||
| default=None, | ||
| help=( | ||
| "Path to the onnx-mlir compiler binary. Required when using a custom " | ||
| "compiler_image_name that is not in the built-in image dictionary." | ||
| ), | ||
| ) | ||
| return parser | ||
|
|
||
|
|
||
| def main(argv=None) -> int: | ||
| parser = build_parser() | ||
| args = parser.parse_args(argv) | ||
|
|
||
| kwargs = vars(args) | ||
| model = kwargs.pop("model") | ||
| compiled_model = compile(model, **kwargs) | ||
| print(f"Compiled to {compiled_model}") | ||
|
|
||
| return 0 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which libraries do we need?