{"record":{"id":"0c76ef0ad5c4b6da","repo":"invoke-ai/InvokeAI","slug":"ed-hidden-size-self-ed-hidden-size-must-be-divis","errorCode":null,"errorMessage":"ed_hidden_size {self.ed_hidden_size} must be divisible by ed_num_heads {self.ed_num_heads}","messagePattern":"ed_hidden_size (.+?) must be divisible by ed_num_heads (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"invokeai/backend/pid/_src/networks/pixeldit_official.py","lineNumber":1292,"sourceCode":"        self.enable_ed = bool(enable_ed)\n        self.ed_compress_ratio = int(ed_compress_ratio)\n        self.ed_depth_per_stage = int(ed_depth_per_stage)\n        self.ed_window_size = int(ed_window_size)\n        self.ed_num_heads = int(ed_num_heads) if ed_num_heads is not None else self.num_groups\n        self.ed_hidden_size = int(ed_hidden_size) if ed_hidden_size is not None else self.hidden_size\n        self.ed_use_token_shuffle = bool(ed_use_token_shuffle)\n        self.encoder_ed: Optional[_EncoderED] = None\n        self.decoder_ed: Optional[_DecoderED] = None\n        self.s_ed_proj_in: Optional[nn.Module] = None\n        self.s_ed_proj_out: Optional[nn.Module] = None\n        self.s_ed_cond_proj: Optional[nn.Module] = None\n        self.s_ed_in_norm: Optional[RMSNorm] = None\n        self.s_ed_out_norm: Optional[RMSNorm] = None\n        num_stages = _compute_num_stages_from_ratio(self.ed_compress_ratio) if self.enable_ed else 0\n        self.use_ed = self.enable_ed and num_stages > 0\n        if self.use_ed:\n            if self.ed_hidden_size % self.ed_num_heads != 0:\n                raise ValueError(\n                    f\"ed_hidden_size {self.ed_hidden_size} must be divisible by ed_num_heads {self.ed_num_heads}\"\n                )\n            self.s_ed_proj_in = (\n                nn.Identity()\n                if self.ed_hidden_size == self.hidden_size\n                else nn.Linear(self.hidden_size, self.ed_hidden_size, bias=True)\n            )\n            self.s_ed_proj_out = (\n                nn.Identity()\n                if self.ed_hidden_size == self.hidden_size\n                else nn.Linear(self.ed_hidden_size, self.hidden_size, bias=True)\n            )\n            self.s_ed_cond_proj = (\n                nn.Identity()\n                if self.ed_hidden_size == self.hidden_size\n                else nn.Linear(self.hidden_size, self.ed_hidden_size, bias=True)\n            )\n            self.s_ed_in_norm = RMSNorm(self.ed_hidden_size, eps=1e-6)","sourceCodeStart":1274,"sourceCodeEnd":1310,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/backend/pid/_src/networks/pixeldit_official.py#L1274-L1310","documentation":"PixDiT_T2I multi-head attention on the encoder-decoder (ED) path requires ed_hidden_size to be evenly divisible by ed_num_heads so the hidden dimension can be split into per-head slices. During __init__, when enable_ed is on and the computed stage count is > 0, the constructor validates this and raises ValueError if the head dimension would not be an integer. It is a configuration error caught at model construction time, before any weights are loaded or forwards run.","triggerScenarios":"Constructing PixDiT_T2I (directly or via a config) with enable_ed=True while ed_hidden_size % ed_num_heads != 0, e.g. ed_hidden_size=1024 with ed_num_heads=48 or a prime/odd head count.","commonSituations":"Hand-edited YAML/JSON model configs, porting hyperparameters from a differently sized variant, or changing ed_hidden_size for memory reasons without re-deriving a compatible head count.","solutions":["Choose ed_num_heads that divides ed_hidden_size evenly (e.g. 1024 with 8, 16, or 32 heads)","Or adjust ed_hidden_size to the nearest value divisible by the desired head count","Disable the ED path with enable_ed=False if the encoder-decoder stages are not needed"],"exampleFix":"// before\nPixDiT_T2I(ed_hidden_size=1024, ed_num_heads=48, enable_ed=True)\n// after\nPixDiT_T2I(ed_hidden_size=1024, ed_num_heads=16, enable_ed=True)","handlingStrategy":"validation","validationCode":"if enable_ed and ed_hidden_size % ed_num_heads != 0:\n    raise ValueError(\"ed_hidden_size must be divisible by ed_num_heads\")","typeGuard":null,"tryCatchPattern":"try:\n    net = PixDiT_T2I(**cfg)\nexcept ValueError as e:\n    if \"divisible\" in str(e):\n        cfg[\"ed_num_heads\"] = next(h for h in (32,16,8) if cfg[\"ed_hidden_size\"] % h == 0)\n        net = PixDiT_T2I(**cfg)\n    else:\n        raise","preventionTips":["Assert divisibility in config validation","Prefer power-of-two head counts","Test all shipped configs at import/CI time"],"tags":["configuration","value-error","attention","divisibility"],"backgroundTag":"config-value-validation-failed","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}