feat: select CUDA device consistently across inference backends - #306
feat: select CUDA device consistently across inference backends#306be-student wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (8)
Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review. WalkthroughChangesCUDA device selection
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to This change adds validated CUDA device selection across the API and CLI while preserving default behavior and positional compatibility. Current coverage indicates no actionable merge-blocking risk remains. Suggested reviewers: Sequence Diagram(s)sequenceDiagram
participant CLI
participant Separator
participant PyTorch
participant ONNXRuntime
CLI->>Separator: Pass cuda_device_index
Separator->>Separator: Validate device index
Separator->>PyTorch: Select cuda:index
Separator->>ONNXRuntime: Set CUDA provider device_id
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 21 functions across 7 files. (1 skipped: 1 unsupported.)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Add
Separator(cuda_device_index=...)and--cuda_device_indexso a multi-GPU user can select the same visible device for PyTorch and ONNX Runtime.configure_cuda(..., device_index=...)also supports an explicit index.Fixes #225.
The constructor argument is appended to preserve existing positional calls. With no index specified, current automatic behavior remains unchanged. Explicit values are validated before initialization; unavailable CUDA and out-of-range indices raise
ValueErrorrather than silently choosing another backend. Indices are relative toCUDA_VISIBLE_DEVICES.The change also handles two downstream requirements of indexed devices:
The README documents CLI/API usage and validation behavior.
Validation
pytest tests/unit -q: 566 passed, 4 skipped, 13 warnings on Python 3.12 withpoetry install -E cpu.git diff --check: passed.Tests cover index propagation to both backends, invalid values, range checks, unavailable CUDA, unchanged defaults, positional compatibility, CLI forwarding, MDX provider options/fallback reporting, and cache cleanup for indexed CUDA devices. These device-selection checks mock CUDA availability and ONNX sessions; real multi-GPU inference was not performed.
AI assistance: Codex implemented this change and ran the listed validation.
Summary by CodeRabbit
New Features
CUDA_VISIBLE_DEVICES.Bug Fixes