Skip to content

Fix the torch.Stream context manager reentrance#176603

Merged
atalman merged 1 commit intorelease/2.11from
cherry-pick-176568-by-pytorch_bot_bot_
Mar 9, 2026
Merged

Fix the torch.Stream context manager reentrance#176603
atalman merged 1 commit intorelease/2.11from
cherry-pick-176568-by-pytorch_bot_bot_

Conversation

@pytorchbot
Copy link
Collaborator

Stack from ghstack (oldest at bottom):

Motivation

This PR aims to fix torch.Stream as a context manager nested/reentrance scenario. torch.cuda.stream and torch.xpu.stream could support these usages.

The following scenario would be fixed with this PR:

import torch
s0 = torch.Stream()
with s0, s0:
    pass
import torch
s0 = torch.Stream()
s1 = torch.Stream()
with s0, s1:
    with s0, s1:
        pass

Addtional Context

Fix #176560

# Motivation
This PR aims to fix `torch.Stream` as a context manager nested/reentrance scenario. `torch.cuda.stream` and `torch.xpu.stream` could support these usages.

The following scenario would be fixed with this PR:
```python
import torch
s0 = torch.Stream()
with s0, s0:
    pass
```
```python
import torch
s0 = torch.Stream()
s1 = torch.Stream()
with s0, s1:
    with s0, s1:
        pass
```

# Addtional Context
Fix #176560

Pull Request resolved: #176568
Approved by: https://github.com/albanD

(cherry picked from commit d43570c)
@pytorch-bot
Copy link

pytorch-bot bot commented Mar 5, 2026

🔗 Helpful Links

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

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

✅ No Failures

As of commit 616cb0c with merge base 0fd766e (image):
💚 Looks good so far! There are no failures yet. 💚

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

@pytorch-bot
Copy link

pytorch-bot bot commented Mar 5, 2026

This PR needs a release notes: label

If your changes are user facing and intended to be a part of release notes, please use a label starting with release notes:.

If not, please add the topic: not user facing label.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "topic: not user facing"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

@atalman atalman merged commit f31baaa into release/2.11 Mar 9, 2026
113 checks passed
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.

3 participants