-
Notifications
You must be signed in to change notification settings - Fork 235
Refactor dynamo converter and ir.Model support #1765
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
Conversation
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.
Pull Request Overview
This PR refactors the model conversion flow to avoid redundant disk IO when saving a Dynamo exported model and enables direct saving of ONNX IR models by introducing the ir_model_to_olive_model function.
- Updated onnxscript_fusion.py to replace model_proto_to_olive_model with ir_model_to_olive_model.
- Refactored conversion.py to add separate export methods for torchscript and dynamo exporters.
- Added ir_model_to_olive_model in onnx/common.py to support saving IR models.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
olive/passes/onnx/onnxscript_fusion.py | Updated the model conversion call to use ir_model_to_olive_model. |
olive/passes/onnx/conversion.py | Refactored export methods and introduced dynamo exporter changes. |
olive/passes/onnx/common.py | Added the new function ir_model_to_olive_model for saving IR models. |
@titaiwangms do you have an idea about this error in |
Yes, it's a bug and the function will be deleted in 2.7. Because I didn't consider the mismatch input names between onnx graph and nn.Module, it causes KeyError to the matching. (That's why I set it to 2.7) |
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.
Pull Request Overview
This PR refactors the dynamo exporter flow to avoid redundant disk IO and updates the torch.onnx conversion passes while improving type annotations and generic typing.
- Update test conditions to account for torch version 2.7.0 and dynamic shape handling.
- Refactor type hints in IoConfig by marking several fields as Optional.
- Enhance generic typing in config_utils with a type variable.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
File | Description |
---|---|
test/unit_test/passes/onnx/test_conversion.py | Adjusted test skip conditions for Windows and dynamic shapes based on torch version. |
olive/model/config/io_config.py | Updated type annotations to use Optional for various input/output fields. |
olive/common/config_utils.py | Modified the config union type to use a generic type variable T. |
Comments suppressed due to low confidence (1)
olive/common/config_utils.py:317
- Ensure that the type variable T is properly defined (e.g., via 'from typing import TypeVar' and 'T = TypeVar("T")') to support the generic type annotation.
config: Union[dict[str, Any], T, None],
@justinchuby @jambayk Are we merging this soon? I am working on a PR to refactor the patch and dynamic_shapes to the latest version for better support on LLMs. |
I think the PR is ready. I would need some reviews |
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.
Pull Request Overview
This PR refactors the dynamo exporter and onnx conversion passes by reducing redundant disk IO and updating type annotations.
- Updated test conditions for dynamo export based on torch versions
- Changed type annotations in IoConfig to use Optional
- Updated generic type hints in config_utils
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
test/unit_test/passes/onnx/test_conversion.py | Adjusted test conditions with additional torch version checks |
olive/model/config/io_config.py | Updated type hints to use Optional for better type clarity and safety |
olive/common/config_utils.py | Modified function signature to use generic type T for configuration input |
Comments suppressed due to low confidence (2)
test/unit_test/passes/onnx/test_conversion.py:36
- [nitpick] Consider adding an inline comment to explain why skipping is conditioned on the torch version for Windows platforms, which can help future maintainers understand the rationale.
if platform.system() == "Windows" and use_dynamo_exporter and _torch_is_older_than("2.7.0"):
olive/model/config/io_config.py:37
- [nitpick] Updating type annotations to Optional is a good improvement. It would be helpful to update the corresponding docstrings to reflect these changes.
input_shapes: Optional[list[list[int]]] = None
=================================== FAILURES =================================== |
closing since it has become stale |
I will continue on this. Thanks |
## Describe your changes While working on #1765, I realized that some typing annotations and error behavior can be improved. I isolated the changes here as a separate PR. ## Checklist before requesting a review - [ ] Add unit tests for this change. - [ ] Make sure all tests can pass. - [ ] Update documents if necessary. - [x] Lint and apply fixes to your code by running `lintrunner -a` - [ ] Is this a user-facing change? If yes, give a description of this change to be included in the release notes. - [ ] Is this PR including examples changes? If yes, please remember to update [example documentation](https://github.com/microsoft/Olive/blob/main/docs/source/examples.md) in a follow-up PR. ## (Optional) Issue link --------- Signed-off-by: Justin Chu <[email protected]>
commit 5450394 Merge: c7276ac 77f897e Author: Justin Chu <[email protected]> Date: Fri Aug 15 13:10:27 2025 -0700 Merge branch 'main' into justinchu/dynamo-save commit c7276ac Merge: ea436b6 6cdedb9 Author: Justin Chu <[email protected]> Date: Wed Aug 13 06:45:32 2025 -0700 Merge branch 'main' into justinchu/dynamo-save commit ea436b6 Author: Justin Chu <[email protected]> Date: Fri Aug 8 17:33:25 2025 -0700 test Signed-off-by: Justin Chu <[email protected]> commit dc90ff1 Merge: 11d49e0 c8718cd Author: Justin Chu <[email protected]> Date: Fri Aug 8 17:31:04 2025 -0700 Merge branch 'main' into justinchu/dynamo-save Signed-off-by: Justin Chu <[email protected]> commit 11d49e0 Merge: 632b1cb 30aa1f9 Author: Xiaoyu <[email protected]> Date: Tue Jun 17 15:58:40 2025 -0700 Merge branch 'main' into justinchu/dynamo-save commit 632b1cb Author: Justin Chu <[email protected]> Date: Fri Jun 13 20:48:35 2025 -0700 merge commit 1ed33da Author: Justin Chu <[email protected]> Date: Fri Jun 13 19:52:06 2025 -0700 Update commit d3a3ca1 Merge: 52504f5 8a847c2 Author: Justin Chu <[email protected]> Date: Fri Jun 13 19:43:24 2025 -0700 Merge branch 'main' into justinchu/dynamo-save commit 52504f5 Merge: 5b500e8 d148eed Author: Justin Chu <[email protected]> Date: Thu Jun 12 13:35:39 2025 -0700 Merge branch 'main' into justinchu/dynamo-save commit 5b500e8 Author: Justin Chu <[email protected]> Date: Fri May 2 11:34:10 2025 -0700 Update conversion.py commit d8d0e94 Merge: 39e73e2 ebf8954 Author: Justin Chu <[email protected]> Date: Fri May 2 11:30:34 2025 -0700 Merge branch 'main' into justinchu/dynamo-save commit 39e73e2 Merge: 11397fa fe0d4b5 Author: Justin Chu <[email protected]> Date: Wed Apr 30 15:54:01 2025 -0700 Merge branch 'main' into justinchu/dynamo-save commit 11397fa Merge: 0ac3491 245ef68 Author: Justin Chu <[email protected]> Date: Tue Apr 29 16:03:08 2025 -0700 Merge branch 'main' into justinchu/dynamo-save commit 0ac3491 Merge: 28d4df0 1535aec Author: Justin Chu <[email protected]> Date: Fri Apr 25 15:52:10 2025 -0700 Merge branch 'main' into justinchu/dynamo-save commit 28d4df0 Author: Justin Chu <[email protected]> Date: Tue Apr 22 12:34:11 2025 -0700 string_to_int_dim_params commit ae1abf6 Author: Justin Chu <[email protected]> Date: Tue Apr 22 10:20:55 2025 -0700 Implement string_to_int_dim_params commit 5926cd4 Author: Justin Chu <[email protected]> Date: Tue Apr 22 10:09:39 2025 -0700 Update tests commit e018963 Merge: 2be4ad8 d9f73b5 Author: Justin Chu <[email protected]> Date: Mon Apr 21 19:44:36 2025 -0700 Merge branch 'main' into justinchu/dynamo-save commit 2be4ad8 Author: Justin Chu <[email protected]> Date: Mon Apr 21 16:51:40 2025 -0700 lint commit 1f8372f Merge: 2a1b6a0 86bd63e Author: Justin Chu <[email protected]> Date: Mon Apr 21 16:48:48 2025 -0700 Merge branch 'main' into justinchu/dynamo-save commit 2a1b6a0 Author: Justin Chu <[email protected]> Date: Fri Apr 18 15:00:13 2025 -0700 count size commit fb4c19b Author: Justin Chu <[email protected]> Date: Fri Apr 18 14:52:06 2025 -0700 Update save_as_external_data commit 3680472 Author: Justin Chu <[email protected]> Date: Fri Apr 18 14:17:31 2025 -0700 Fix test commit 2a87477 Author: Justin Chu <[email protected]> Date: Fri Apr 18 14:02:33 2025 -0700 update commit ce1824c Author: Justin Chu <[email protected]> Date: Fri Apr 18 13:47:31 2025 -0700 Fix external data handling commit 3d5d42f Author: Justin Chu <[email protected]> Date: Fri Apr 18 13:28:55 2025 -0700 save model first commit c4e6215 Author: Justin Chu <[email protected]> Date: Fri Apr 18 12:01:53 2025 -0700 Refactor commit 90052a1 Author: Justin Chu <[email protected]> Date: Fri Apr 18 11:53:55 2025 -0700 Refactor commit 405bca6 Author: Justin Chu <[email protected]> Date: Fri Apr 18 11:20:53 2025 -0700 Update commit f779277 Author: Justin Chu <[email protected]> Date: Thu Apr 17 17:56:46 2025 -0700 Refactor ONNX model conversion return logic commit 25ff541 Author: Justin Chu <[email protected]> Date: Thu Apr 17 17:55:13 2025 -0700 Update olive/passes/onnx/conversion.py commit 5017ad4 Author: Justin Chu <[email protected]> Date: Thu Apr 17 17:52:23 2025 -0700 Rename `model_ir_to_olive_model` to `ir_model_to_olive_model`. commit 73bdb33 Author: Justin Chu <[email protected]> Date: Thu Apr 17 17:50:09 2025 -0700 Update OnnxScriptFusion commit b885198 Author: Justin Chu <[email protected]> Date: Thu Apr 17 17:47:03 2025 -0700 Implement model_ir_to_olive_model commit 561f453 Author: Justin Chu <[email protected]> Date: Thu Apr 17 17:37:57 2025 -0700 Refactor dynamo converter Signed-off-by: Justin Chu <[email protected]>
5450394
to
2f9b942
Compare
Signed-off-by: Justin Chu <[email protected]>
Signed-off-by: Justin Chu <[email protected]>
Describe your changes
Checklist before requesting a review
lintrunner -a