Skip to content

[dynamo] Migrate AutogradFunctionContextVariable methods - #195179

Closed
AayushMainali-Github wants to merge 2 commits into
pytorch:mainfrom
AayushMainali-Github:fix/autograd-function-context-variable-195165
Closed

AayushMainali-Github wants to merge 2 commits into
pytorch:mainfrom
AayushMainali-Github:fix/autograd-function-context-variable-195165

Conversation

@AayushMainali-Github

Copy link
Copy Markdown
Contributor

Summary

Migrate AutogradFunctionContextVariable off a call_method if-chain onto declarative tp_methods, as in #195165.

save_for_backward, mark_dirty, and mark_non_differentiable are now Method handlers.

Part of #195165 (does not close the umbrella).

Test plan

  • git diff --check
  • python -m py_compile torch/_dynamo/variables/misc.py

AI-assisted implementation.

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @kadeng @chauhang @amjames @jataylo @azahed98

The context methods were dispatched through a hand-written name if-chain. Register them in tp_methods so named-method dispatch is declarative while retaining the existing handlers.

Test Plan:

```
git diff --check
python -m py_compile torch/_dynamo/variables/misc.py
```

AI-assisted implementation; reviewed and approved by the contributor.
@pytorch-bot

pytorch-bot Bot commented Aug 28, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

✅ You can merge normally! (1 Unrelated Failure)

As of commit 9f781e1 with merge base 6a211a9 (image):

BROKEN TRUNK - The following job failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

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

@pytorch-bot pytorch-bot Bot added ciflow/inductor ciflow/torchtitan Run TorchTitan integration tests module: dynamo labels Aug 28, 2026
@pytorch-bot

pytorch-bot Bot commented Aug 28, 2026 •

Copy link
Copy Markdown

Workflows were awaiting approval. CI has now been triggered for the ciflow labels on this PR.

@AayushMainali-Github

Copy link
Copy Markdown
Contributor Author

@pytorchbot label "topic: not user facing"

@pytorch-bot pytorch-bot Bot added the topic: not user facing topic category label Aug 28, 2026
Comment thread torch/_dynamo/variables/misc.py Resolved
Comment thread torch/_dynamo/variables/misc.py Resolved
@drisspg drisspg added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Aug 31, 2026
Address review on #195179: mark_dirty and mark_non_differentiable now use
no_keywords instead of raise_args_mismatch, matching CPython's
_PyArg_NoKeywords and the other tp_methods handlers. Sync the graph-break
registry for the hardcoded context strings from the migration.

Test Plan:
```
git diff --check
python -m py_compile torch/_dynamo/variables/misc.py
lintrunner --skip PYREFLY,CLANGTIDY,CLANGTIDY_EXECUTORCH_COMPATIBILITY,CLANGFORMAT torch/_dynamo/variables/misc.py
python test/dynamo/test_autograd_function.py AutogradFunctionTests
python test/dynamo/test_autograd_function.py AutogradFunctionFunctorchTests
```

AI-assisted.
@guilhermeleobas

Copy link
Copy Markdown
Collaborator

@pytorchbot merge

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Sep 1, 2026
@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: torchtitan-test / torchtitan-x-pytorch-test / test (torchtitan_models_integration, 1, 1, mt-l-x86aavx2-189-704-a10g-8)

Details for Dev Infra team Raised by workflow job

@guilhermeleobas

Copy link
Copy Markdown
Collaborator

@pytorchbot merge -i

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged while ignoring the following 1 checks: torchtitan-test / torchtitan-x-pytorch-test / test (torchtitan_models_integration, 1, 1, mt-l-x86aavx2-189-704-a10g-8)

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

Sanskaaar1 pushed a commit to Sanskaaar1/pytorch that referenced this pull request Sep 8, 2026
)

## Summary
Migrate `AutogradFunctionContextVariable` off a `call_method` if-chain onto declarative `tp_methods`, as in pytorch#195165.

`save_for_backward`, `mark_dirty`, and `mark_non_differentiable` are now `Method` handlers.

Part of pytorch#195165 (does not close the umbrella).

## Test plan
- [x] `git diff --check`
- [x] `python -m py_compile torch/_dynamo/variables/misc.py`

> AI-assisted implementation.

Pull Request resolved: pytorch#195179
Approved by: https://github.com/guilhermeleobas
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/inductor ciflow/torchtitan Run TorchTitan integration tests ciflow/trunk Trigger trunk jobs on your pull request Merged module: dynamo open source topic: not user facing topic category triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants