{"record":{"id":"117b94800a272c22","repo":"invoke-ai/InvokeAI","slug":"lllite-module-name-targets-block-block-idx","errorCode":null,"errorMessage":"LLLite module '{name}' targets block {block_idx}, but the transformer has only {len(blocks)} blocks","messagePattern":"LLLite module '(.+?)' targets block (.+?), but the transformer has only (.+?) blocks","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"invokeai/backend/anima/control_net_lllite.py","lineNumber":547,"sourceCode":"\n        LIFO contract: each bind saves the forward that was CURRENT at bind\n        time, so when multiple adapters are stacked on one transformer they\n        must be restored in reverse apply order. Restoring an earlier adapter\n        first would delete a later adapter's wrapper and re-pin the earlier\n        one's saved forward.\n        \"\"\"\n        for m in self.lllite_modules:\n            m.unbind()\n\n    @staticmethod\n    def _resolve_target(transformer: nn.Module, name: str) -> nn.Module:\n        match = MODULE_NAME_PATTERN.match(name)\n        if match is None:\n            raise ValueError(f\"Unrecognized LLLite module name: '{name}'\")\n        block_idx = int(match.group(1))\n        blocks = transformer.blocks\n        if block_idx >= len(blocks):\n            raise ValueError(\n                f\"LLLite module '{name}' targets block {block_idx}, but the transformer has only {len(blocks)} blocks\"\n            )\n        target: nn.Module = blocks[block_idx]\n        for attr in _SUFFIX_TO_ATTR_PATH[match.group(2)]:\n            target = getattr(target, attr)\n        return target\n","sourceCodeStart":529,"sourceCodeEnd":554,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/backend/anima/control_net_lllite.py#L529-L554","documentation":"After the module name parses, _resolve_target checks the block index against the transformer's actual depth. If the name targets block N but transformer.blocks has fewer than N+1 blocks, the layer does not exist and the library raises ValueError rather than indexing out of range.","triggerScenarios":"apply_to(transformer) where an adapter name like 'blocks30.ff.net.0.proj' is applied to a transformer with e.g. 28 blocks — a shallower model than the adapter was trained on.","commonSituations":"Adapter trained on a deep (e.g. 36-block) Anima model applied to a distilled or smaller variant; changed num_blocks in model config after adapter training.","solutions":["Match the adapter to a base transformer with at least as many blocks as it targets.","Filter out or remap adapter entries whose block indices exceed len(transformer.blocks).","Verify model config (number of transformer blocks) hasn't changed relative to the adapter's training config."],"exampleFix":"// before\nlllite.apply_to(transformer_distilled)  # 28 blocks, adapter targets block 30\n// after\nlllite.apply_to(transformer_full)  # 36 blocks, matches adapter","handlingStrategy":"validation","validationCode":"max_block = max(int(re.search(r\"blocks(\\d+)\", m[\"lllite_name\"]).group(1)) for m in adapter_modules)\nassert max_block < len(transformer.blocks)","typeGuard":"def fits_transformer(names: list[str], transformer) -> bool:\n    return all(int(n.split(\"blocks\")[1].split(\".\")[0] if \".\" in n else re.search(r\"\\d+\", n).group()) < len(transformer.blocks) for n in names)","tryCatchPattern":"try:\n    lllite.apply_to(transformer)\nexcept ValueError as e:\n    if \"has only\" in str(e):\n        logger.error(\"Adapter targets a deeper transformer than loaded: %s\", e)\n    raise","preventionTips":["Record the base model depth with the adapter and verify len(transformer.blocks) first.","Filter adapter entries whose block index exceeds model depth at load time.","Pin model versions in graph definitions."],"tags":["pytorch","indexing","controlnet","config"],"backgroundTag":"index-out-of-range","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}