Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
ea41a99
[NPU] Support Kimi-K3 decode context parallelism
qybnb Sep 3, 2026
16f8c1c
[NPU] Add a group-local HCCL buffer for DCP
qybnb Sep 14, 2026
49d0647
fix(ci): address NPU DCP lint failures
qybnb Sep 17, 2026
0fcf4d7
refactor(npu): isolate Kimi-K3 DCP metadata
qybnb Sep 17, 2026
4cc040a
refactor(npu): use standard HCCL buffer for DCP
qybnb Sep 22, 2026
5051451
perf(npu): compact Kimi-K3 DCP state exchange
qybnb Sep 22, 2026
72de60d
refactor(npu): reuse shared DCP metadata and graph buffers
qybnb Sep 23, 2026
6c8b249
docs: keep local DCP notes out of the PR
invalid-email-address Sep 23, 2026
0003011
fix(npu): restore slice-based DCP prefix metadata
qybnb Sep 23, 2026
8e8d8a5
refactor(npu): remove redundant DCP pool sharding flag
qybnb Sep 23, 2026
57f995f
refactor(npu): preserve original MLA KV split ordering
qybnb Sep 23, 2026
8a43e00
refactor(npu): preserve MLA KV read index dtype
qybnb Sep 23, 2026
7ab7d9c
refactor(npu): use scalar dummy for DCP write remapping
qybnb Sep 23, 2026
724c787
refactor(npu): reuse shared Triton DCP KV writer
qybnb Sep 23, 2026
58060ec
refactor(npu): simplify DCP FIA metadata and graph padding
qybnb Sep 29, 2026
ac5ebfe
merge: integrate main into Kimi-K3 NPU DCP
qybnb Sep 29, 2026
2d965e1
test(npu): align DCP kernel test with CI taxonomy
qybnb Sep 29, 2026
70fc82f
refactor(npu): keep MLA KV reads in native cache dtype
qybnb Sep 30, 2026
02068ed
fix(dcp): tolerate full-attn backends without dcp_use_packed_kv
qybnb Sep 30, 2026
7b2b108
merge: integrate latest main with Kimi-K3 NPU DCP
qybnb Oct 6, 2026
b49fc9c
refactor(npu): isolate dense MLA DCP metadata from DSA
qybnb Oct 6, 2026
cbb7cfb
fix(npu): allow K3 DCP startup and exclude CUDA output gate JIT
qybnb Oct 6, 2026
0224a7b
chore: remove NPU DCP regression test changes from PR
qybnb Oct 6, 2026
ee4d5bf
refactor(npu): keep upstream DSA metadata logic inline
qybnb Oct 6, 2026
840a35f
refactor(npu): simplify dense MLA DCP predicates
qybnb Oct 6, 2026
cbc00ae
Merge branch 'main' into feature/kimi-k3-npu-dcp-reuse
qybnb Oct 6, 2026
1670159
test(npu): cover page and token DCP retraction layouts
qybnb Oct 8, 2026
3e6b38e
refactor(npu): clarify DCP routing and explicit MLA cache writes
qybnb Oct 8, 2026
73031a7
refactor(npu): restore existing MLA cache-write ownership
qybnb Oct 8, 2026
9531c10
Merge branch 'main' into feature/kimi-k3-npu-dcp-reuse
qybnb Oct 8, 2026
677eabe
test(npu): sync graph runner mocks with current runtime APIs
qybnb Oct 8, 2026
45e5b7e
Merge main and reconcile NPU graph test mocks
qybnb Oct 8, 2026
6f40e5f
Merge main and preserve NPU DCP write-index ownership
qybnb Oct 8, 2026
096434d
refactor(dcp): restore upstream LSE merge behavior
qybnb Oct 8, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion python/sglang/kernels/ops/attention/mla_output_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
load_jit,
make_cpp_args,
)
from sglang.srt.utils import is_npu

if TYPE_CHECKING:
from tvm_ffi.module import Module

_THREADS: int = 256
_is_npu = is_npu()


@cache_once
Expand All @@ -32,8 +34,10 @@ def _jit_mla_output_gate_module() -> Module:


def covered(x: torch.Tensor, gate: torch.Tensor) -> bool:
# transfer_to_npu aliases Tensor.is_cuda to Tensor.is_npu; this JIT is CUDA-only.
return (
x.is_cuda
not _is_npu

@qybnb qybnb Oct 6, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

防止 NPU 误调用 CUDA 专用的 MLA output gate 融合算子。

原来通过以下条件判断能否使用 CUDA 算子:

x.is_cuda and gate.is_cuda

但当前 NPU 环境加载的 transfer_to_npu 兼容层会把 Tensor.is_cuda 映射成 Tensor.is_npu。所以 NPU 张量也可能通过这个判断,然后尝试调用 nvcc 编译 CUDA,导致启动报错。
参考pr36406

and x.is_cuda
and gate.is_cuda
and x.dtype == torch.bfloat16
and gate.dtype == torch.bfloat16
Expand Down
11 changes: 8 additions & 3 deletions python/sglang/srt/arg_groups/model_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ def handle_model_specific_adjustments(server_args: Any):
NONCAUSAL_FULL_ATTENTION,
get_mimo_v2_fused_qkv_expected_tp_size,
is_deepseek_dsa,
is_kimi_k3,
)

if cfg.enable_deterministic_inference:
Expand All @@ -169,11 +170,15 @@ def handle_model_specific_adjustments(server_args: Any):
hf_config = model_config.hf_config
model_arch = hf_config.architectures[0]

if get_platform().is_npu and cfg.dcp_size > 1 and not is_deepseek_dsa(hf_config):
if (
get_platform().is_npu
and cfg.dcp_size > 1
and not (is_deepseek_dsa(hf_config) or is_kimi_k3(hf_config))
):
raise ValueError(
"NPU decode context parallelism is currently implemented only for "
"DeepSeek DSA models; got "
f"{model_arch}. Set --decode-context-parallel-size=1 or use a DSA model."
"DeepSeek DSA and Kimi-K3 models; got "
f"{model_arch}. Set --decode-context-parallel-size=1 or use a supported model."
)

if model_arch == "InternS2MobiusForConditionalGeneration":
Expand Down
43 changes: 42 additions & 1 deletion python/sglang/srt/arg_groups/model_overrides/kimi_k3.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,52 @@ def _require_kimi_k3_aiter_gluon_dcp_support() -> None:
)


@_register_for("KimiK3ForConditionalGeneration")
@_register_for("KimiK3ForConditionalGeneration", "KimiK3LinearForCausalLM")
def _kimi_k3_overrides(server_args: Any, hf_config: Any) -> dict:
cfg = resolving_view(server_args)
if cfg.dcp_size > 1:
overrides = {}
if get_platform().is_npu:
if cfg.speculative_algorithm not in (None, "DSPARK"):
raise ValueError(
"Kimi-K3 NPU DCP currently supports speculative decoding "
"only with DSPARK."
)
if cfg.speculative_algorithm == "DSPARK":
from sglang.srt.speculative.ragged_verify import (
RaggedVerifyMode,
read_ragged_verify_mode,
)

ragged_mode = read_ragged_verify_mode()
if ragged_mode is not RaggedVerifyMode.STATIC:
raise ValueError(
"Kimi-K3 NPU DCP + DSPARK currently requires "
"SGLANG_RAGGED_VERIFY_MODE=static; compact/cap-accept "
f"are not validated under DCP (got {ragged_mode.value!r})."
)
overrides["speculative_attention_mode"] = "decode"
if cfg.dcp_replicate_q_proj:
raise ValueError(
"Kimi-K3 NPU DCP does not support --dcp-replicate-q-proj "
"yet; the Ascend path uses an HCCL Q AllGather."
)
if cfg.enable_symm_mem:
logger.warning(
"Kimi-K3 NPU DCP disables --enable-symm-mem; the initial "
"Ascend path uses ordinary HCCL collectives."
)
overrides["enable_symm_mem"] = False
logger.info(
"Kimi-K3 NPU DCP selects the HCCL A2A communication path and "
"disables replicated Q projection."
)
overrides.update(
dcp_comm_backend="a2a",
dcp_replicate_q_proj=False,
)
return overrides

if cfg.enable_symm_mem:
logger.warning(
"Kimi-K3 DCP disables --enable-symm-mem due to decode CUDA "
Expand Down
Loading
Loading