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
- 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
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
- 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
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
- Make sure that when passing `sliding_window` that its value
- OCR pipeline config text must decode to an object.
- OCR pipeline config must be an object or YAML text.
- ${modulePath}.model_dir must be null or an asset descriptor
- Unsupported pipeline_name "${pipelineName}". PaddleOCR.js cu
AI-assisted analysis of PaddlePaddle/PaddleOCR@2661c7c0ef (2026-08-14).
Data as JSON: /api/errors/845f785de74f0e4b.
Report an issue: GitHub.