Comfy-Org/ComfyUI · error · ValueError

`only_cross_attention` can only be set to True if `added_kv_

Error message

`only_cross_attention` can only be set to True if `added_kv_proj_dim` is not None. Make sure to set either `only_cross_attention=False` or define `added_kv_proj_dim`.

What it means

Constructor guard in the ACE attention module (comfy/ldm/ace/attention.py): only_cross_attention=True makes the attention read keys/values solely from an externally projected conditioning tensor, which requires a projection width, i.e. added_kv_proj_dim must be set. Without it the module has no source for the cross KV tensors, so construction is rejected immediately with ValueError.

Source

Thrown at comfy/ldm/ace/attention.py:83

        self.out_context_dim = out_context_dim if out_context_dim is not None else query_dim
        self.context_pre_only = context_pre_only
        self.pre_only = pre_only
        self.is_causal = is_causal

        self.scale_qk = scale_qk
        self.scale = dim_head**-0.5 if self.scale_qk else 1.0

        self.heads = out_dim // dim_head if out_dim is not None else heads
        # for slice_size > 0 the attention score computation
        # is split across the batch axis to save memory
        # You can set slice_size with `set_attention_slice`
        self.sliceable_head_dim = heads

        self.added_kv_proj_dim = added_kv_proj_dim
        self.only_cross_attention = only_cross_attention

        if self.added_kv_proj_dim is None and self.only_cross_attention:
            raise ValueError(
                "`only_cross_attention` can only be set to True if `added_kv_proj_dim` is not None. Make sure to set either `only_cross_attention=False` or define `added_kv_proj_dim`."
            )

        self.group_norm = None
        self.spatial_norm = None

        self.norm_q = None
        self.norm_k = None

        self.norm_cross = None
        self.to_q = operations.Linear(query_dim, self.inner_dim, bias=bias, dtype=dtype, device=device)

        if not self.only_cross_attention:
            # only relevant for the `AddedKVProcessor` classes
            self.to_k = operations.Linear(self.cross_attention_dim, self.inner_kv_dim, bias=bias, dtype=dtype, device=device)
            self.to_v = operations.Linear(self.cross_attention_dim, self.inner_kv_dim, bias=bias, dtype=dtype, device=device)
        else:
            self.to_k = None

View on GitHub (pinned to 1c6d8d45b3)

Solutions

  1. Set added_kv_proj_dim to the conditioning width (e.g. the text/audio embedding dim) in the attention config
  2. Set only_cross_attention=False (or omit it) if you do not need cross-only attention
  3. Check the checkpoint's config JSON that feeds this constructor for a missing/renamed added_kv_proj_dim key and restore it from the original release

Example fix

# before
attn = Attention(query_dim=1024, only_cross_attention=True)  # added_kv_proj_dim missing

# after
attn = Attention(query_dim=1024, only_cross_attention=False)
# or
attn = Attention(query_dim=1024, added_kv_proj_dim=768, only_cross_attention=True)
Defensive patterns

Strategy: validation

Validate before calling

def build_attention(query_dim, cfg):
    if cfg.get('only_cross_attention') and cfg.get('added_kv_proj_dim') is None:
        cfg = {**cfg, 'only_cross_attention': False}
    return Attention(query_dim, **cfg)

Type guard

def is_valid_attention_cfg(cfg: dict) -> bool:
    return not (cfg.get('only_cross_attention', False) and cfg.get('added_kv_proj_dim') is None)

Prevention

When it happens

Trigger: Instantiating the Attention class (or a model config that builds it) with only_cross_attention=True while added_kv_proj_dim is None. Usually comes from a hand-written model config dict or an edited checkpoint config for the ACE/ACE-step diffusion model.

Common situations: Copying a diffusers-style Attention config into an ACE model loader; enabling cross-attention-only mode without also wiring the added KV projection dim; checkpoint config drift where added_kv_proj_dim was dropped during serialization.

Related errors


AI-assisted analysis of Comfy-Org/ComfyUI@1c6d8d45b3 (2026-08-14). Data as JSON: /api/errors/745a2b1df0aceea2. Report an issue: GitHub.