{"record":{"id":"3a28ddc3a5b65978","repo":"PaddlePaddle/PaddleOCR","slug":"invalid-layer-type-layer-type","errorCode":null,"errorMessage":"invalid layer type {layer_type}","messagePattern":"invalid layer type (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"ppocr/modeling/heads/rec_latexocr_head.py","lineNumber":595,"sourceCode":"                + (\"f\",) * sandwich_coef\n            )\n        else:\n            layer_types = default_block * depth\n\n        self.layer_types = layer_types\n        self.num_attn_layers = len(list(filter(equals(\"a\"), layer_types)))\n        for layer_type in self.layer_types:\n            if layer_type == \"a\":\n                layer = Attention(\n                    dim, heads=heads, causal=causal, is_export=is_export, **attn_kwargs\n                )\n            elif layer_type == \"c\":\n                layer = Attention(dim, heads=heads, is_export=is_export, **attn_kwargs)\n            elif layer_type == \"f\":\n                layer = FeedForward(dim, **ff_kwargs)\n                layer = layer if not macaron else Scale(0.5, layer)\n            else:\n                raise Exception(f\"invalid layer type {layer_type}\")\n            if isinstance(layer, Attention) and exists(branch_fn):\n                layer = branch_fn(layer)\n            residual_fn = Residual()\n            self.layers.append(nn.LayerList([norm_fn(), layer, residual_fn]))\n\n    def forward(\n        self,\n        x,\n        context=None,\n        mask=None,\n        context_mask=None,\n        mems=None,\n        seq_len=0,\n        return_hiddens=False,\n    ):\n        assert not (\n            self.cross_attend ^ exists(context)\n        ), \"context must be passed in if cross_attend is set to True\"","sourceCodeStart":577,"sourceCodeEnd":613,"githubUrl":"https://github.com/PaddlePaddle/PaddleOCR/blob/2661c7c0ef5c613e8f93c6e93b2e052399f0f854/ppocr/modeling/heads/rec_latexocr_head.py#L577-L613","documentation":"Thrown while building the Transformer stack in the LaTeX-OCR recognition head. The constructor iterates over the layer_types string and maps each character to a module: 'a' = causal self-attention, 'c' = non-causal attention, 'f' = feed-forward. Any other character falls into the else branch and raises.","triggerScenarios":"Setting Head.enc_layer_types or Head.dec_layer_types in the LaTeXOCR config to a string containing characters other than 'a', 'c', 'f' (e.g. \"acafcX\", \"a-ttn\", uppercase \"A\", or a typo like \"g\"). The exception fires during model construction, before any training/inference step.","commonSituations":"Editing a copied LaTeX-OCR yml config and mistyping the layer string; porting a config from another transformer implementation that uses letters like 't' or 'm'; accidentally including whitespace, separators, or uppercase letters in the layer string.","solutions":["Fix the layer type string so it only contains 'a', 'c', 'f' (e.g. enc_layer_types: \"aacfc\", dec_layer_types: \"cacfc\")","If you intended a new layer kind, subclass the Transformer wrapper in rec_latexocr_head.py and add an elif branch for your character before the else","Verify the config actually loaded the values you expect (print the head args) to rule out YAML indentation mistakes that silently change the string"],"exampleFix":"# before (config yml)\nHead:\n  enc_layer_types: \"aatfc\"   # 't' is invalid\n# after\nHead:\n  enc_layer_types: \"aacfc\"","handlingStrategy":"validation","validationCode":"VALID = set('acf')\ndef check_layer_types(s):\n    bad = set(str(s)) - VALID\n    if bad:\n        raise ValueError(f\"invalid layer types {sorted(bad)}; allowed: a, c, f\")\n    return s\n# before building the model:\n# check_layer_types(cfg['Head']['enc_layer_types'])\n# check_layer_types(cfg['Head']['dec_layer_types'])","typeGuard":"def is_layer_type_str(v) -> bool:\n    return isinstance(v, str) and len(v) > 0 and set(v) <= {'a', 'c', 'f'}","tryCatchPattern":"try:\n    model = build_model(cfg)\nexcept Exception as e:\n    if 'invalid layer type' in str(e):\n        raise ValueError(f\"config layer_types invalid: {e}\") from e\n    raise","preventionTips":["Validate layer-type strings against {'a','c','f'} in config-loading code","Keep a schema/pytest for LaTeX-OCR configs that regex-matches ^[acf]+$","Copy layer strings verbatim from the shipped config templates"],"tags":["config","transformer","latex-ocr","validation"],"backgroundTag":null,"analyzedSha":"2661c7c0ef5c613e8f93c6e93b2e052399f0f854","analyzedAt":"2026-08-14T20:17:30.180Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}