Skip to content

Conversation

@yifuwang
Copy link
Collaborator

@yifuwang yifuwang commented Oct 31, 2024

Stack from ghstack (oldest at bottom):

This PR fixes a compilation time regression manifested in timm_models/hrnet_w18 caused by #136732.

The regression is reproducible locally. The compilation time is a bit noisy, but it's still possible to tell the difference.

Before the offending PR

compilation_latency mean=176.022 seconds
compilation_latency mean=176.564 seconds

On the offending PR

compilation_latency mean=180.096 seconds
compilation_latency mean=179.101 seconds

On the fix

compilation_latency mean=173.153 seconds
compilation_latency mean=174.182 seconds

(I think the fix being faster than the baseline is due to noise)

The cause of the regression is an inefficiency in is_user_visible_output(). Specifically, it used output_node.args[0].index(node) to obtain the output idx for each node (and we called this for each node twice). The offending PR had the assumption that len(output_node.args[0]) is rather small. However, it has been proven false by the benchmark (it was 1900+ for timm_models/hrnet_w18).

The fix is to precompute user_visible_output_strides once by iterating only over the nodes in output_node.args[0].

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @yf225 @chenyang78 @kadeng @muchulee8 @ColinPeppler @amjames @desertfire @chauhang @aakhundov

@pytorch-bot
Copy link

pytorch-bot bot commented Oct 31, 2024

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/139420

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 906c09a with merge base 73fde0d (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@yifuwang yifuwang marked this pull request as draft October 31, 2024 19:08
@yifuwang yifuwang added the topic: not user facing topic category label Oct 31, 2024
@yifuwang yifuwang requested a review from ezyang October 31, 2024 19:56
Copy link
Contributor

@ezyang ezyang left a comment

Choose a reason for hiding this comment

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

Aww yeahhh, that's what I'm talking about!

@yifuwang
Copy link
Collaborator Author

@pytorchbot rebase

@pytorchmergebot
Copy link
Collaborator

@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here

[ghstack-poisoned]
@pytorchmergebot
Copy link
Collaborator

Successfully rebased gh/yifuwang/161/orig onto refs/remotes/origin/viable/strict, please pull locally before adding more changes (for example, via ghstack checkout https://github.com/pytorch/pytorch/pull/139420)

pytorchmergebot pushed a commit that referenced this pull request Oct 31, 2024
…utput handling

ghstack-source-id: 8abfccd
Pull Request resolved: #139420
@yifuwang yifuwang marked this pull request as ready for review October 31, 2024 20:37
@yifuwang
Copy link
Collaborator Author

yifuwang commented Nov 1, 2024

@pytorchbot merge

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Nov 1, 2024
@pytorchmergebot
Copy link
Collaborator

Merge started

Your 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

Advanced Debugging
Check the merge workflow status
here

rahulsingh-intel pushed a commit to rahulsingh-intel/pytorch that referenced this pull request Nov 5, 2024
…utput handling (pytorch#139420)

This PR fixes a compilation time regression manifested in timm_models/hrnet_w18 caused by pytorch#136732.

The regression is reproducible locally. The compilation time is a bit noisy, but it's still possible to tell the difference.

```
Before the offending PR

compilation_latency mean=176.022 seconds
compilation_latency mean=176.564 seconds

On the offending PR

compilation_latency mean=180.096 seconds
compilation_latency mean=179.101 seconds

On the fix

compilation_latency mean=173.153 seconds
compilation_latency mean=174.182 seconds
```

(I think the fix being faster than the baseline is due to noise)

The cause of the regression is an inefficiency in `is_user_visible_output()`. Specifically, it used `output_node.args[0].index(node)` to obtain the output idx for each node (and we called this for each node twice). The offending PR had the assumption that `len(output_node.args[0])` is rather small. However, it has been proven false by the benchmark (it was 1900+ for timm_models/hrnet_w18).

The fix is to precompute `user_visible_output_strides` once by iterating only over the nodes in `output_node.args[0]`.

Pull Request resolved: pytorch#139420
Approved by: https://github.com/ezyang
@github-actions github-actions bot deleted the gh/yifuwang/161/head branch December 2, 2024 02:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants