{"record":{"id":"3defc1710d3da8d8","repo":"sgl-project/sglang","slug":"dsv4-draft-state-transfer-expects-swa-only-nextn-l","errorCode":null,"errorMessage":"DSV4 draft state transfer expects SWA-only NextN layers","messagePattern":"DSV4 draft state transfer expects SWA-only NextN layers","errorType":"validation","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/disaggregation/utils.py","lineNumber":1147,"sourceCode":"            append_state_component(\n                kv_args,\n                AscendStateType.DSV4_C128,\n                c128_ptrs,\n                c128_lens,\n                c128_item_lens,\n            )\n\n    # DSV4 NextN shares the target allocator, so target and draft use the same\n    # local SWA indices. Keep draft buffers in a separate positional component\n    # to avoid mixing them into the target's heterogeneous state layout, while\n    # reusing the existing SWA transport dispatch on both GPU and NPU.\n    if isinstance(token_to_kv_pool, DeepSeekV4TokenToKVPool) and isinstance(\n        draft_token_to_kv_pool, DeepSeekV4TokenToKVPool\n    ):\n        if not draft_token_to_kv_pool.compression_ratios or not all(\n            ratio == 0 for ratio in draft_token_to_kv_pool.compression_ratios\n        ):\n            raise RuntimeError(\n                \"DSV4 draft state transfer expects SWA-only NextN layers\"\n            )\n        if token_to_kv_pool._unified_kv != draft_token_to_kv_pool._unified_kv:\n            raise RuntimeError(\n                \"DSV4 target and draft pools must use the same unified-KV mode\"\n            )\n\n        if token_to_kv_pool._unified_kv:\n            target_geometry = (\n                token_to_kv_pool.unified_swa_window,\n                token_to_kv_pool.unified_swa_ring_size,\n                token_to_kv_pool.unified_swa_pages,\n            )\n            draft_geometry = (\n                draft_token_to_kv_pool.unified_swa_window,\n                draft_token_to_kv_pool.unified_swa_ring_size,\n                draft_token_to_kv_pool.unified_swa_pages,\n            )","sourceCodeStart":1129,"sourceCodeEnd":1165,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/disaggregation/utils.py#L1129-L1165","documentation":"For DeepSeek-V4 target+draft pool pairs, draft (NextN speculative) state transfer requires every draft layer to be SWA-only, expressed as compression_ratios all equal to 0. Any nonzero compression ratio in the draft pool means the draft model has compressed layers whose state cannot be transferred via the SWA path, so setup_state_kv_args raises RuntimeError.","triggerScenarios":"Running DSV4 with speculative decoding (NextN draft pool is a DeepSeekV4TokenToKVPool) where draft_token_to_kv_pool.compression_ratios contains a nonzero ratio, under PD disaggregation.","commonSituations":"Enabling MTP/speculative decoding with a draft config that includes compressed layers; mixing a compressed-layer draft with disaggregation; new draft configs after a model/config update.","solutions":["Use an SWA-only NextN draft model (all compression_ratios == 0)","Disable speculative decoding for this deployment","Disable PD disaggregation and serve single-node"],"exampleFix":"# before\n--speculative-algorithm NEXTN --disaggregation-prefill  # draft has compressed layers\n# after\n--speculative-algorithm NEXTN --disaggregation-prefill  # with SWA-only draft (ratios all 0)","handlingStrategy":"type-guard","validationCode":"if draft_pool.compression_ratios and any(r != 0 for r in draft_pool.compression_ratios):\n    raise SystemExit(\"Draft pool must be SWA-only (compression_ratios all 0) for DSV4 state transfer\")","typeGuard":"def dsv4_draft_transfer_ok(draft_pool) -> bool:\n    return all(r == 0 for r in draft_pool.compression_ratios)","tryCatchPattern":null,"preventionTips":["Validate draft pool compression_ratios before enabling spec decoding with disaggregation","Use SWA-only NextN checkpoints"],"tags":["disaggregation","deepseek-v4","speculative-decoding","swa"],"backgroundTag":"incompatible-model-configuration","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}