PaddlePaddle/PaddleOCR · error · ValueError

Make sure that when passing `sliding_window` that its value

Error message

Make sure that when passing `sliding_window` that its value is a strictly positive integer, not `{self.sliding_window}`

What it means

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.

Source

Thrown at ppocr/modeling/heads/rec_unimernet_head.py:289

        is_causal (bool): Indicates if the attention mechanism is causal.
        sliding_window (Optional[int]): Specifies the size of the sliding window
                                        for local attention, if applicable.

    Args:
        is_causal (bool): Determines if the attention mask should enforce causality.
        sliding_window (Optional[int], optional): The size of the sliding window
                                                  for local attention. Default is None.
    """

    is_causal: bool
    sliding_window: int

    def __init__(self, is_causal: bool, sliding_window=None):
        self.is_causal = is_causal
        self.sliding_window = sliding_window

        if self.sliding_window is not None and self.sliding_window <= 0:
            raise ValueError(
                f"Make sure that when passing `sliding_window` that its value is a strictly positive integer, not `{self.sliding_window}`"
            )

    @staticmethod
    def _make_causal_mask(
        input_ids_shape,
        dtype,
        past_key_values_length=0,
        sliding_window=None,
        is_export=False,
    ):
        bsz, tgt_len = input_ids_shape
        if is_export:
            mask = paddle.full(
                (tgt_len, tgt_len), paddle.finfo(dtype).min, dtype="float64"
            )
        else:
            mask = paddle.full((tgt_len, tgt_len), paddle.finfo(dtype).min)

View on GitHub (pinned to 2661c7c0ef)

Solutions

  1. Set sliding_window to a positive int (e.g. 1024) or null to disable
  2. Validate computed window sizes before instantiating the model
  3. Cross-check the shipped UniMERNet config template for the intended value

Example fix

# before (config yml)
Head:
  sliding_window: 0
# after
Head:
  sliding_window: null  # or a positive int such as 1024
Defensive patterns

Strategy: validation

Validate before calling

def check_sliding_window(v):
    if v is not None and (not isinstance(v, int) or v <= 0):
        raise ValueError(f'sliding_window must be a positive int or None, got {v!r}')
    return v

Type guard

def valid_sliding_window(v) -> bool:
    return v is None or (isinstance(v, int) and not isinstance(v, bool) and v > 0)

Try / catch

try:
    model = build_model(cfg)
except ValueError as e:
    if 'sliding_window' in str(e):
        cfg['Head']['sliding_window'] = None
        model = build_model(cfg)
    else:
        raise

Prevention

When it happens

Trigger: Building the UniMERNet head with config field sliding_window set to 0, negative, or a computed expression that evaluates <= 0 while not being None.

Common situations: 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.

Related errors


AI-assisted analysis of PaddlePaddle/PaddleOCR@2661c7c0ef (2026-08-14). Data as JSON: /api/errors/845f785de74f0e4b. Report an issue: GitHub.