Commit bcb7e29
Modernize polynomial_custom_function: torch.accelerator and setup_context (#3885)
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
- [x] The issue that is being fixed is referred in the description (see
above "Fixes #ISSUE_NUMBER")
- [x] Only one issue is addressed in this pull request
- [] Labels from the issue that this PR is fixing are added to this pull
request
- [x] No unnecessary issues are included into this pull request.
---------
Co-authored-by: jalilAlva <jalil.alva@welocalize.com>
Co-authored-by: sekyondaMeta <127536312+sekyondaMeta@users.noreply.github.com>1 parent 43859b1 commit bcb7e29
1 file changed
Lines changed: 17 additions & 9 deletions
Lines changed: 17 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
| 35 | + | |
40 | 36 | | |
41 | 37 | | |
42 | | - | |
43 | 38 | | |
44 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
45 | 50 | | |
46 | 51 | | |
47 | 52 | | |
| |||
54 | 59 | | |
55 | 60 | | |
56 | 61 | | |
57 | | - | |
58 | | - | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
59 | 67 | | |
60 | 68 | | |
61 | 69 | | |
| |||
0 commit comments