Skip to content
,

ComfyUI mat1 and mat2 Shapes Cannot Be Multiplied: Fix for SD1.5, SDXL and Flux

7–10 minutes
Woman at a home desk with a PC tower holding a card reading SHAPES, hook Shape error? Easy fix

Your workflow runs for a second, then stops with RuntimeError: mat1 and mat2 shapes cannot be multiplied (77x2048 and 768x320). It looks like a maths error, but it is almost always a much simpler problem: two parts of your workflow come from different model families.

The two numbers in the error tell you exactly which families are clashing. This guide shows how to read them, the usual culprits (ControlNet, CLIP loaders, IPAdapter, wrong text encoder files), and the fix for SD1.5, SDXL, SD 2.x and Flux workflows.

TL;DR

  • Cause: you mixed model families, for example an SD1.5 ControlNet with an SDXL checkpoint. It is not a VRAM problem and not a ComfyUI bug.
  • Read the widths: 768 = SD1.5 (CLIP-L), 1024 = SD 2.x, 2048 = SDXL, 4096 = T5-XXL (Flux/SD3).
  • ...x2048 and 768x...: SDXL conditioning hitting an SD1.5 part. Use the SDXL version of that ControlNet or adapter.
  • Flux: DualCLIPLoader type must be flux, with clip_l in one slot and T5-XXL in the other, never the same file twice.
  • Fastest fix: start from the model’s official template workflow and swap one loader at a time.

New to ComfyUI? My ComfyUI beginner guide covers install, models, nodes and fixes in one place.

What the Error Means

Inside a model, data passes through layers that multiply one table of numbers (a matrix) by another. That only works if the inner sizes match: a 77x2048 table can be multiplied by a 2048x320 table, but not by a 768x320 one.

So mat1 and mat2 shapes cannot be multiplied (77x2048 and 768x320) means: “I received data that is 2048 wide, but this layer was built for data that is 768 wide.” The data came from one model family and the layer belongs to another.

The official ComfyUI troubleshooting docs list this under architecture mismatch: models from different families used together. The fix is always to make every model in the chain come from the same family.

Read the Numbers: Which Family Is Which

Look at the second number of mat1 (the width of the data) and the first number of mat2 (what the layer expects). Match them to this table:

Width Comes from Model family
768 CLIP ViT-L/14 text encoder SD1.5 (also the CLIP-L part of SDXL and Flux)
1024 OpenCLIP ViT-H text encoder SD 2.0 / 2.1
2048 CLIP-L (768) + OpenCLIP bigG (1280) joined SDXL
4096 T5-XXL text encoder Flux, SD3

The first number of mat1 is usually the token count: 77 is one prompt chunk, 154 is two chunks (a long prompt, or positive and negative batched together), and 1 or 2 means a single pooled vector.

Example: 154x2048 and 768x320. The data is 2048 wide (SDXL), the layer expects 768 (SD1.5). You are feeding SDXL conditioning into an SD1.5 component, very often a ControlNet.

Common Error Patterns and Fixes

Error What is clashing Fix
77x2048 and 768x320 or 154x2048 and 768x320 SDXL checkpoint + SD1.5 ControlNet or adapter Use the SDXL version of the ControlNet
...x768 and 2048x... SD1.5 checkpoint + SDXL component Use an SDXL checkpoint, or the SD1.5 version of the component
154x1024 and 768x320 SD 2.x checkpoint in an SD1.5 workflow Download the SD1.5 checkpoint, or SD 2.x versions of the other parts
1x2048 and 768x3072 Flux model fed by a CLIP loader set to another type Set DualCLIPLoader type to flux
Error right after a CLIP loader with a standalone file Wrong text encoder file in models/text_encoders Download the encoders from the model’s own repo

Fix 1: ControlNet From the Wrong Family

This is the most common cause. ControlNets are trained for one base model, and file names do not always say which.

  1. Note your checkpoint’s family (SD1.5, SDXL, Flux and so on).
  2. Open the ControlNet loader and check the file. Names with sd15, v11p_sd15 or control_v11 are SD1.5. Names with sdxl or xl are SDXL. Flux ControlNets usually say flux.
  3. Download the matching version from the same author, put it in ComfyUI/models/controlnet/, click Refresh (or press R) and select it.
  4. Run again.

Some repackaged ControlNets drop the family from the name. If you are not sure, check the model page on Hugging Face or Civitai, which always states the base model.

Fix 2: Flux CLIP Loader Set Up Wrong

Flux uses two text encoders: CLIP-L and T5-XXL. Two mistakes cause shape errors:

  • Wrong type. The DualCLIPLoader has a type dropdown. For Flux it must be flux. Leaving it on sdxl or sd3 gives errors like 1x2048 and 768x3072.
  • Same file twice. One slot must hold clip_l.safetensors and the other a T5-XXL file such as t5xxl_fp8_e4m3fn.safetensors. Loading T5 in both slots breaks it.

Also use the Flux VAE (ae.safetensors), not sdxl_vae or taesd. A wrong VAE gives a different error (channel counts, see below), but it is often fixed at the same time.

Newer families (Flux.2, Qwen-Image, MiniMax H3 and others) each have their own text encoder and VAE. Use exactly the files listed in that model’s official ComfyUI template or Comfy-Org repack, and put them in the folders my ComfyUI model folder cheat sheet lists.

Fix 3: Wrong Checkpoint or Text Encoder File

  • Downloaded workflow, different checkpoint. A workflow built for SDXL will break if you pick an SD1.5 checkpoint in the loader (or the other way round). Pick a checkpoint from the same family as the rest of the graph.
  • SD 2.x by accident. Some old “v2” or “768-v” files are SD 2.x. If the error shows 1024, that is the reason.
  • Loose text encoder files. If you load a CLIP or T5 file with a separate loader, get it from the model’s own repository. Random files in models/text_encoders (older installs: models/clip) are a common source of odd widths like 2x1024 and 768x8192.

Fix 4: IPAdapter, CLIP Vision and Other Adapters

Any add-on model can cause the same error if it was made for a different base: IPAdapter models, CLIP Vision encoders, AnimateDiff motion modules, T2I adapters and style models.

  • Check that the IPAdapter model matches your checkpoint family (SD1.5 or SDXL), and that its CLIP Vision encoder is the one the IPAdapter pack’s README names.
  • AnimateDiff motion modules are made for SD1.5 or SDXL separately.
  • When in doubt, bypass the adapter node (select it, press Ctrl+B) and run. If the error disappears, that adapter is the mismatch.

LoRAs from the wrong family usually do not throw this error. Instead the console prints many lora key not loaded lines and the LoRA simply has no effect. Fix it the same way: use a LoRA made for your base model.

Error Meaning Fix
expected input[1, 16, 128, 128] to have 4 channels, but got 16 channels instead A 16-channel latent (Flux, SD3) going into a 4-channel VAE (SD1.5, SDXL), or the reverse Use the VAE from the same family as the model
The size of tensor a (49) must match the size of tensor b (16) at non-singleton dimension 1 Mixed families or a wrong latent size Match all loaders; start from the official template
Tensors must have same number of dimensions: got 2 and 3 Mixed families Same as above
Expected all tensors to be on the same device Part of the model on CPU, part on GPU (often a custom node) Update the node; remove forced-device flags; try without custom nodes

In an “expected input[X, Y, Z…]” error, the second number (Y) is the channel count. 4 points to SD1.5/SDXL and 16 points to Flux/SD3.

What Does Not Cause It

  • Not VRAM. A bigger GPU will not fix it. Memory problems show “CUDA out of memory” instead (see my CUDA out of memory fix).
  • Not a corrupt file. A broken download fails when loading, usually with “Error while deserializing header”.
  • Usually not a ComfyUI bug. Updating ComfyUI rarely helps, because the files are the problem.

Prevent It Next Time

  • Start from templates. ComfyUI’s built-in templates (Workflow, Browse Templates) list the exact files each model needs.
  • Keep families in subfolders. For example models/controlnet/sdxl/ and models/controlnet/sd15/. Loaders show subfolders in the file name, so mismatches are obvious.
  • Download sets from one source. Get the model, its text encoders and its VAE from the same official repo.
  • Change one loader at a time when you adapt a downloaded workflow, and run after each change.

Still stuck? My list of 22 common ComfyUI errors and fixes covers the rest, and if nodes are red rather than erroring, see the ComfyUI import failed and missing nodes fix.

FAQ

Can I use an SD1.5 ControlNet with SDXL at all?

No. The layers are built for different sizes. You need a ControlNet trained for SDXL.

Why does the error appear only when I enable ControlNet?

Because that is the part from the other family. Without it, the checkpoint, CLIP and VAE all match.

Do SDXL LoRAs work on Pony or Illustrious models?

Those are SDXL-based, so they usually load without shape errors. How good the result looks depends on the LoRA, but they will not cause mat1 and mat2 errors.

Will converting the model to fp8 or GGUF fix it?

No. Precision changes do not change the layer sizes. You need a model from the right family.

Is the second number always the expected width?

For these errors, yes: the first number of mat2 is what the layer expects, and the second number of mat1 is what it got.

Sources

Free weekly email

Get new AI guides every week

One short weekly email with our newest local AI, ComfyUI and AI tool guides. No spam, no pop-ups, just the good stuff.

Free. Unsubscribe anytime in one click. We only use your email to send this newsletter. See our privacy policy.

Woman at a home desk with a PC tower holding a card reading SHAPES, hook Shape error? Easy fix