Skip to content

fix(splatfacto): replace .cuda() with .to(self.device) for MPS support#3750

Open
ChrisMOxon wants to merge 1 commit intonerfstudio-project:mainfrom
ChrisMOxon:fix/splatfacto-mps-device-support
Open

fix(splatfacto): replace .cuda() with .to(self.device) for MPS support#3750
ChrisMOxon wants to merge 1 commit intonerfstudio-project:mainfrom
ChrisMOxon:fix/splatfacto-mps-device-support

Conversation

@ChrisMOxon
Copy link
Copy Markdown

Summary

  • Replace two hardcoded .cuda() calls in splatfacto.py with .to(self.device)
  • Fixes crash on Apple Silicon (MPS) and CPU-only systems: AssertionError: Torch not compiled with CUDA enabled
  • Zero impact on CUDA systems — .to(self.device) resolves to cuda:N when CUDA is active

Changes

  • Line 208: torch.zeros(...).float().cuda().float().to(self.device) (SH coefficient init)
  • Line 535: camera.get_intrinsics_matrices().cuda().to(self.device) (camera intrinsics)

Testing

  • Verified on M2 Max (MPS backend) — model initializes and completes forward pass
  • Confirmed no remaining .cuda() calls in splatfacto.py
  • CUDA compatibility preserved

Context

Discovered by an autonomous Claude Code agent ("Ralph") while optimizing a 3D scanning pipeline for Apple Silicon. The agent audited all nerfstudio model code for CUDA-only patterns and identified these two lines as the only hardcoded .cuda() calls in splatfacto.

🤖 Generated with Claude Code

…MPS support

Two lines in splatfacto.py use .cuda() directly instead of the model's
device property, causing crashes on non-CUDA systems (Apple Silicon MPS,
CPU-only machines) with "Torch not compiled with CUDA enabled".

Replace with .to(self.device) which correctly resolves to cuda:N on NVIDIA,
mps:0 on Apple Silicon, or cpu as appropriate.

Tested on M2 Max (MPS) — model initializes and runs forward pass successfully.
CUDA compatibility preserved: .to(self.device) resolves to cuda:N on CUDA systems.

Discovered and benchmarked by an autonomous Claude Code agent ("Ralph")
optimizing a 3D scanning pipeline for Apple Silicon.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

1 participant