{"record":{"id":"2ebfe276b84b68f6","repo":"sgl-project/sglang","slug":"sampling-factor-should-be-a-multiply-of-2","errorCode":null,"errorMessage":"Sampling factor should be a multiply of 2!","messagePattern":"Sampling factor should be a multiply of 2!","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/models/phi4mm_utils.py","lineNumber":1098,"sourceCode":"    def __init__(\n        self,\n        feat_in,\n        feat_out,\n        subsampling_factor=4,\n        subsampling=\"dw_striding\",\n        conv_channels=256,\n        subsampling_conv_chunking_factor=1,\n        activation=nn.ReLU(),  # noqa: B008\n        is_causal=False,\n    ):\n        super().__init__()\n        self._subsampling = subsampling\n        self._conv_channels = conv_channels\n        self._feat_in = feat_in\n        self._feat_out = feat_out\n\n        if subsampling_factor % 2 != 0:\n            raise ValueError(\"Sampling factor should be a multiply of 2!\")\n        self._sampling_num = int(math.log(subsampling_factor, 2))\n        self.subsampling_factor = subsampling_factor\n        self.is_causal = is_causal\n        self.subsampling_causal_cond = subsampling in (\n            \"dw_striding\",\n            \"striding\",\n            \"striding_conv1d\",\n        )\n\n        if (\n            subsampling_conv_chunking_factor != -1\n            and subsampling_conv_chunking_factor != 1\n            and subsampling_conv_chunking_factor % 2 != 0\n        ):\n            raise ValueError(\n                \"subsampling_conv_chunking_factor should be -1, 1, or a \" \"power of 2\"\n            )\n        self.subsampling_conv_chunking_factor = subsampling_conv_chunking_factor","sourceCodeStart":1080,"sourceCodeEnd":1116,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/models/phi4mm_utils.py#L1080-L1116","documentation":"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__.","triggerScenarios":"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.","commonSituations":"Configuring a new audio frontend where input_feat_ratio/model chunk size yields an odd subsampling factor; editing configs to experiment with compression rates.","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"],"exampleFix":"# before\nConvSubsampling(subsampling_factor=3, ...)  # ValueError\n# after\nConvSubsampling(subsampling_factor=4, ...)","handlingStrategy":"validation","validationCode":"assert subsampling_factor > 0 and subsampling_factor % 2 == 0, \"subsampling_factor must be a power of two\"","typeGuard":"def is_power_of_two(n: int) -> bool:\n    return n > 0 and (n & (n - 1)) == 0","tryCatchPattern":null,"preventionTips":["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"],"tags":["subsampling","convolution","audio","config-validation","phi4"],"backgroundTag":"invalid-config-value","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}