Skip to content

fix: add Apple Silicon MPS support for device detection#58

Open
msgjsmj wants to merge 1 commit into
datalab-to:masterfrom
msgjsmj:fix/apple-silicon-mps-support
Open

fix: add Apple Silicon MPS support for device detection#58
msgjsmj wants to merge 1 commit into
datalab-to:masterfrom
msgjsmj:fix/apple-silicon-mps-support

Conversation

@msgjsmj

@msgjsmj msgjsmj commented Dec 29, 2025

Copy link
Copy Markdown

Summary

  • Fixed hardcoded "cuda" device in generate_hf() function that caused AssertionError: Torch not compiled with CUDA enabled on non-NVIDIA systems
  • Added automatic device detection with priority: TORCH_DEVICE setting → model.device → CUDA → MPS → CPU
  • Enables running chandra on Apple Silicon Macs with Metal acceleration

Problem

When running chandra-app on macOS with Apple Silicon (M1/M2/M3), the following error occurs:

AssertionError: Torch not compiled with CUDA enabled

This is because hf.py:36 has hardcoded inputs.to("cuda").

Solution

Replace hardcoded device with automatic detection that respects:

  1. User-configured TORCH_DEVICE setting
  2. Model's device attribute
  3. Available hardware (CUDA → MPS → CPU fallback)

Test Plan

  • Tested on Apple M2 Pro with chandra-app
  • Verify CUDA systems still work as expected

🤖 Generated with Claude Code

The generate_hf function had hardcoded "cuda" device, causing
AssertionError on non-NVIDIA systems. This change adds automatic
device detection with the following priority:

1. TORCH_DEVICE setting (if configured)
2. model.device attribute (if available)
3. CUDA (if torch.cuda.is_available())
4. MPS (if torch.backends.mps.is_available()) - Apple Silicon
5. CPU (fallback)

This enables running chandra on Apple Silicon Macs with Metal
acceleration via MPS backend.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@msgjsmj msgjsmj force-pushed the fix/apple-silicon-mps-support branch from 9978015 to 419af07 Compare December 29, 2025 08:21
@sawoz

sawoz commented Feb 8, 2026

Copy link
Copy Markdown

Hi! Just curious about the state of this fix, any plans to release it soonish? Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants