-
Notifications
You must be signed in to change notification settings - Fork 21.9k
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
[onnx.export] Avoid linear look up in env for exist_in_env #124909
[onnx.export] Avoid linear look up in env for exist_in_env #124909
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/124909
Note: Links to docs will display an error until the docs builds have been completed. ❗ 1 Active SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below: ✅ No FailuresAs of commit 0726246 with merge base 6ea226b (): This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
6e80e7f
to
ab070ac
Compare
ab070ac
to
b59ab82
Compare
@@ -169,8 +169,14 @@ std::shared_ptr<Graph> ToONNX( | |||
ConstantValueMap::ClearMaps(); | |||
auto new_graph = std::make_shared<Graph>(graph->current_scope()); | |||
std::unordered_map<Value*, Value*> env; | |||
py::set values_in_env; |
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.
Could you add the rationale as a comment here for future readers? Thanks!
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.
Added a comment, thanks! I also pushed a rebase since #123063 merged, that touches many of the same lines.
- As part of torch.onnx.export, a reverse look-up is made in env. This is done for each node, and this look-up costs in proportion to the graph size, which incurs and overall O(N^2) time complexity. - A pragmatic solution is simply to keep a separate data structure to make this de facto constant time. So, this introduces a set containing all the values of env. - Resolves (4) in pytorch#121422.
b59ab82
to
0726246
Compare
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
This PR is part of a series of PRs to significantly speed up torch.onnx.export for models with many nodes (e.g. LLM). See #121422 for more analysis.
exist_in_env
wouldn't be needed at all, but to preserve current behavior exactly I'm not sure how that can be done.Partially fixes #121422