{"record":{"id":"72ee55bdae66fcb1","repo":"sgl-project/sglang","slug":"bad-compress-ratio-compress-ratio","errorCode":null,"errorMessage":"bad compress_ratio {compress_ratio}","messagePattern":"bad compress_ratio (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/kernels/ops/attention/dsv4/unified_kv_kernels/runtime.py","lineNumber":420,"sourceCode":"    c128_page_indices: Optional[torch.Tensor],\n    c4_sparse_page_indices: Optional[torch.Tensor],\n) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]:\n    \"\"\"Build ragged prefill indices: prefix (SWA ring + swa_pages + compressed) into unified_kv + extend into current-chunk kv; returns (prefix_indices, prefix_indptr, extend_indices, extend_indptr).\"\"\"\n    device = state_slot.device\n    T = state_slot.shape[0]\n    assert positions.is_contiguous() and chunk_start.is_contiguous()\n    assert cu_q.is_contiguous() and state_slot.is_contiguous()\n\n    if compress_ratio == 0:\n        page_idx = None\n    elif compress_ratio == 128:\n        assert c128_page_indices is not None\n        page_idx = c128_page_indices[:T]\n    elif compress_ratio == 4:\n        assert c4_sparse_page_indices is not None\n        page_idx = c4_sparse_page_indices[:T]\n    else:\n        raise ValueError(f\"bad compress_ratio {compress_ratio}\")\n\n    has_compress = page_idx is not None\n    if has_compress:\n        assert page_idx.is_contiguous()\n    Wc = page_idx.shape[1] if has_compress else 0\n\n    block = min(1024, triton.next_power_of_2(max(win, Wc, 1)))\n    prefix_len = torch.empty(T, dtype=torch.int32, device=device)\n    extend_len = torch.empty(T, dtype=torch.int32, device=device)\n    _prefill_lengths_kernel[(T,)](\n        positions,\n        chunk_start,\n        page_idx if has_compress else positions,  # dummy ptr when no compress\n        prefix_len,\n        extend_len,\n        win=win,\n        Wc=Wc if has_compress else 1,\n        HAS_COMPRESS=has_compress,","sourceCodeStart":402,"sourceCodeEnd":438,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/kernels/ops/attention/dsv4/unified_kv_kernels/runtime.py#L402-L438","documentation":"build_prefill_indices only supports compress_ratio values 0 (no compression), 128 (C128 full-context pages), and 4 (C4 sparse pages). Any other ratio hits the else branch and raises ValueError.","triggerScenarios":"Calling build_prefill_indices with compress_ratio not in {0, 128, 4} — e.g. a config exposing 16, 32, or 64, or an uninitialized/None value coerced to an unexpected int.","commonSituations":"Adding a new compression granularity to the DSV4 unified-KV runtime without extending this dispatcher; a typo in config plumbing; a default value that was never updated when the API changed from a boolean to a ratio.","solutions":["Set compress_ratio to one of the supported values: 0, 128, or 4","If you need a new ratio, extend the if/elif chain in build_prefill_indices and provide the matching page-indices tensor","Trace where compress_ratio is computed (scheduler/config) and validate it against the allowed set early"],"exampleFix":"// before\nidx = build_prefill_indices(..., compress_ratio=64)\n// after\nidx = build_prefill_indices(..., compress_ratio=128)  # or 0 / 4","handlingStrategy":"validation","validationCode":"assert compress_ratio in (0, 4, 128), f\"unsupported compress_ratio {compress_ratio}\"","typeGuard":"def compress_ratio_ok(r: int) -> bool:\n    return r in (0, 4, 128)","tryCatchPattern":"try:\n    idx = build_prefill_indices(..., compress_ratio=cr)\nexcept ValueError:\n    cr = 0  # fall back to no compression\n    idx = build_prefill_indices(..., compress_ratio=cr)","preventionTips":["Validate config-derived enums at config-parse time, not deep in kernels","Keep the allowed-ratio set defined in one constant shared by config and runtime"],"tags":["deepseek","sparse-attention","indexing","config-validation"],"backgroundTag":"unsupported-argument-value","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}