{"record":{"id":"845f785de74f0e4b","repo":"PaddlePaddle/PaddleOCR","slug":"make-sure-that-when-passing-sliding-window-that-845f78","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_unimernet_head.py","lineNumber":289,"sourceCode":"        is_causal (bool): Indicates if the attention mechanism is causal.\n        sliding_window (Optional[int]): Specifies the size of the sliding window\n                                        for local attention, if applicable.\n\n    Args:\n        is_causal (bool): Determines if the attention mask should enforce causality.\n        sliding_window (Optional[int], optional): The size of the sliding window\n                                                  for local attention. Default is None.\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        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\"\n            )\n        else:\n            mask = paddle.full((tgt_len, tgt_len), paddle.finfo(dtype).min)","sourceCodeStart":271,"sourceCodeEnd":307,"githubUrl":"https://github.com/PaddlePaddle/PaddleOCR/blob/2661c7c0ef5c613e8f93c6e93b2e052399f0f854/ppocr/modeling/heads/rec_unimernet_head.py#L271-L307","documentation":"The UniMERNet head's _MaskConverter validates sliding_window the same way as PP-FormulaNet: windowed attention requires a strictly positive window size, and 0/negative values raise ValueError at construction.","triggerScenarios":"Building the UniMERNet head with config field sliding_window set to 0, negative, or a computed expression that evaluates <= 0 while not being None.","commonSituations":"Disabling the window by writing 0 instead of null; configs derived from a paper setting where the window is derived from max length; merging configs across UniMERNet variants with different window defaults.","solutions":["Set sliding_window to a positive int (e.g. 1024) or null to disable","Validate computed window sizes before instantiating the model","Cross-check the shipped UniMERNet config template for the intended value"],"exampleFix":"# before (config yml)\nHead:\n  sliding_window: 0\n# after\nHead:\n  sliding_window: null  # or a positive int such as 1024","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","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 to disable the window, never 0","Copy the sliding_window value from the official UniMERNet config","Lint config fields whose value must be positive-or-null"],"tags":["config","attention-mask","unimernet","validation"],"backgroundTag":null,"analyzedSha":"2661c7c0ef5c613e8f93c6e93b2e052399f0f854","analyzedAt":"2026-08-14T20:17:30.180Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}