Skip to content

[User-streams] Make torch.Event weakref compatible - #164522

Closed
mlazos wants to merge 19 commits into
gh/mlazos/33/basefrom
gh/mlazos/33/head
Closed

mlazos wants to merge 19 commits into
gh/mlazos/33/basefrom
gh/mlazos/33/head

Conversation

@pytorch-bot

pytorch-bot Bot commented Oct 2, 2025 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

✅ No Failures

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

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

mlazos added a commit that referenced this pull request Oct 3, 2025
ghstack-source-id: fbfe632
Pull Request resolved: #164522
mlazos added a commit that referenced this pull request Oct 3, 2025
ghstack-source-id: fbfe632
Pull Request resolved: #164522
mlazos added a commit that referenced this pull request Oct 3, 2025
ghstack-source-id: fbfe632
Pull Request resolved: #164522
mlazos added a commit that referenced this pull request Oct 7, 2025
ghstack-source-id: fbfe632
Pull Request resolved: #164522
mlazos added a commit that referenced this pull request Oct 8, 2025
ghstack-source-id: 49e3de1
Pull Request resolved: #164522
mlazos added a commit that referenced this pull request Oct 8, 2025
ghstack-source-id: 49e3de1
Pull Request resolved: #164522
[ghstack-poisoned]
@mlazos

mlazos commented Oct 29, 2025

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

pytorchmergebot pushed a commit that referenced this pull request Oct 30, 2025
Preivously, we would stash a single stream value we constructed at trace time in a global and return the same value from repeated calls to the graph.

With this PR, we construct the stream value in advance, reference the constructed value in the graph via the lookup table, and if that value is returned as an output, read the value from the lookup table and return it (in bytecode, not as a graph output, since we don't support arbitrary stream outputs).

Pull Request resolved: #164819
Approved by: https://github.com/anijain2305
ghstack dependencies: #164304, #164522
BoyuanFeng pushed a commit that referenced this pull request Oct 31, 2025
Preivously, we would stash a single stream value we constructed at trace time in a global and return the same value from repeated calls to the graph.

With this PR, we construct the stream value in advance, reference the constructed value in the graph via the lookup table, and if that value is returned as an output, read the value from the lookup table and return it (in bytecode, not as a graph output, since we don't support arbitrary stream outputs).

Pull Request resolved: #164819
Approved by: https://github.com/anijain2305
ghstack dependencies: #164304, #164522
BoyuanFeng pushed a commit that referenced this pull request Oct 31, 2025
etaf pushed a commit to etaf/pytorch-inductor-xpu that referenced this pull request Nov 4, 2025
Preivously, we would stash a single stream value we constructed at trace time in a global and return the same value from repeated calls to the graph.

With this PR, we construct the stream value in advance, reference the constructed value in the graph via the lookup table, and if that value is returned as an output, read the value from the lookup table and return it (in bytecode, not as a graph output, since we don't support arbitrary stream outputs).

Pull Request resolved: pytorch#164819
Approved by: https://github.com/anijain2305
ghstack dependencies: pytorch#164304, pytorch#164522
etaf pushed a commit to etaf/pytorch-inductor-xpu that referenced this pull request Nov 4, 2025
Khanaksahu pushed a commit to Khanaksahu/pytorch that referenced this pull request Nov 17, 2025
Khanaksahu pushed a commit to Khanaksahu/pytorch-fork that referenced this pull request Nov 17, 2025
Khanaksahu pushed a commit to Khanaksahu/pytorch-fork that referenced this pull request Nov 17, 2025
@github-actions
github-actions Bot deleted the gh/mlazos/33/head branch November 29, 2025 02:20
pytorch-bot Bot pushed a commit that referenced this pull request Apr 13, 2026
torch.Generator is defined via the raw CPython API and did not set
tp_weaklistoffset, so weakref.ref(generator) raised TypeError. The
proxy tensor tracing infrastructure tracks opaque objects in a
WeakIdKeyDictionary, so weak reference support is a prerequisite for
treating Generator as an opaque reference type.

Add a PyObject* weakrefs field to THPGenerator, set tp_weaklistoffset,
initialize the field in all constructors, and clear weak refs in dealloc.
This follows the same pattern used for torch.Stream (#164304) and
torch.Event (#164522).

<!-- ps-id: d542629c-9c69-49bd-ac66-a6569e111771 -->
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.

5 participants