Skip to content

Commit ead21ba

Browse files
ChrisMOxonclaude
andcommitted
fix(splatfacto): replace hardcoded .cuda() with .to(self.device) for 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>
1 parent 50e0e3c commit ead21ba

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

nerfstudio/models/splatfacto.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def populate_modules(self):
205205
# We can have colors without points.
206206
and self.seed_points[1].shape[0] > 0
207207
):
208-
shs = torch.zeros((self.seed_points[1].shape[0], dim_sh, 3)).float().cuda()
208+
shs = torch.zeros((self.seed_points[1].shape[0], dim_sh, 3)).float().to(self.device)
209209
if self.config.sh_degree > 0:
210210
shs[:, 0, :3] = RGB2SH(self.seed_points[1] / 255)
211211
shs[:, 1:, 3:] = 0.0
@@ -532,7 +532,7 @@ def get_outputs(self, camera: Cameras) -> Dict[str, Union[torch.Tensor, List]]:
532532
camera_scale_fac = self._get_downscale_factor()
533533
camera.rescale_output_resolution(1 / camera_scale_fac)
534534
viewmat = get_viewmat(optimized_camera_to_world)
535-
K = camera.get_intrinsics_matrices().cuda()
535+
K = camera.get_intrinsics_matrices().to(self.device)
536536
W, H = int(camera.width.item()), int(camera.height.item())
537537
self.last_size = (H, W)
538538
camera.rescale_output_resolution(camera_scale_fac) # type: ignore

0 commit comments

Comments
 (0)