Skip to content

Modernize polynomial_custom_function: torch.accelerator and setup_context#3885

Open
jvz37 wants to merge 1 commit intopytorch:mainfrom
jvz37:fix/3880-custom-autograd-modernize
Open

Modernize polynomial_custom_function: torch.accelerator and setup_context#3885
jvz37 wants to merge 1 commit intopytorch:mainfrom
jvz37:fix/3880-custom-autograd-modernize

Conversation

@jvz37
Copy link
Copy Markdown

@jvz37 jvz37 commented May 9, 2026

Fixes #3880

Description

Modernizes the custom autograd function tutorial by:

  • Replacing hardcoded torch.device("cpu") with torch.accelerator for accelerator-agnostic device selection
  • Splitting legacy forward(ctx, input) into forward(input) + setup_context(ctx, inputs, output) per PyTorch 2.0+ recommended pattern

Tested locally: 2000 iterations, loss converged, output identical to original.

Checklist

  • The issue that is being fixed is referred in the description (see above "Fixes #ISSUE_NUMBER")
  • Only one issue is addressed in this pull request
  • [] Labels from the issue that this PR is fixing are added to this pull request
  • No unnecessary issues are included into this pull request.

@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented May 9, 2026

🔗 Helpful Links

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

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

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

@meta-cla meta-cla Bot added the cla signed label May 9, 2026
@jvz37
Copy link
Copy Markdown
Author

jvz37 commented May 9, 2026

Note: the commit author shows jalilAlva (another account I have) due to a local git config mistake. This PR was opened and authored by jvz37, my the account registered for Docathon 2026.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update Custom autograd Function example — use torch.accelerator, modernize Function pattern

2 participants