{"record":{"id":"89d617cdd7fbdace","repo":"PaddlePaddle/PaddleOCR","slug":"make-sure-that-when-passing-sliding-window-that","errorCode":null,"errorMessage":"Make sure that when passing `sliding_window` that its value is a strictly positive integer, not `{self.sliding_window}`","messagePattern":"Make sure that when passing `sliding_window` that its value is a strictly positive integer, not `(.+?)`","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"ppocr/modeling/heads/rec_ppformulanet_head.py","lineNumber":71,"sourceCode":"    and sliding window attention, which are commonly used in transformer models.\n\n    Attributes:\n        is_causal (bool): Flag indicating whether the attention mask should enforce causal masking,\n                          which ensures each position can only attend to previous positions.\n        sliding_window (int, optional): Size of the sliding window for local attention. If set,\n                                        attention is restricted to a local window of this size.\n\n    \"\"\"\n\n    is_causal: bool\n    sliding_window: int\n\n    def __init__(self, is_causal: bool, sliding_window=None):\n        self.is_causal = is_causal\n        self.sliding_window = sliding_window\n\n        if self.sliding_window is not None and self.sliding_window <= 0:\n            raise ValueError(\n                f\"Make sure that when passing `sliding_window` that its value is a strictly positive integer, not `{self.sliding_window}`\"\n            )\n\n    @staticmethod\n    def _make_causal_mask(\n        input_ids_shape,\n        dtype,\n        past_key_values_length=0,\n        sliding_window=None,\n        is_export=False,\n    ):\n        \"\"\"\n        Make causal mask used for bi-directional self-attention.\n        \"\"\"\n        bsz, tgt_len = input_ids_shape\n        if is_export:\n            mask = paddle.full(\n                (tgt_len, tgt_len), paddle.finfo(dtype).min, dtype=\"float64\"","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/PaddlePaddle/PaddleOCR/blob/2661c7c0ef5c613e8f93c6e93b2e052399f0f854/ppocr/modeling/heads/rec_ppformulanet_head.py#L53-L89","documentation":"_MaskConverter in the PP-FormulaNet head validates its sliding_window argument at construction. sliding_window enables local (windowed) attention; a value of 0 or a negative number is meaningless, so it raises ValueError immediately.","triggerScenarios":"Constructing the attention-mask converter (indirectly, when building PPFormulaNet / PPFormulaNetPlus models) with config field sliding_window set to 0, a negative int, or an expression that evaluates to <= 0.","commonSituations":"Trying to 'disable' sliding window by setting it to 0 instead of null/None in the config; a config default that computes window size from another parameter (e.g. max_seq_len - something) that can go non-positive for short-sequence settings.","solutions":["Set sliding_window to a strictly positive integer (e.g. 512) in the model config","Set it to null / omit it to disable windowed attention entirely","If the value is computed, clamp or validate it before it reaches the model constructor"],"exampleFix":"# before (config yml)\nHead:\n  sliding_window: 0\n# after\nHead:\n  sliding_window: null   # or e.g. 512","handlingStrategy":"validation","validationCode":"def check_sliding_window(v):\n    if v is not None and (not isinstance(v, int) or v <= 0):\n        raise ValueError(f'sliding_window must be a positive int or None, got {v!r}')\n    return v\n# check_sliding_window(cfg['Head'].get('sliding_window'))","typeGuard":"def valid_sliding_window(v) -> bool:\n    return v is None or (isinstance(v, int) and not isinstance(v, bool) and v > 0)","tryCatchPattern":"try:\n    model = build_model(cfg)\nexcept ValueError as e:\n    if 'sliding_window' in str(e):\n        cfg['Head']['sliding_window'] = None\n        model = build_model(cfg)\n    else:\n        raise","preventionTips":["Use null (not 0) to disable windowed attention","LINT config: any numeric field whose name contains 'window' must be > 0 or null","When computing window size, clamp with max(1, value) or set None"],"tags":["config","attention-mask","ppformulanet","validation"],"backgroundTag":null,"analyzedSha":"2661c7c0ef5c613e8f93c6e93b2e052399f0f854","analyzedAt":"2026-08-14T20:17:30.180Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}