[Bug] MPS crash in SAM3 Text Segmentation (grid_sample) on macOS - Placeholder tensor is empty
Description
When running SAM3 Text Segmentation on macOS (Apple Silicon, MPS backend), the node crashes with a PyTorch internal assertion error:
RuntimeError: [srcBuf length] > 0 INTERNAL ASSERT FAILED ...
Placeholder tensor is empty!
The error occurs inside torch.nn.functional.grid_sample during the grounding phase.
Environment
- OS: macOS 14.8.2 (Apple Silicon)
- Device: MPS (Metal)
- PyTorch: 2.10.0
- Python: 3.12
- ComfyUI: 0.18.2
- comfyui-sam3: latest (as of 2026-04)
Full Error Trace
RuntimeError: [srcBuf length] > 0 INTERNAL ASSERT FAILED at ...
Placeholder tensor is empty!
File ".../sam3/model.py", line 2344:
sampled = torch.nn.functional.grid_sample(img_feats, grid, align_corners=False)
Root Cause (Analysis)
From code inspection:
# load_model.py
load_device = comfy.model_management.get_torch_device()
# utils.py
if device is None:
device = comfy.model_management.get_torch_device()
This means:
- The model always follows ComfyUI’s global device
- On macOS → this becomes
mps
The crash happens specifically in:
grid_sample (MPS backend)
This suggests:
PyTorch MPS backend + SAM3 grounding pipeline is unstable or unsupported in this code path.
Expected Behavior
- SAM3 Text Segmentation should run correctly on MPS
- OR fallback to CPU automatically if unsupported operations are used
Actual Behavior
- Node crashes during grounding
- No output produced
- Error occurs consistently on MPS
Workaround (Confirmed Working)
Forcing the model to run on CPU resolves the issue completely.
Fix 1 — nodes/load_model.py
import torch
load_device = torch.device("cpu")
Fix 2 — nodes/_model_cache.py
import torch
load_device = torch.device("cpu")
offload_device = torch.device("cpu")
Fix 3 (optional, safer) — nodes/sam3/utils.py
if device is None:
device = torch.device("cpu")
Result After Fix
- No crash
- Segmentation works correctly
- Multiple instance masks are generated as expected
- Only downside: slower inference (CPU)
Suggestion
Consider:
- Detecting MPS and disabling problematic ops (e.g.
grid_sample)
- Automatically falling back to CPU when running grounding
- Adding a device override option in the node UI
Additional Notes
- This issue is independent of prompt correctness
- Once running on CPU, results are stable and correct
- Likely related to PyTorch MPS limitations rather than model logic
[Bug] MPS crash in SAM3 Text Segmentation (grid_sample) on macOS - Placeholder tensor is empty
Description
When running SAM3 Text Segmentation on macOS (Apple Silicon, MPS backend), the node crashes with a PyTorch internal assertion error:
The error occurs inside
torch.nn.functional.grid_sampleduring the grounding phase.Environment
Full Error Trace
Root Cause (Analysis)
From code inspection:
This means:
mpsThe crash happens specifically in:
This suggests:
Expected Behavior
Actual Behavior
Workaround (Confirmed Working)
Forcing the model to run on CPU resolves the issue completely.
Fix 1 —
nodes/load_model.pyFix 2 —
nodes/_model_cache.pyFix 3 (optional, safer) —
nodes/sam3/utils.pyResult After Fix
Suggestion
Consider:
grid_sample)Additional Notes