{"record":{"id":"33215dd8838cce94","repo":"sgl-project/sglang","slug":"miss-src-miss-dst-and-miss-count-must-be-provide","errorCode":null,"errorMessage":"miss_src, miss_dst, and miss_count must be provided together.","messagePattern":"miss_src, miss_dst, and miss_count must be provided together\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/kernels/ops/kvcache/hisparse.py","lineNumber":105,"sourceCode":") -> None:\n    \"\"\"Resolve all speculative steps and swap unique misses in one launch pair.\n\n    Optional miss-plan outputs use the same protocol as the single-step HiSparse\n    kernel, so shared-index layers can replay only the Host-to-GPU copies with\n    ``copy_cache_planned_mla``.\n    \"\"\"\n    _, num_steps, num_top_k = top_k_tokens.shape\n    if not 2 <= num_steps <= 4:\n        raise ValueError(\n            f\"HiSparse speculative swap requires 2-4 steps, got {num_steps}.\"\n        )\n    hot_buffer_size = state.cache_policy.size(1)\n    page_size = device_buffer_tokens.size(1) - hot_buffer_size\n    item_size_bytes = host_cache.stride(0) * host_cache.element_size()\n    record_miss_plan = miss_src is not None\n    if record_miss_plan:\n        if miss_dst is None or miss_count is None:\n            raise ValueError(\n                \"miss_src, miss_dst, and miss_count must be provided together.\"\n            )\n        if miss_src.dtype != torch.int64 or miss_dst.dtype != torch.int32:\n            raise ValueError(\"miss_src must be int64 and miss_dst must be int32.\")\n        if miss_count.dtype != torch.int32:\n            raise ValueError(\"miss_count must be int32.\")\n        plan_capacity = num_steps * num_top_k\n        batch_size = top_k_tokens.size(0)\n        if (\n            miss_src.ndim != 2\n            or miss_dst.ndim != 2\n            or miss_src.size(0) < batch_size\n            or miss_dst.size(0) < batch_size\n            or miss_src.size(1) < plan_capacity\n            or miss_dst.size(1) < plan_capacity\n        ):\n            raise ValueError(\n                \"speculative miss_src/miss_dst must have shape \"","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/kernels/ops/kvcache/hisparse.py#L87-L123","documentation":"The speculative HiSparse loader's optional miss-plan recording takes a triple of tensors (miss_src, miss_dst, miss_count) that are written together by the kernel. Supplying miss_src without the other two (this branch triggers when miss_dst or miss_count is None while miss_src is set) would leave the plan half-initialized, so all three must be provided or none.","triggerScenarios":"Calling load_cache_to_device_buffer_spec_mla with miss_src set but miss_dst=None or miss_count=None.","commonSituations":"Wrapping the API and defaulting only some tensors to None; refactoring call sites that added miss-plan recording incrementally.","solutions":["Provide all three: miss_src (int64), miss_dst (int32), miss_count (int32)","Or pass none of them to disable miss-plan recording","Audit wrapper defaults so the three parameters default together"],"exampleFix":"# before\nload_cache_to_device_buffer_spec_mla(..., miss_src=src)\n# after\nload_cache_to_device_buffer_spec_mla(..., miss_src=src, miss_dst=dst, miss_count=cnt)","handlingStrategy":"validation","validationCode":"provided = (miss_src is not None, miss_dst is not None, miss_count is not None)\nassert all(provided) or not any(provided), 'miss-plan tensors are all-or-none'","typeGuard":"def miss_plan_args_consistent(s, d, c) -> bool:\n    p = (s is not None, d is not None, c is not None)\n    return all(p) or not any(p)","tryCatchPattern":null,"preventionTips":["Allocate the miss-plan triple in one helper so they always appear together"],"tags":["hisparse","argument-validation","all-or-none"],"backgroundTag":"missing-required-parameter","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}