{"record":{"id":"dfc4583fea1fa0c2","repo":"sgl-project/sglang","slug":"miss-src-must-be-int64-and-miss-dst-must-be-int32","errorCode":null,"errorMessage":"miss_src must be int64 and miss_dst must be int32.","messagePattern":"miss_src must be int64 and miss_dst must be int32\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/kernels/ops/kvcache/hisparse.py","lineNumber":109,"sourceCode":"    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 \"\n                f\"[batch, >= steps * top_k] (capacity {plan_capacity}).\"\n            )\n        if miss_count.ndim != 1 or miss_count.numel() < batch_size:\n            raise ValueError(\"speculative miss_count must have shape [batch].\")","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/kernels/ops/kvcache/hisparse.py#L91-L127","documentation":"Part of the miss-plan validation: the kernel ABI expects miss_src as int64 (host row indices) and miss_dst as int32 (device slot indices). Wrong dtypes would silently truncate or misindex in the CUDA kernel, so they are rejected before launch.","triggerScenarios":"Calling load_cache_to_device_buffer_spec_mla with miss_plan enabled and miss_src not torch.int64 or miss_dst not torch.int32 (e.g. both allocated as int32 or both as int64).","commonSituations":"Allocating plan tensors with a single dtype for convenience; converting from a numpy array whose default integer width differs by platform.","solutions":["Allocate miss_src with dtype=torch.int64 and miss_dst with dtype=torch.int32","Double-check miss_count is int32 as well","Keep one shared helper that allocates the correctly-typed triple"],"exampleFix":"# before\nmiss_src = torch.zeros(bs, cap, dtype=torch.int32, device=dev)\n# after\nmiss_src = torch.zeros(bs, cap, dtype=torch.int64, device=dev)","handlingStrategy":"type-guard","validationCode":"assert miss_src.dtype == torch.int64 and miss_dst.dtype == torch.int32","typeGuard":"def miss_plan_dtypes_ok(s, d) -> bool:\n    return s is None or (s.dtype == torch.int64 and d.dtype == torch.int32)","tryCatchPattern":null,"preventionTips":["Use the documented dtypes when allocating plan tensors","Centralize plan-tensor allocation in one function"],"tags":["hisparse","dtype-validation","miss-plan"],"backgroundTag":"dtype-mismatch","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}