pytorch - ✅(Solved) Fix Accelerators: torch.Stream.record_event doesn't handle torch.cuda.Events even though torch.cuda.Event is a torch.Event subclass [1 pull requests, 5 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
pytorch/pytorch#177771Fetched 2026-04-08 00:57:53
View on GitHub
Comments
5
Participants
3
Timeline
53
Reactions
0
Author
Timeline (top)
mentioned ×18subscribed ×18commented ×5labeled ×4

Error Message

RuntimeError: Event device type CPU does not match recording stream's device type CUDA.

Fix Action

Fixed

PR fix notes

PR #177701: [user-streams] Fix check that didn't include torch.Event subclasses

Description (problem / solution / changelog)

Fixes https://github.com/pytorch/pytorch/issues/177771

Stack from ghstack (oldest at bottom):

  • -> #177701

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

Changed files

  • test/dynamo/test_streams.py (modified, +8/-0)
  • torch/csrc/Event.cpp (modified, +1/-2)
  • torch/csrc/Stream.cpp (modified, +1/-2)
  • torch/csrc/cuda/Event.cpp (modified, +6/-0)

Code Example

import torch                                                                            
   
event = torch.cuda.Event()                                                              
stream = torch.Stream(device=torch.device("cuda"))              
stream.record_event(event)

---

RuntimeError: Event device type CPU does not match recording stream's device type CUDA.
RAW_BUFFERClick to expand / collapse

🐛 Describe the bug

torch.Stream.record_event doesn't handle torch.cuda.Event arguments.

import torch                                                                            
   
event = torch.cuda.Event()                                                              
stream = torch.Stream(device=torch.device("cuda"))              
stream.record_event(event)

error

RuntimeError: Event device type CPU does not match recording stream's device type CUDA.

Versions

c5065b607ce

cc @ptrblck @msaroufim @eqy @jerryzh168 @tinglvv @nWEIdia @albanD @guangyey @EikanWang

extent analysis

Fix Plan

The fix involves ensuring that the torch.cuda.Event is created on the same device as the torch.Stream.

Step-by-Step Solution

  • Create the torch.cuda.Event on the CUDA device:
import torch

# Create a CUDA device
device = torch.device("cuda")

# Create the event on the CUDA device
event = torch.cuda.Event(device=device)

# Create the stream on the CUDA device
stream = torch.Stream(device=device)

# Record the event
stream.record_event(event)

Alternatively, you can also use the torch.cuda.current_device() to get the current CUDA device and create the event on it:

import torch

# Get the current CUDA device
device = torch.cuda.current_device()

# Create the event on the current CUDA device
event = torch.cuda.Event(device=device)

# Create the stream on the current CUDA device
stream = torch.Stream(device=device)

# Record the event
stream.record_event(event)

Verification

To verify that the fix worked, run the code and check that it no longer raises a RuntimeError. You can also add some debug prints to ensure that the event is being recorded correctly:

print("Event device:", event.device)
print("Stream device:", stream.device)
stream.record_event(event)
print("Event recorded successfully")

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

pytorch - ✅(Solved) Fix Accelerators: torch.Stream.record_event doesn't handle torch.cuda.Events even though torch.cuda.Event is a torch.Event subclass [1 pull requests, 5 comments, 3 participants]