Skip to content

Support Triton kernels in SAC region - #161541

Closed
soulitzer wants to merge 6 commits into
gh/soulitzer/378/basefrom
gh/soulitzer/378/head
Closed

soulitzer wants to merge 6 commits into
gh/soulitzer/378/basefrom
gh/soulitzer/378/head

Conversation

@soulitzer

@soulitzer soulitzer commented Aug 26, 2025 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

SAC interaction with triton kernel:

  • In eager, triton ops are not dispatchable, and so it is always ignored by SAC, i.e., always recomputed.
  • In compile, although we wrap triton kernels into HOPs, allowing us to intercept them, we still recompute by default rather than save by default, so that compile maintains the invariant of using less memory than eager.
  • If you want to do something else (e.g. save the output of your triton kernel) you should wrap it in a custom op.

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @chenyang78 @kadeng @chauhang @amjames @Lucaskabela @fegin

[ghstack-poisoned]
@soulitzer
soulitzer requested a review from zou3519 as a code owner August 26, 2025 20:53
@pytorch-bot

pytorch-bot Bot commented Aug 26, 2025 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

✅ No Failures

As of commit be665a2 with merge base 4fd761f (image):
💚 Looks good so far! There are no failures yet. 💚

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

[ghstack-poisoned]
soulitzer added a commit that referenced this pull request Aug 26, 2025
ghstack-source-id: b8e491e
Pull-Request-resolved: #161541
@soulitzer
soulitzer requested review from drisspg and ydwu4 August 26, 2025 20:56
@soulitzer
soulitzer marked this pull request as draft August 26, 2025 20:58
@soulitzer soulitzer added the release notes: autograd release notes category label Aug 26, 2025
@pytorch pytorch deleted a comment from github-actions Bot Aug 26, 2025
@soulitzer soulitzer changed the title Fix SAC when there are Triton kernels Support Triton kernels in SAC region Aug 26, 2025
@@ -1342,6 +1344,9 @@ def triton_kernel_wrapper_functional_functionalize(
triton_kernel_wrapper_functional.fallthrough(DispatchKey.AutogradCUDA)
triton_kernel_wrapper_functional.fallthrough(DispatchKey.AutogradCPU)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I wonder when the functional HOP is used over mutation HOP? Should we register to both?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

after functionalization key, the mutation hop becomes functional hop. The functional hop is not user-facing.

[ghstack-poisoned]
@soulitzer
soulitzer marked this pull request as ready for review August 27, 2025 20:44
@soulitzer

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Aug 27, 2025
@pytorchmergebot

Copy link
Copy Markdown
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

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: 1 jobs have failed, first few of them are: trunk / linux-jammy-rocm-py3.10 / test (default, 2, 2, linux.rocm.gpu.2)

Details for Dev Infra team Raised by workflow job

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@soulitzer your PR has been successfully reverted.

[ghstack-poisoned]
@soulitzer

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge

@pytorchmergebot

Copy link
Copy Markdown
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

[ghstack-poisoned]
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: New commits were pushed while merging. Please rerun the merge command.

Details for Dev Infra team Raised by workflow job

[ghstack-poisoned]
@soulitzer

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge

@pytorchmergebot

Copy link
Copy Markdown
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

fegin added a commit to pytorch/torchtitan that referenced this pull request Aug 29, 2025
This PR refactors the activation checkpoint by moving `apply_ac()` out
of the llama3 `parallelize.py` module. Additionally, it introduces a
warning about the configuration combinations involving SAC,
`torch.compile`, and `flex_attention` to inform users of potential
issues.

This PR depends on pytorch/pytorch#161541

cc., @drisspg @bdhirsh @soulitzer
wwwjn pushed a commit to pytorch/torchtitan that referenced this pull request Sep 3, 2025
This PR refactors the activation checkpoint by moving `apply_ac()` out
of the llama3 `parallelize.py` module. Additionally, it introduces a
warning about the configuration combinations involving SAC,
`torch.compile`, and `flex_attention` to inform users of potential
issues.

This PR depends on pytorch/pytorch#161541

cc., @drisspg @bdhirsh @soulitzer
markc-614 pushed a commit to markc-614/pytorch that referenced this pull request Sep 17, 2025
SAC interaction with triton kernel:
- In eager, triton ops are not dispatchable, and so it is always ignored by SAC,  i.e., always recomputed.
- In compile, although we wrap triton kernels into HOPs, allowing us to intercept them, we still recompute by default rather than save by default, so that compile maintains the invariant of using less memory than eager.
- If you want to do something else (e.g. save the output of your triton kernel) you should wrap it in a custom op.

Pull Request resolved: pytorch#161541
Approved by: https://github.com/drisspg, https://github.com/zou3519
ghstack dependencies: pytorch#160781
markc-614 pushed a commit to markc-614/pytorch that referenced this pull request Sep 17, 2025
SAC interaction with triton kernel:
- In eager, triton ops are not dispatchable, and so it is always ignored by SAC,  i.e., always recomputed.
- In compile, although we wrap triton kernels into HOPs, allowing us to intercept them, we still recompute by default rather than save by default, so that compile maintains the invariant of using less memory than eager.
- If you want to do something else (e.g. save the output of your triton kernel) you should wrap it in a custom op.

Pull Request resolved: pytorch#161541
Approved by: https://github.com/drisspg, https://github.com/zou3519, https://github.com/xmfan
@github-actions
github-actions Bot deleted the gh/soulitzer/378/head branch September 28, 2025 02:16
Khanaksahu pushed a commit to Khanaksahu/pytorch that referenced this pull request Nov 17, 2025
ghstack-source-id: 4b2ce29
Pull-Request-resolved: pytorch/pytorch#161541
xrsrke pushed a commit to NousResearch/torchtitan that referenced this pull request Feb 13, 2026
This PR refactors the activation checkpoint by moving `apply_ac()` out
of the llama3 `parallelize.py` module. Additionally, it introduces a
warning about the configuration combinations involving SAC,
`torch.compile`, and `flex_attention` to inform users of potential
issues.

This PR depends on pytorch/pytorch#161541

cc., @drisspg @bdhirsh @soulitzer
xrsrke pushed a commit to NousResearch/torchtitan that referenced this pull request Feb 25, 2026
This PR refactors the activation checkpoint by moving `apply_ac()` out
of the llama3 `parallelize.py` module. Additionally, it introduces a
warning about the configuration combinations involving SAC,
`torch.compile`, and `flex_attention` to inform users of potential
issues.

This PR depends on pytorch/pytorch#161541

cc., @drisspg @bdhirsh @soulitzer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-no-td Do not run TD on this PR ciflow/inductor ciflow/trunk Trigger trunk jobs on your pull request Merged module: dynamo release notes: autograd release notes category Reverted

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants