Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error when device mismatches when calling gather() on CUDA #2180

Merged
merged 2 commits into from
Nov 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/accelerate/utils/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,13 @@ def _gpu_gather_one(tensor):
if not tensor.is_contiguous():
tensor = tensor.contiguous()

# Check if `tensor` is not on CUDA
if state.device.type == "cuda" and tensor.device.type != "cuda":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there other device mismatches that could be checked here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@muellerzr @BenjaminBossan Can this logic be extended to other devices ? Seems like a generic exception handling case.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it can, for now it’s just a thing on CUDA but if it’s useful for other devices that can be added. This is just a known base case

raise RuntimeError(
"One or more of the tensors passed to `gather` were not on the GPU while the `Accelerator` is configured for CUDA. "
"Please move it to the GPU before calling `gather`."
)

if state.backend is not None and state.backend != "gloo":
# We use `empty` as `all_gather_into_tensor` slightly
# differs from `all_gather` for better efficiency,
Expand Down
Loading