Repository navigation
[Train][TPU] Enable stream support in TPUTorchDeviceManager - #66822
Merged
ryanaoleary merged 1 commit intoOct 30, 2026
Merged
Conversation
chiayi
force-pushed
the
tpu-device-manager-streams
branch
3 times, most recently
from
October 7, 2026 21:18
dc4ff55 to
4e1a634
Compare
chiayi
marked this pull request as ready for review
October 7, 2026 21:20
Contributor
There was a problem hiding this comment.
Code Review
This pull request adds stream support for TPU devices in TPUTorchDeviceManager and updates _WrappedDataLoader to handle record_stream errors on TPU and other custom backends. It also introduces corresponding unit tests. The review feedback suggests two improvements: first, checking if torch has the tpu attribute in supports_stream to prevent potential AttributeErrors when torch.tpu is unavailable; second, logging ignored RuntimeErrors during record_stream on TPU at a debug level to prevent masking other genuine runtime issues.
chiayi
force-pushed
the
tpu-device-manager-streams
branch
from
October 7, 2026 21:25
4e1a634 to
e699b79
Compare
chiayi
force-pushed
the
tpu-device-manager-streams
branch
3 times, most recently
from
October 7, 2026 22:57
78b7b44 to
ce952f3
Compare
ryanaoleary
reviewed
Oct 7, 2026
ryanaoleary
reviewed
Oct 7, 2026
ryanaoleary
reviewed
Oct 7, 2026
ryanaoleary
reviewed
Oct 7, 2026
ryanaoleary
reviewed
Oct 8, 2026
chiayi
force-pushed
the
tpu-device-manager-streams
branch
from
October 8, 2026 05:54
ce952f3 to
b2a160e
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Reviewed by Cursor Bugbot for commit b2a160e. Configure here.
chiayi
force-pushed
the
tpu-device-manager-streams
branch
2 times, most recently
from
October 8, 2026 22:51
1c64660 to
f831e6f
Compare
chiayi
force-pushed
the
tpu-device-manager-streams
branch
from
October 19, 2026 23:00
f831e6f to
b3b46df
Compare
liulehui
approved these changes
Oct 27, 2026
Signed-off-by: Aaron Liang <[email protected]>
chiayi
force-pushed
the
tpu-device-manager-streams
branch
from
October 29, 2026 20:17
b3b46df to
d497a3b
Compare
ryanaoleary
enabled auto-merge (squash)
October 30, 2026 02:23
14 of 20 tasks
ryanaoleary
pushed a commit
that referenced
this pull request
Nov 10, 2026
…or guide (#67779) ## Description Adds a `PyTorch: Prefetch batches with device streams` section to `doc/source/train/user-guides/using-accelerators.md`. It documents how `ray.train.torch.prepare_data_loader` prefetches batches with `torch.tpu.Stream` on TPUs and `torch.cuda.Stream` on GPUs when `auto_transfer=True`. ## Related issues Doc related to #66822 ## Additional information Signed-off-by: Aaron Liang <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Description
Enable TPU stream support in
TPUTorchDeviceManagerusingtorch.tpusoprepare_data_loader(..., auto_transfer=True)can prefetch batches asynchronously onto TPU devices. Also handlerecord_streamerrors ontorch_tpu, whereaten::record_streamis not supported.Key Changes
supports_stream(),create_stream(),get_stream_context(), andget_current_stream()inTPUTorchDeviceManagerusingtorch.tpu(returningnullcontext()whenstream is None).record_streamerrors (NotImplementedError, andRuntimeErrorontpu) in_WrappedDataLoader._wait_for_batch().test_tpu_torch_backend.pyand register the target inBUILD.bazel.Related issues
N/A
Test commands run and results
pytest -v python/ray/train/tests/test_tpu_torch_backend.py-> 4 passedRayJobwithauto_transfer=Trueandauto_transfer=False.