{"record":{"id":"62d858760b014842","repo":"sgl-project/sglang","slug":"subsampling-conv-chunking-factor-should-be-1-1","errorCode":null,"errorMessage":"subsampling_conv_chunking_factor should be -1, 1, or a power of 2","messagePattern":"subsampling_conv_chunking_factor should be -1, 1, or a power of 2","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/models/phi4mm_utils.py","lineNumber":1113,"sourceCode":"        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\n\n        in_channels = 1\n        layers = []\n\n        if subsampling == \"dw_striding\":\n            self._stride = 2\n            self._kernel_size = 3\n            self._ceil_mode = False\n\n            if self.is_causal:\n                self._left_padding = self._kernel_size - 1\n                self._right_padding = self._stride - 1\n                self._max_cache_len = subsampling_factor + 1\n            else:\n                self._left_padding = (self._kernel_size - 1) // 2","sourceCodeStart":1095,"sourceCodeEnd":1131,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/models/phi4mm_utils.py#L1095-L1131","documentation":"ConvSubsampling's chunked-convolution memory optimization parameter subsampling_conv_chunking_factor only accepts -1 (disabled), 1, or powers of 2. Odd values other than 1 fail the check and raise ValueError because chunk sizes must evenly divide the strided conv stacks.","triggerScenarios":"Constructing ConvSubsampling with subsampling_conv_chunking_factor set to 3, 5, 6, or any non-power-of-two > 1.","commonSituations":"Tuning memory usage during long-audio inference and picking an arbitrary chunk factor; porting configs from NeMo where the default is -1; env-driven overrides injecting odd values.","solutions":["Use -1 to disable chunking (default, safest)","Use 1 or a power of 2 (2, 4, 8, ...) as the chunking factor","Verify the value if it comes from a serialized or programmatically computed config"],"exampleFix":"# before\nConvSubsampling(..., subsampling_conv_chunking_factor=6)  # ValueError\n# after\nConvSubsampling(..., subsampling_conv_chunking_factor=4)","handlingStrategy":"validation","validationCode":"v = subsampling_conv_chunking_factor\nassert v == -1 or v == 1 or (v > 0 and v % 2 == 0), \"must be -1, 1, or power of 2\"","typeGuard":"def is_valid_chunking_factor(v: int) -> bool:\n    return v in (-1, 1) or (v > 0 and (v & (v - 1)) == 0)","tryCatchPattern":null,"preventionTips":["Leave subsampling_conv_chunking_factor at -1 unless memory tuning demands chunking","When tuning, restrict choices to powers of two"],"tags":["subsampling","chunking","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"}