sgl-project/sglang · error · ValueError

patch_size must be greater than 1, otherwise this doesn't ma

Error message

patch_size must be greater than 1, otherwise this doesn't make sense

What it means

plan_out_scales refuses patch_size <= 1 because the whole point of patch planning is to compute downscaled (time,height,width,channel) shapes per HMLP layer; with patch 1 there is no downsampling and the scale plan is meaningless. It is a configuration sanity check at model init time.

Source

Thrown at python/sglang/srt/models/inkling_common/hmlp.py:42

    p = 3
    while p * p <= n:
        while n % p == 0:
            factors.append(p)
            n //= p
        p += 2

    if n > 1:
        factors.append(n)
    return factors


def plan_out_scales(
    temporal_patch_size: int, patch_size: int, n_layers: int, n_channels: int = 3
) -> list[tuple[int, int, int, int]]:
    """Plan the ``(time, height, width, channels)`` scale at each HMLP layer."""
    if patch_size <= 1:
        raise ValueError(
            "patch_size must be greater than 1, otherwise this doesn't make sense"
        )

    def _round_up(x: int) -> int:
        return int(np.ceil(x / 64)) * 64

    last_h_scale = 1
    scales: list[tuple[int, int, int, int]] = [(1, 1, 1, n_channels)]
    for pscale in _prime_factors(patch_size)[::-1]:
        last_h_scale *= pscale
        scales.append(
            (
                1,
                last_h_scale,
                last_h_scale,
                _round_up((last_h_scale**2) * n_channels),
            )
        )

View on GitHub (pinned to 0132848349)

Solutions

  1. Set a real patch size (> 1, e.g. 14 or 16) in the vision config
  2. Check argument order if calling plan_out_scales manually — patch_size is the 2nd positional arg
  3. If the model truly has no patching, bypass the HMLP scale planner rather than passing 1

Example fix

# before
plan_out_scales(temporal_patch_size=2, patch_size=1, n_layers=8)
# after
plan_out_scales(temporal_patch_size=2, patch_size=16, n_layers=8)
Defensive patterns

Strategy: validation

Validate before calling

assert patch_size > 1, f"patch_size={patch_size} must be > 1"
plan_out_scales(temporal_patch_size, patch_size, n_layers)

Type guard

def valid_patch_size(p) -> bool: return isinstance(p, int) and p > 1

Prevention

When it happens

Trigger: Constructing the Inkling HMLP (init -> plan_out_scales) with a vision config whose patch_size is 1 or 0 (or a temporal_patch_size mistakenly passed in the patch_size slot).

Common situations: Custom/converted vision encoder configs with patch_size: 1; argument order mistakes when calling plan_out_scales directly; text-only configs reused for a vision tower; typos in exported checkpoints.

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/a7ff4e04dd9fef20. Report an issue: GitHub.