{"record":{"id":"745a2b1df0aceea2","repo":"Comfy-Org/ComfyUI","slug":"only-cross-attention-can-only-be-set-to-true-if","errorCode":null,"errorMessage":"`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`.","messagePattern":"`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`\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy/ldm/ace/attention.py","lineNumber":83,"sourceCode":"        self.out_context_dim = out_context_dim if out_context_dim is not None else query_dim\n        self.context_pre_only = context_pre_only\n        self.pre_only = pre_only\n        self.is_causal = is_causal\n\n        self.scale_qk = scale_qk\n        self.scale = dim_head**-0.5 if self.scale_qk else 1.0\n\n        self.heads = out_dim // dim_head if out_dim is not None else heads\n        # for slice_size > 0 the attention score computation\n        # is split across the batch axis to save memory\n        # You can set slice_size with `set_attention_slice`\n        self.sliceable_head_dim = heads\n\n        self.added_kv_proj_dim = added_kv_proj_dim\n        self.only_cross_attention = only_cross_attention\n\n        if self.added_kv_proj_dim is None and self.only_cross_attention:\n            raise ValueError(\n                \"`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`.\"\n            )\n\n        self.group_norm = None\n        self.spatial_norm = None\n\n        self.norm_q = None\n        self.norm_k = None\n\n        self.norm_cross = None\n        self.to_q = operations.Linear(query_dim, self.inner_dim, bias=bias, dtype=dtype, device=device)\n\n        if not self.only_cross_attention:\n            # only relevant for the `AddedKVProcessor` classes\n            self.to_k = operations.Linear(self.cross_attention_dim, self.inner_kv_dim, bias=bias, dtype=dtype, device=device)\n            self.to_v = operations.Linear(self.cross_attention_dim, self.inner_kv_dim, bias=bias, dtype=dtype, device=device)\n        else:\n            self.to_k = None","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy/ldm/ace/attention.py#L65-L101","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Set added_kv_proj_dim to the conditioning width (e.g. the text/audio embedding dim) in the attention config","Set only_cross_attention=False (or omit it) if you do not need cross-only attention","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"],"exampleFix":"# before\nattn = Attention(query_dim=1024, only_cross_attention=True)  # added_kv_proj_dim missing\n\n# after\nattn = Attention(query_dim=1024, only_cross_attention=False)\n# or\nattn = Attention(query_dim=1024, added_kv_proj_dim=768, only_cross_attention=True)","handlingStrategy":"validation","validationCode":"def build_attention(query_dim, cfg):\n    if cfg.get('only_cross_attention') and cfg.get('added_kv_proj_dim') is None:\n        cfg = {**cfg, 'only_cross_attention': False}\n    return Attention(query_dim, **cfg)","typeGuard":"def is_valid_attention_cfg(cfg: dict) -> bool:\n    return not (cfg.get('only_cross_attention', False) and cfg.get('added_kv_proj_dim') is None)","tryCatchPattern":null,"preventionTips":["Treat only_cross_attention=True as requiring added_kv_proj_dim by definition; never set one without the other","Validate attention config dicts against required-key invariants before constructing modules","Load configs from the checkpoint's original JSON instead of hand-writing them"],"tags":["config","attention","constructor-validation"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}