sgl-project/sglang · error · ValueError
Sampling factor should be a multiply of 2!
Error message
Sampling factor should be a multiply of 2!
What it means
The ConvSubsampling module only supports power-of-two subsampling factors (its internal logic takes log2 of the factor to build strided conv layers). Any subsampling_factor not divisible by 2 raises this ValueError in __init__.
Source
Thrown at python/sglang/srt/models/phi4mm_utils.py:1098
def __init__(
self,
feat_in,
feat_out,
subsampling_factor=4,
subsampling="dw_striding",
conv_channels=256,
subsampling_conv_chunking_factor=1,
activation=nn.ReLU(), # noqa: B008
is_causal=False,
):
super().__init__()
self._subsampling = subsampling
self._conv_channels = conv_channels
self._feat_in = feat_in
self._feat_out = feat_out
if subsampling_factor % 2 != 0:
raise ValueError("Sampling factor should be a multiply of 2!")
self._sampling_num = int(math.log(subsampling_factor, 2))
self.subsampling_factor = subsampling_factor
self.is_causal = is_causal
self.subsampling_causal_cond = subsampling in (
"dw_striding",
"striding",
"striding_conv1d",
)
if (
subsampling_conv_chunking_factor != -1
and subsampling_conv_chunking_factor != 1
and subsampling_conv_chunking_factor % 2 != 0
):
raise ValueError(
"subsampling_conv_chunking_factor should be -1, 1, or a " "power of 2"
)
self.subsampling_conv_chunking_factor = subsampling_conv_chunking_factorView on GitHub (pinned to 0132848349)
Solutions
- Set subsampling_factor to a power of two (2, 4, 8)
- Adjust the upstream feature hop/chunking so the required factor becomes even
- Verify the config value comes from the original checkpoint rather than a hand edit
Example fix
# before ConvSubsampling(subsampling_factor=3, ...) # ValueError # after ConvSubsampling(subsampling_factor=4, ...)
Defensive patterns
Strategy: validation
Validate before calling
assert subsampling_factor > 0 and subsampling_factor % 2 == 0, "subsampling_factor must be a power of two"
Type guard
def is_power_of_two(n: int) -> bool:
return n > 0 and (n & (n - 1)) == 0 Prevention
- Compute subsampling factor from the audio rate / token rate ratio and assert it is a power of two at config load time
- Keep the checkpoint's original value
When it happens
Trigger: Constructing ConvSubsampling with subsampling_factor of 1, 3, 5, or any odd value; subsampling_factor is often derived from the ratio of audio feature rate to LLM token rate.
Common situations: Configuring a new audio frontend where input_feat_ratio/model chunk size yields an odd subsampling factor; editing configs to experiment with compression rates.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- subsampling_conv_chunking_factor should be -1, 1, or a power
- audio_out_channels must be divisible by tp_size for TP-shard
- projection_cls = {projection_cls}, not implemented
- audio_projection_mode = {audio_projection_mode} not implemen
- Unsupported activation type {self.glu_act}
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/2ebfe276b84b68f6.
Report an issue: GitHub.