Skip to content

Fix CPU support by removing hardcoded CUDA calls - #81

Open
jonathansim94 wants to merge 1 commit into
facebookresearch:mainfrom
jonathansim94:fix/cpu-inference
Open

Fix CPU support by removing hardcoded CUDA calls#81
jonathansim94 wants to merge 1 commit into
facebookresearch:mainfrom
jonathansim94:fix/cpu-inference

Conversation

@jonathansim94

Copy link
Copy Markdown

This PR fixes CPU support by removing all hard-coded CUDA device calls in the model execution path. Several modules previously forced tensors to "cuda" (e.g., via .cuda(), recursive_to(..., "cuda"), or device="cuda"), which caused runtime failures when no GPU was available.

All these occurrences have been replaced with device-agnostic logic relying on "self.device".

Also tested in a Docker container without GPU support, confirming that inference runs successfully on CPU without errors.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Dec 4, 2025
@JVPC0D3R

Copy link
Copy Markdown

This is also an issue with multi-gpu setups. Hardcoded "cuda" doesn't allow correct device selection. Adding os.environ["CUDA_VISIBLE_DEVICES"] also helps

adcoh added a commit to adcoh/sam-3d-body that referenced this pull request Apr 8, 2026
Fixes facebookresearch#93. Supersedes facebookresearch#81.

- Replace hardcoded "cuda" / .cuda() calls with self.device
- Auto-detect device: CUDA > MPS > CPU
- Force MHR TorchScript to load/run on CPU (MPS incompatible with
  float64 placeholder storage)
- Downcast float64 to float32 in recursive_to() for MPS compatibility

Tested on MacBook Pro M1 Max, macOS 15.x, PyTorch 2.5+ with MPS backend.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants