Skip to content

Fix CUDA device index preservation in standardize_device_string#364

Merged
yuecideng merged 1 commit into
mainfrom
fix/standardize-cuda-device-index
Jul 6, 2026
Merged

Fix CUDA device index preservation in standardize_device_string#364
yuecideng merged 1 commit into
mainfrom
fix/standardize-cuda-device-index

Conversation

@yuecideng

Copy link
Copy Markdown
Contributor

Description

This PR fixes standardize_device_string so it preserves non-zero CUDA device indices instead of forcing every cuda:X to cuda:0.

Previously, when running with --device cuda:4, tensors were placed on cuda:4 but Warp kernels were launched on cuda:0, causing a RuntimeError during environment reset in solvers such as OPW.

Dependencies: None

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (non-breaking change which improves an existing functionality)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (existing functionality will not work without user modification)
  • Documentation update

Screenshots

N/A

Checklist

  • I have run the black . command to format the code base.
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • Dependencies have been updated, if applicable.

Previously, standardize_device_string mapped any cuda:X string to cuda:0,
causing Warp kernels to launch on the wrong GPU when users specified a
non-zero CUDA device (e.g., --device cuda:4). Now only bare 'cuda' is
normalized to 'cuda:0', and existing indices are preserved.
Copilot AI review requested due to automatic review settings July 6, 2026 03:36
@yuecideng yuecideng added bug Something isn't working solver Robot kinematics solver robot Module related to robot labels Jul 6, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes embodichain.utils.device_utils.standardize_device_string so that only the bare "cuda" device string is normalized to "cuda:0", preserving explicit CUDA device indices like "cuda:4" to avoid Warp/Torch device mismatches in CUDA-based solvers.

Changes:

  • Update standardize_device_string to special-case only "cuda" (not all "cuda:*" strings).
  • Add unit tests covering CPU, CUDA without index, and CUDA with explicit indices for both str and torch.device inputs.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
embodichain/utils/device_utils.py Adjusts CUDA device string normalization to preserve non-zero indices.
tests/utils/test_device_utils.py Adds test coverage for standardize_device_string behavior across CPU/CUDA variants.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +19 to +20
import pytest
import torch
@yuecideng yuecideng merged commit bf72a8e into main Jul 6, 2026
6 checks passed
@yuecideng yuecideng deleted the fix/standardize-cuda-device-index branch July 6, 2026 04:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working robot Module related to robot solver Robot kinematics solver

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants