← all conversations

MPS error tensor dims

2026-04-052 turns7,845 charsgpt-5-3
machine-learningpytorchmps

Summary

User encountered an MPS graph error related to tensor dimensions exceeding INT_MAX limit.

Messages

!!! Exception during processing !!! MPSGaph does not support tensor dims larger than INT_MAX Traceback (most recent call last): File "/Users/danielkliewer/Documents/Projects/Comfy/comfy/execution.py", line 534, in execute output_data, output_ui, has_subgraph, has_pending_tasks = await get_output_data(prompt_id, unique_id, obj, input_data_all, execution_block_cb=execution_block_cb, pre_execute_cb=pre_execute_cb, v3_data=v3_data) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/danielkliewer/Documents/Projects/Comfy/comfy/execution.py", line 334, in get_output_data return_values = await _async_map_node_over_list(prompt_id, unique_id, obj, input_data_all, obj.FUNCTION, allow_interrupt=True, execution_block_cb=execution_block_cb, pre_execute_cb=pre_execute_cb, v3_data=v3_data) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/danielkliewer/Documents/Projects/Comfy/comfy/execution.py", line 308, in _async_map_node_over_list await process_inputs(input_dict, i) File "/Users/danielkliewer/Documents/Projects/Comfy/comfy/execution.py", line 296, in process_inputs result = f(**inputs) File "/Users/danielkliewer/Documents/Projects/Comfy/comfy/nodes.py", line 316, in decode images = vae.decode(latent) File "/Users/danielkliewer/Documents/Projects/Comfy/comfy/comfy/sd.py", line 967, in decode model_management.raise_non_oom(e) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^ File "/Users/danielkliewer/Documents/Projects/Comfy/comfy/comfy/model_management.py", line 289, in raise_non_oom raise e File "/Users/danielkliewer/Documents/Projects/Comfy/comfy/comfy/sd.py", line 960, in decode out = self.first_stage_model.decode(samples, **vae_options).to(device=self.output_device, dtype=self.vae_output_dtype(), copy=True) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/danielkliewer/Documents/Projects/Comfy/comfy/comfy/ldm/models/autoencoder.py", line 143, in decode x = self.decoder(z, **kwargs) File "/Users/danielkliewer/Documents/Projects/Comfy/venv/lib/python3.14/site-packages/torch/nn/modules/module.py", line 1778, in _wrapped_call_impl return self._call_impl(*args, **kwargs) ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^ File "/Users/danielkliewer/Documents/Projects/Comfy/venv/lib/python3.14/site-packages/torch/nn/modules/module.py", line 1789, in _call_impl return forward_call(*args, **kwargs) File "/Users/danielkliewer/Documents/Projects/Comfy/comfy/comfy/ldm/modules/diffusionmodules/model.py", line 790, in forward h = self.mid.attn_1(h, **kwargs) File "/Users/danielkliewer/Documents/Projects/Comfy/venv/lib/python3.14/site-packages/torch/nn/modules/module.py", line 1778, in _wrapped_call_impl return self._call_impl(*args, **kwargs) ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^ File "/Users/danielkliewer/Documents/Projects/Comfy/venv/lib/python3.14/site-packages/torch/nn/modules/module.py", line 1789, in _call_impl return forward_call(*args, **kwargs) File "/Users/danielkliewer/Documents/Projects/Comfy/comfy/comfy/ldm/modules/diffusionmodules/model.py", line 374, in forward h_ = self.optimized_attention(q, k, v) File "/Users/danielkliewer/Documents/Projects/Comfy/comfy/comfy/ldm/modules/diffusionmodules/model.py", line 282, in normal_attention r1 = slice_attention(q, k, v) File "/Users/danielkliewer/Documents/Projects/Comfy/comfy/comfy/ldm/modules/diffusionmodules/model.py", line 262, in slice_attention model_management.raise_non_oom(e) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^ File "/Users/danielkliewer/Documents/Projects/Comfy/comfy/comfy/model_management.py", line 289, in raise_non_oom raise e File "/Users/danielkliewer/Documents/Projects/Comfy/comfy/comfy/ldm/modules/diffusionmodules/model.py", line 258, in slice_attention r1[:, :, i:end] = torch.bmm(v, s2) ~~~~~~~~~^^^^^^^ RuntimeError: MPSGaph does not support tensor dims larger than INT_MAX
This error is very specific to **Apple Silicon (MPS backend)** and almost always means: > You created a tensor so large that Metal (Apple’s GPU API) literally cannot index it. --- ## 💥 What’s actually happening The key line: ``` RuntimeError: MPSGraph does not support tensor dims larger than INT_MAX ``` And the stack trace shows it blows up here: ``` r1[:, :, i:end] = torch.bmm(v, s2) ``` That’s inside **attention computation** → meaning: 👉 Your **attention matrix got insanely large** --- ## 🧠 Why this happens (in ComfyUI) This usually comes from one of these: ### 1. 🚨 Resolution way too high Attention scales **quadratically** with image size. - 512x512 → fine - 1024x1024 → pushing it - 2048x2048 → 💀 on MPS - Anything tiled incorrectly → 💀💀💀 --- ### 2. 🚨 Latent tensor exploded If your latent shape is wrong (like earlier error you had), you can accidentally create: ``` [batch, channels, HUGE, HUGE] ``` That leads to attention matrices like: ``` (H*W) x (H*W) ``` Which becomes billions of elements. --- ### 3. 🚨 Bad node connections (very likely in your case) You mentioned earlier: > "none of it is connected properly" If: - VAE decode gets wrong latent - Or latent is passed multiple times / concatenated incorrectly 👉 you can silently blow up tensor size --- ### 4. 🚨 GGUF misuse with diffusion graph If you're mixing: - GGUF (LLM nodes) - Diffusion pipeline (VAE, UNet) 👉 You might be feeding incompatible tensor shapes into the VAE --- ## 🔧 How to fix it (in order of likelihood) ### ✅ Step 1 — Drop resolution immediately Set: - Width: **512** - Height: **512** If that works → scale slowly to 768 max on MPS --- ### ✅ Step 2 — Enable attention slicing In ComfyUI: - Use nodes or flags: - `--force-fp32` - `--use-split-cross-attention` Or in nodes: - Add **"Attention Split" / "Slice Attention"** --- ### ✅ Step 3 — Check latent shape before VAE decode Add a debug node or print: You want something like: ``` [1, 4, 64, 64] ← for 512x512 [1, 4, 96, 96] ← for 768x768 ``` If you see something like: ``` [1, 4, 2560, ...] ``` 👉 that's your problem --- ### ✅ Step 4 — Fix graph structure (VERY IMPORTANT) Correct minimal pipeline: ``` Checkpoint → KSampler → VAE Decode → Image ``` NOT: - multiple VAEs - stacked latents - GGUF → VAE directly (❌ invalid) --- ### ✅ Step 5 — Don’t run diffusion through GGUF GGUF is for: - LLMs (text) NOT for: - image latent tensors If you're trying to: > "only use GGUF" 👉 Then you **cannot** use: - VAE Decode - KSampler - diffusion pipeline Those require a **diffusion model checkpoint (.safetensors)** --- ## 🧪 Quick diagnosis trick Ask yourself: 👉 Did I: - Go above 1024 resolution? - Chain latents weirdly? - Mix GGUF + diffusion nodes? If yes → that's it. --- ## ⚡ Fastest fix (do this first) 1. Set resolution to **512x512** 2. Use a **standard checkpoint** 3. Use only: ``` CheckpointLoader → KSampler → VAE Decode → Save Image ``` If that works → your issue is graph complexity --- ## 🧠 Important insight (this matters for your setup) You’re experimenting heavily (which is good), but ComfyUI is **not forgiving**: > It won’t tell you “this tensor is wrong” > It will just explode deep in PyTorch like this --- ## If you want, I can fix your graph Paste your current JSON again and I’ll: - Debug connections - Ensure GGUF is used correctly (if at all) - Prevent tensor explosion - Optimize for MPS (Apple GPU) Right now this is 100% a **tensor size explosion**, not a random bug.
gpt-5-3