{"record":{"id":"8b1df58613a50e9d","repo":"PaddlePaddle/PaddleOCR","slug":"sliding-window-is-currently-only-implemented-for-c","errorCode":null,"errorMessage":"Sliding window is currently only implemented for causal masking","messagePattern":"Sliding window is currently only implemented for causal masking","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"ppocr/modeling/heads/rec_ppformulanet_head.py","lineNumber":219,"sourceCode":"                causal_4d_mask = self._make_causal_mask_parallel(\n                    input_shape,\n                    dtype,\n                    past_key_values_length=past_key_values_length,\n                    sliding_window=self.sliding_window,\n                    parallel_step=parallel_step,\n                    is_export=is_export,\n                )\n            else:\n                causal_4d_mask = self._make_causal_mask(\n                    input_shape,\n                    dtype,\n                    past_key_values_length=past_key_values_length,\n                    sliding_window=self.sliding_window,\n                    is_export=is_export,\n                )\n\n        elif self.sliding_window is not None:\n            raise NotImplementedError(\n                \"Sliding window is currently only implemented for causal masking\"\n            )\n\n        expanded_attn_mask = self._expand_mask(\n            attention_mask_2d, dtype, tgt_len=input_shape[-1]\n        )\n\n        if causal_4d_mask is not None:\n            expanded_attn_mask = causal_4d_mask.masked_fill_(\n                expanded_attn_mask.cast(paddle.bool), paddle.finfo(dtype).min\n            )\n\n        expanded_4d_mask = expanded_attn_mask\n        return expanded_4d_mask\n\n    def to_4d_export(\n        self,\n        attention_mask_2d,","sourceCodeStart":201,"sourceCodeEnd":237,"githubUrl":"https://github.com/PaddlePaddle/PaddleOCR/blob/2661c7c0ef5c613e8f93c6e93b2e052399f0f854/ppocr/modeling/heads/rec_ppformulanet_head.py#L201-L237","documentation":"Sliding-window masking in the PP-FormulaNet head is only implemented inside the causal-mask code path. If the converter was built with a sliding_window but is_causal=False, the causal branch is skipped and the elif raises NotImplementedError.","triggerScenarios":"Building the model with a positive sliding_window value while the mask converter is configured with is_causal=False (bidirectional/full attention), then running any forward pass that converts the 2D mask to 4D.","commonSituations":"Copying an encoder config (non-causal) but keeping the decoder's sliding_window key; experimenting with bidirectional attention for a formula model and leaving sliding_window set; merging configs from PP-FormulaNet variants where only the decoder is causal.","solutions":["Remove sliding_window (set to null) if you want non-causal attention","Keep sliding_window but set is_causal: true so the causal masking path (which implements windowing) runs","If bidirectional windowed attention is truly needed, implement a non-causal windowed mask in _make_causal_mask-style helper and extend the elif branch"],"exampleFix":"# before (config yml)\nHead:\n  is_causal: false\n  sliding_window: 512\n# after\nHead:\n  is_causal: false\n  sliding_window: null","handlingStrategy":"validation","validationCode":"def check_mask_config(is_causal, sliding_window):\n    if sliding_window is not None and not is_causal:\n        raise ValueError('sliding_window requires is_causal=True in this head; set sliding_window to null for non-causal attention')\n    return is_causal, sliding_window","typeGuard":"def window_compatible(cfg) -> bool:\n    sw = cfg.get('sliding_window')\n    return sw is None or bool(cfg.get('is_causal'))","tryCatchPattern":"null  # configuration error; fail fast rather than catching","preventionTips":["Pair sliding_window only with causal decoders in configs","Add a config lint rule: sliding_window != null implies is_causal true","Document in project README which head fields are decoder-only"],"tags":["config","attention-mask","ppformulanet","not-implemented"],"backgroundTag":null,"analyzedSha":"2661c7c0ef5c613e8f93c6e93b2e052399f0f854","analyzedAt":"2026-08-14T20:17:30.180Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}