[GH-ISSUE #1866] Gibberish output when using GPU offload prefill with RAWINT4 Kimi K2.5 #1163

Closed
opened 2026-10-29 14:49:25 +00:00 by bsakaguchi · 25 comments
Owner

Originally created by @DocShotgun on GitHub (Feb 24, 2026).
Original GitHub issue: https://github.com/kvcache-ai/ktransformers/issues/1866

Originally assigned to: @ouqingliang on GitHub.

Reminder

  • I have read the above rules and searched the existing issues.

System Info

2x 5th-gen Xeon Platinum 64c 128t with 768gb
1x RTX Pro 6000 Workstation Edition 96gb

Reproduction

I've followed the instructions in the guide for setting up Kimi-K2.5 native QAT weights using your fork of sglang (github.com/kvcache-ai/sglang@a864420ee4) with ktransformers github.com/kvcache-ai/ktransformers@16a8b98f3e.

Launch command:

PYTORCH_ALLOC_CONF=expandable_segments:True \
SGLANG_ENABLE_JIT_DEEPGEMM=0 \
python -m sglang.launch_server \
  --host 0.0.0.0 \
  --port 5000 \
  --model /mnt/data2/models/Kimi-K2.5 \
  --kt-weight-path /mnt/data2/models/Kimi-K2.5 \
  --kt-cpuinfer 128 \
  --kt-threadpool-count 4 \
  --kt-num-gpu-experts 0 \
  --kt-method RAWINT4 \
  --kt-gpu-prefill-token-threshold 512 \
  --trust-remote-code \
  --mem-fraction-static 0.98 \
  --served-model-name moonshotai/Kimi-K2.5 \
  --enable-mixed-chunk \
  --tensor-parallel-size 1 \
  --enable-p2p-check \
  --disable-shared-experts-fusion \
  --chunked-prefill-size 4096 \
  --context-length 32768 \
  --max-total-tokens 32768 \
  --max-running-requests 1 \
  --attention-backend flashinfer

I noticed that on generation, I was getting nonsense/garbage outputs, however if I sent a short enough prompt, the outputs were coherent. My guess was that the problem was related to the GPU offload prefill for large prompts. I re-launched the server, changing --kt-gpu-prefill-token-threshold to 999999 so that it would never trigger, and it was able to produce coherent output (although the prompt processing is very slow without full GPU offload and without AMX kernels).

Others

No response

Originally created by @DocShotgun on GitHub (Feb 24, 2026). Original GitHub issue: https://github.com/kvcache-ai/ktransformers/issues/1866 Originally assigned to: @ouqingliang on GitHub. ### Reminder - [x] I have read the above rules and searched the existing issues. ### System Info 2x 5th-gen Xeon Platinum 64c 128t with 768gb 1x RTX Pro 6000 Workstation Edition 96gb ### Reproduction I've followed the instructions in the guide for setting up Kimi-K2.5 native QAT weights using your fork of sglang (https://github.com/kvcache-ai/sglang/commit/a864420ee4d0daba15644f3f2d4a50dadcd892a6) with ktransformers https://github.com/kvcache-ai/ktransformers/commit/16a8b98f3e80538a01c027bde2bacf851ac49d42. Launch command: ```text PYTORCH_ALLOC_CONF=expandable_segments:True \ SGLANG_ENABLE_JIT_DEEPGEMM=0 \ python -m sglang.launch_server \ --host 0.0.0.0 \ --port 5000 \ --model /mnt/data2/models/Kimi-K2.5 \ --kt-weight-path /mnt/data2/models/Kimi-K2.5 \ --kt-cpuinfer 128 \ --kt-threadpool-count 4 \ --kt-num-gpu-experts 0 \ --kt-method RAWINT4 \ --kt-gpu-prefill-token-threshold 512 \ --trust-remote-code \ --mem-fraction-static 0.98 \ --served-model-name moonshotai/Kimi-K2.5 \ --enable-mixed-chunk \ --tensor-parallel-size 1 \ --enable-p2p-check \ --disable-shared-experts-fusion \ --chunked-prefill-size 4096 \ --context-length 32768 \ --max-total-tokens 32768 \ --max-running-requests 1 \ --attention-backend flashinfer ``` I noticed that on generation, I was getting nonsense/garbage outputs, however if I sent a short enough prompt, the outputs were coherent. My guess was that the problem was related to the GPU offload prefill for large prompts. I re-launched the server, changing `--kt-gpu-prefill-token-threshold` to 999999 so that it would never trigger, and it was able to produce coherent output (although the prompt processing is very slow without full GPU offload and without AMX kernels). ### Others _No response_
Author
Owner

@shrould8888 commented on GitHub (Feb 26, 2026):

I have similar config(Xeon5 64 cores x1 + 768GB RAM + RTX PRO 6000 96GB) and use 10 feb 2026 github source code (ktransformation+sglang):
python -m sglang.launch_server
--host 0.0.0.0
--port 10005
--model /Kimi-K2.5
--kt-weight-path /Kimi-K2.5
--kt-cpuinfer 60
--kt-threadpool-count 1
--kt-num-gpu-experts 0
--kt-method RAWINT4 -chunked-prefill-size
--trust-remote-code
--mem-fraction-static 0.94
--served-model-name Kimi-K2.5
--enable-mixed-chunk
--tensor-parallel-size 1
--enable-p2p-check
--disable-shared-experts-fusion
--chunked-prefill-size 32768
--max-total-tokens 256000
--attention-backend flashinfer
--sleep-on-idle
--reasoning-parser kimi_k2
--tool-call-parser kimi_k2 --kt-gpu-prefill-token-threshold 500 --kt-enable-dynamic-expert-update

But I don't have any problem with running k2.5. The main difference is I don't use "PYTORCH_ALLOC_CONF=expandable_segments:True SGLANG_ENABLE_JIT_DEEPGEMM=0" and my --chunked-prefill-size is 32768 (in other model, changing this number may generate garbage output. (e.g. when using Deepseek V3.2 AMX weights, if I set it to 32768 something like that , the model will produce garbage output, have to set it to 4096) . you could use "kt" command to run the model, it should generate workable arguments/options.

<!-- gh-comment-id:3964498459 --> @shrould8888 commented on GitHub (Feb 26, 2026): I have similar config(Xeon5 64 cores x1 + 768GB RAM + RTX PRO 6000 96GB) and use 10 feb 2026 github source code (ktransformation+sglang): python -m sglang.launch_server \ --host 0.0.0.0 \ --port 10005 \ --model /Kimi-K2.5 \ --kt-weight-path /Kimi-K2.5 \ --kt-cpuinfer 60 \ --kt-threadpool-count 1 \ --kt-num-gpu-experts 0 \ --kt-method RAWINT4 \-chunked-prefill-size --trust-remote-code \ --mem-fraction-static 0.94 \ --served-model-name Kimi-K2.5 \ --enable-mixed-chunk \ --tensor-parallel-size 1 \ --enable-p2p-check \ --disable-shared-experts-fusion \ **--chunked-prefill-size 32768** \ --max-total-tokens 256000 \ --attention-backend flashinfer \ --sleep-on-idle \ --reasoning-parser kimi_k2 \ --tool-call-parser kimi_k2 --kt-gpu-prefill-token-threshold 500 --kt-enable-dynamic-expert-update But I don't have any problem with running k2.5. The main difference is I don't use "PYTORCH_ALLOC_CONF=expandable_segments:True SGLANG_ENABLE_JIT_DEEPGEMM=0" and my -**-chunked-prefill-size** is 32768 (in other model, changing this number may generate garbage output. (e.g. when using Deepseek V3.2 AMX weights, if I set it to 32768 something like that , the model will produce garbage output, have to set it to 4096) . you could use "kt" command to run the model, it should generate workable arguments/options.
Author
Owner

@DocShotgun commented on GitHub (Feb 26, 2026):

But I don't have any problem with running k2.5. The main difference is I don't use "PYTORCH_ALLOC_CONF=expandable_segments:True SGLANG_ENABLE_JIT_DEEPGEMM=0" and my --chunked-prefill-size is 32768 (in other model, changing this number may generate garbage output. (e.g. when using Deepseek V3.2 AMX weights, if I set it to 32768 something like that , the model will produce garbage output, have to set it to 4096) . you could use "kt" command to run the model, it should generate workable arguments/options.

I tried removing thos env vars and also adjusting the chunked prefill size to match yours, but it still produces gibberish with GPU offload prefill.

I noticed another difference is that I'm using 4 CPU threadpools (two sockets with 2 NUMA nodes per socket) while you're only using 1, while we both only have 1 GPU. So when I'm doing GPU offload prefill, the CPU weights that were previously split for TP=4 have to be re-combined to run on the single GPU. If done incorrectly, this could definitely cause gibberish. Perhaps this could be the source of error?

<!-- gh-comment-id:3964979803 --> @DocShotgun commented on GitHub (Feb 26, 2026): > But I don't have any problem with running k2.5. The main difference is I don't use "PYTORCH_ALLOC_CONF=expandable_segments:True SGLANG_ENABLE_JIT_DEEPGEMM=0" and my -**-chunked-prefill-size** is 32768 (in other model, changing this number may generate garbage output. (e.g. when using Deepseek V3.2 AMX weights, if I set it to 32768 something like that , the model will produce garbage output, have to set it to 4096) . you could use "kt" command to run the model, it should generate workable arguments/options. I tried removing thos env vars and also adjusting the chunked prefill size to match yours, but it still produces gibberish with GPU offload prefill. I noticed another difference is that I'm using 4 CPU threadpools (two sockets with 2 NUMA nodes per socket) while you're only using 1, while we both only have 1 GPU. So when I'm doing GPU offload prefill, the CPU weights that were previously split for TP=4 have to be re-combined to run on the single GPU. If done incorrectly, this could definitely cause gibberish. Perhaps this could be the source of error?
Author
Owner

@trilog-inc commented on GitHub (Feb 26, 2026):

I am also interested in this issue. The original version of kt-kernel which supported K2.5 did not have this problem, however pulling and installing the latest does.

<!-- gh-comment-id:3969088945 --> @trilog-inc commented on GitHub (Feb 26, 2026): I am also interested in this issue. The original version of kt-kernel which supported K2.5 did not have this problem, however pulling and installing the latest does.
Author
Owner

@DocShotgun commented on GitHub (Feb 26, 2026):

I am also interested in this issue. The original version of kt-kernel which supported K2.5 did not have this problem, however pulling and installing the latest does.

Do you happen to know what the last working commit was on your end?

<!-- gh-comment-id:3969237654 --> @DocShotgun commented on GitHub (Feb 26, 2026): > I am also interested in this issue. The original version of kt-kernel which supported K2.5 did not have this problem, however pulling and installing the latest does. Do you happen to know what the last working commit was on your end?
Author
Owner

@trilog-inc commented on GitHub (Feb 26, 2026):

On ktransformers:
Branch: origin/kimi_k2.5
Commit: b941447a83

On SGlang
Branch: origin/kimi_k2.5 ( manually updated xgrammar==0.1.29 )
Commit: 317ee674ee78b6c684ba342d054d65c7438d021b

Command:

CUDA_DEVICE_ORDER="PCI_BUS_ID" CUDA_VISIBLE_DEVICES=0 CUDA_LAUNCH_BLOCKING=1
python -m sglang.launch_server --host 0.0.0.0 --port 60000
--model /mnt/home_extend/models/kimi25/
--kt-weight-path /mnt/home_extend/models/kimi25/
--kt-cpuinfer 52 --kt-threadpool-count 2 --kt-num-gpu-experts 26
--kt-method RAWINT4 --attention-backend flashinfer --kt-gpu-prefill-token-threshold 400
--kt-max-deferred-experts-per-token 1 --trust-remote-code
--mem-fraction-static 0.94 --chunked-prefill-size 16384 --max-running-requests 4
--max-total-tokens 120000 --enable-mixed-chunk --tensor-parallel-size 1 --enable-p2p-check --disable-shared-experts-fusion --served-model-name kimi
--tool-call-parser kimi_k2 --reasoning-parser kimi_k2

<!-- gh-comment-id:3969272902 --> @trilog-inc commented on GitHub (Feb 26, 2026): On ktransformers: Branch: origin/kimi_k2.5 Commit: b941447a831c4b59911043b560f6267365030bc9 On SGlang Branch: origin/kimi_k2.5 ( manually updated xgrammar==0.1.29 ) Commit: 317ee674ee78b6c684ba342d054d65c7438d021b Command: CUDA_DEVICE_ORDER="PCI_BUS_ID" CUDA_VISIBLE_DEVICES=0 CUDA_LAUNCH_BLOCKING=1 python -m sglang.launch_server --host 0.0.0.0 --port 60000 --model /mnt/home_extend/models/kimi25/ --kt-weight-path /mnt/home_extend/models/kimi25/ --kt-cpuinfer 52 --kt-threadpool-count 2 --kt-num-gpu-experts 26 --kt-method RAWINT4 --attention-backend flashinfer --kt-gpu-prefill-token-threshold 400 --kt-max-deferred-experts-per-token 1 --trust-remote-code --mem-fraction-static 0.94 --chunked-prefill-size 16384 --max-running-requests 4 --max-total-tokens 120000 --enable-mixed-chunk --tensor-parallel-size 1 --enable-p2p-check --disable-shared-experts-fusion --served-model-name kimi --tool-call-parser kimi_k2 --reasoning-parser kimi_k2
Author
Owner

@DocShotgun commented on GitHub (Feb 26, 2026):

Might be worth doing a git bisect, although it wouldn't exactly be quick to iterate lol.

<!-- gh-comment-id:3969292754 --> @DocShotgun commented on GitHub (Feb 26, 2026): Might be worth doing a `git bisect`, although it wouldn't exactly be quick to iterate lol.
Author
Owner

@trilog-inc commented on GitHub (Feb 26, 2026):

Won't be easy :s Although I love K2.5 and its multi modal capabilities, I have moved on to GLM5 as the function parsers are more mature. Even with those working branches, K2.5 would fail in inconsistent ways especially above 80K context. Although half the speed, GLM5 has been very solid

<!-- gh-comment-id:3969383223 --> @trilog-inc commented on GitHub (Feb 26, 2026): Won't be easy :s Although I love K2.5 and its multi modal capabilities, I have moved on to GLM5 as the function parsers are more mature. Even with those working branches, K2.5 would fail in inconsistent ways especially above 80K context. Although half the speed, GLM5 has been very solid
Author
Owner

@ErvinXie commented on GitHub (Feb 28, 2026):

Thanks for the detailed report. We previously fixed a related bug in the GPU offload prefill path. Could you try using the latest main branch for both KTransformers and SGLang and see if the issue is resolved?

As a temporary workaround, setting --kt-gpu-prefill-token-threshold to a very large value (effectively disabling GPU prefill) should produce correct outputs, as you have already confirmed.

Please let us know if the issue persists after updating.


This reply was generated by an AI agent and reviewed by a human.

<!-- gh-comment-id:3976659212 --> @ErvinXie commented on GitHub (Feb 28, 2026): Thanks for the detailed report. We previously fixed a related bug in the GPU offload prefill path. Could you try using the latest `main` branch for both KTransformers and SGLang and see if the issue is resolved? As a temporary workaround, setting `--kt-gpu-prefill-token-threshold` to a very large value (effectively disabling GPU prefill) should produce correct outputs, as you have already confirmed. Please let us know if the issue persists after updating. --- *This reply was generated by an AI agent and reviewed by a human.*
Author
Owner

@DocShotgun commented on GitHub (Feb 28, 2026):

Please let us know if the issue persists after updating.

Thanks for the update! I just tried the current latest commits of github.com/kvcache-ai/ktransformers@9e69fccb02 github.com/kvcache-ai/sglang@a8b821aee8 and unfortunately I'm not able to get far enough to test this functionality due to a new error.

During CUDA graph capture, JIT compilation of the fused marlin kernel fails due to an unexpected indent:

Traceback (most recent call last):
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/managers/scheduler.py", line 3118, in run_scheduler_process
    scheduler = Scheduler(
                ^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/managers/scheduler.py", line 363, in __init__
    self.init_model_worker()
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/managers/scheduler.py", line 559, in init_model_worker
    self.init_tp_model_worker()
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/managers/scheduler.py", line 517, in init_tp_model_worker
    self.tp_worker = TpModelWorker(
                     ^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/managers/tp_worker.py", line 247, in __init__
    self._init_model_runner()
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/managers/tp_worker.py", line 330, in _init_model_runner
    self._model_runner = ModelRunner(
                         ^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/model_executor/model_runner.py", line 415, in __init__
    self.initialize(min_per_gpu_memory)
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/model_executor/model_runner.py", line 611, in initialize
    self.init_device_graphs()
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/model_executor/model_runner.py", line 2149, in init_device_graphs
    self.graph_runner = graph_runners[self.device](self)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/model_executor/cuda_graph_runner.py", line 567, in __init__
    self.capture()
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/model_executor/cuda_graph_runner.py", line 723, in capture
    _capture_one_stream()
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/model_executor/cuda_graph_runner.py", line 710, in _capture_one_stream
    ) = self.capture_one_batch_size(bs, forward, stream_idx)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/model_executor/cuda_graph_runner.py", line 929, in capture_one_batch_size
    run_once()
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/model_executor/cuda_graph_runner.py", line 916, in run_once
    logits_output_or_pp_proxy_tensors = forward(
                                        ^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/models/kimi_k25.py", line 727, in forward
    hidden_states = general_mm_embed_routine(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/managers/mm_utils.py", line 1134, in general_mm_embed_routine
    hidden_states = language_model(
                    ^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1775, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1786, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/utils/_contextlib.py", line 120, in decorate_context
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/models/deepseek_v2.py", line 2998, in forward
    hidden_states = self.model(
                    ^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1775, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1786, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/models/deepseek_v2.py", line 2749, in forward
    hidden_states, residual = layer(
                              ^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1775, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1786, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/models/deepseek_v2.py", line 577, in forward
    return self.forward_normal_dual_stream(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/models/deepseek_v2.py", line 611, in forward_normal_dual_stream
    final_hidden_states = self.experts(hidden_states, topk_output)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1775, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1786, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/layers/moe/fused_moe_triton/layer.py", line 983, in forward
    return self.forward_impl(hidden_states, topk_output)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/layers/moe/fused_moe_triton/layer.py", line 1002, in forward_impl
    combine_input = self.run_moe_core(
                    ^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/layers/moe/fused_moe_triton/layer.py", line 1023, in run_moe_core
    return self.quant_method.apply(
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/layers/moe/kt_ep_wrapper.py", line 2340, in apply
    gpu_combine_input = self.gpu_method.apply(layer, masked_dispatch_output)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/layers/quantization/compressed_tensors/compressed_tensors.py", line 1014, in apply
    return scheme.apply_weights(layer, dispatch_output)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/layers/quantization/compressed_tensors/schemes/compressed_tensors_wNa16_moe.py", line 363, in apply_weights
    from sglang.srt.layers.moe.fused_moe_triton.fused_marlin_moe import (
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/layers/moe/fused_moe_triton/fused_marlin_moe.py", line 16
    from sglang.jit_kernel.moe_wna16_marlin import moe_wna16_marlin_gemm
IndentationError: unexpected indent
<!-- gh-comment-id:3977467169 --> @DocShotgun commented on GitHub (Feb 28, 2026): > Please let us know if the issue persists after updating. Thanks for the update! I just tried the current latest commits of https://github.com/kvcache-ai/ktransformers/commit/9e69fccb026b1359bb850b8b7bef09be23b6cbb7 https://github.com/kvcache-ai/sglang/commit/a8b821aee86922fafcf175a4915a1d97e1cd1169 and unfortunately I'm not able to get far enough to test this functionality due to a new error. During CUDA graph capture, JIT compilation of the fused marlin kernel fails due to an unexpected indent: ``` Traceback (most recent call last): File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/managers/scheduler.py", line 3118, in run_scheduler_process scheduler = Scheduler( ^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/managers/scheduler.py", line 363, in __init__ self.init_model_worker() File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/managers/scheduler.py", line 559, in init_model_worker self.init_tp_model_worker() File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/managers/scheduler.py", line 517, in init_tp_model_worker self.tp_worker = TpModelWorker( ^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/managers/tp_worker.py", line 247, in __init__ self._init_model_runner() File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/managers/tp_worker.py", line 330, in _init_model_runner self._model_runner = ModelRunner( ^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/model_executor/model_runner.py", line 415, in __init__ self.initialize(min_per_gpu_memory) File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/model_executor/model_runner.py", line 611, in initialize self.init_device_graphs() File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/model_executor/model_runner.py", line 2149, in init_device_graphs self.graph_runner = graph_runners[self.device](self) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/model_executor/cuda_graph_runner.py", line 567, in __init__ self.capture() File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/model_executor/cuda_graph_runner.py", line 723, in capture _capture_one_stream() File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/model_executor/cuda_graph_runner.py", line 710, in _capture_one_stream ) = self.capture_one_batch_size(bs, forward, stream_idx) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/model_executor/cuda_graph_runner.py", line 929, in capture_one_batch_size run_once() File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/model_executor/cuda_graph_runner.py", line 916, in run_once logits_output_or_pp_proxy_tensors = forward( ^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/models/kimi_k25.py", line 727, in forward hidden_states = general_mm_embed_routine( ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/managers/mm_utils.py", line 1134, in general_mm_embed_routine hidden_states = language_model( ^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1775, in _wrapped_call_impl return self._call_impl(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1786, in _call_impl return forward_call(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/utils/_contextlib.py", line 120, in decorate_context return func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/models/deepseek_v2.py", line 2998, in forward hidden_states = self.model( ^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1775, in _wrapped_call_impl return self._call_impl(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1786, in _call_impl return forward_call(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/models/deepseek_v2.py", line 2749, in forward hidden_states, residual = layer( ^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1775, in _wrapped_call_impl return self._call_impl(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1786, in _call_impl return forward_call(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/models/deepseek_v2.py", line 577, in forward return self.forward_normal_dual_stream( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/models/deepseek_v2.py", line 611, in forward_normal_dual_stream final_hidden_states = self.experts(hidden_states, topk_output) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1775, in _wrapped_call_impl return self._call_impl(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1786, in _call_impl return forward_call(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/layers/moe/fused_moe_triton/layer.py", line 983, in forward return self.forward_impl(hidden_states, topk_output) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/layers/moe/fused_moe_triton/layer.py", line 1002, in forward_impl combine_input = self.run_moe_core( ^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/layers/moe/fused_moe_triton/layer.py", line 1023, in run_moe_core return self.quant_method.apply( ^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/layers/moe/kt_ep_wrapper.py", line 2340, in apply gpu_combine_input = self.gpu_method.apply(layer, masked_dispatch_output) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/layers/quantization/compressed_tensors/compressed_tensors.py", line 1014, in apply return scheme.apply_weights(layer, dispatch_output) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/layers/quantization/compressed_tensors/schemes/compressed_tensors_wNa16_moe.py", line 363, in apply_weights from sglang.srt.layers.moe.fused_moe_triton.fused_marlin_moe import ( File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/layers/moe/fused_moe_triton/fused_marlin_moe.py", line 16 from sglang.jit_kernel.moe_wna16_marlin import moe_wna16_marlin_gemm IndentationError: unexpected indent ```
Author
Owner

@ErvinXie commented on GitHub (Mar 1, 2026):

Thanks for the detailed follow-up and the traceback, @DocShotgun.

We've identified the root cause. The recent merge from upstream SGLang into our fork introduced two issues:

  1. fused_marlin_moe.py IndentationError — A merge conflict was not properly resolved, leaving an orphaned indented import on line 16. This is the error you encountered.

  2. RAWINT4 quantization path change — The upstream merge replaced the MoE quantization scheme (compressed_tensors_wNa16 → compressed_tensors_wNa16_moe), which now uses a JIT-compiled marlin MoE kernel (moe_wna16_marlin_gemm). This new kernel path has compatibility issues with CUDA graph capture on Blackwell (SM120) GPUs, causing the cudaErrorIllegalAddress after the IndentationError is fixed.

This is consistent with @trilog-inc's finding that the kimi_k2.5 branch (commit 317ee674ee) still works — that branch predates the upstream merge and uses the original marlin MoE path.

We are working on a fix. In the meantime, please use the kimi_k2.5 branch for both KTransformers and SGLang to run Kimi K2.5:

# SGLang
cd sglang && git checkout kimi_k2.5

# KTransformers
cd ktransformers && git checkout kimi_k2.5

We'll update this issue once the fix is merged to main.


This reply was co-authored by an AI agent and a human.

<!-- gh-comment-id:3979988343 --> @ErvinXie commented on GitHub (Mar 1, 2026): Thanks for the detailed follow-up and the traceback, @DocShotgun. We've identified the root cause. The recent merge from upstream SGLang into our fork introduced two issues: 1. **`fused_marlin_moe.py` IndentationError** — A merge conflict was not properly resolved, leaving an orphaned indented import on line 16. This is the error you encountered. 2. **RAWINT4 quantization path change** — The upstream merge replaced the MoE quantization scheme (`compressed_tensors_wNa16` → `compressed_tensors_wNa16_moe`), which now uses a JIT-compiled marlin MoE kernel (`moe_wna16_marlin_gemm`). This new kernel path has compatibility issues with CUDA graph capture on Blackwell (SM120) GPUs, causing the `cudaErrorIllegalAddress` after the IndentationError is fixed. This is consistent with @trilog-inc's finding that the `kimi_k2.5` branch (commit `317ee674ee`) still works — that branch predates the upstream merge and uses the original marlin MoE path. **We are working on a fix.** In the meantime, please use the `kimi_k2.5` branch for both KTransformers and SGLang to run Kimi K2.5: ``` # SGLang cd sglang && git checkout kimi_k2.5 # KTransformers cd ktransformers && git checkout kimi_k2.5 ``` We'll update this issue once the fix is merged to main. --- *This reply was co-authored by an AI agent and a human.*
Author
Owner

@ErvinXie commented on GitHub (Mar 1, 2026):

The fix has been pushed to kvcache-ai/sglang main branch: 8d06c33.

Root cause

Three bugs introduced by the upstream SGLang merge (a2f451315):

  1. fused_marlin_moe.py IndentationError — merge conflict left imports outside the if _is_cuda: block, causing IndentationError on import.

  2. fused_marlin_moe.py crash on empty expert weights — when --kt-num-gpu-experts 0, GPU expert weight tensors have shape [0, ...]. The marlin MoE kernel crashes on these empty inputs. Fixed by returning zeros early when E=0 so CPU experts provide the full result.

  3. deepseek_v2.py dual-stream conflict with KT wrapper — forward_normal_dual_stream uses alt_stream for shared expert parallelism, which conflicts with KT wrapper's internal _cpu_stream during CUDA graph capture. Fixed by skipping dual-stream path when using KT wrapper.

How to update

cd sglang
git pull origin main

Verified on

  • RTX 5090 (SM120 Blackwell), single GPU
  • --kt-num-gpu-experts 0 --kt-method RAWINT4 --attention-backend triton
  • CUDA graph capture: OK
  • Decode with CUDA graph: OK, correct output
  • What is 2+3? → 5 (correct reasoning + answer)

Please update both SGLang and KTransformers to the latest main branch and let us know if the issue persists.


This reply was co-authored by an AI agent and a human.

<!-- gh-comment-id:3980241206 --> @ErvinXie commented on GitHub (Mar 1, 2026): The fix has been pushed to kvcache-ai/sglang main branch: [`8d06c33`](https://github.com/kvcache-ai/sglang/commit/8d06c33). ### Root cause Three bugs introduced by the upstream SGLang merge (`a2f451315`): 1. **`fused_marlin_moe.py` IndentationError** — merge conflict left imports outside the `if _is_cuda:` block, causing `IndentationError` on import. 2. **`fused_marlin_moe.py` crash on empty expert weights** — when `--kt-num-gpu-experts 0`, GPU expert weight tensors have shape `[0, ...]`. The marlin MoE kernel crashes on these empty inputs. Fixed by returning zeros early when `E=0` so CPU experts provide the full result. 3. **`deepseek_v2.py` dual-stream conflict with KT wrapper** — `forward_normal_dual_stream` uses `alt_stream` for shared expert parallelism, which conflicts with KT wrapper's internal `_cpu_stream` during CUDA graph capture. Fixed by skipping dual-stream path when using KT wrapper. ### How to update ```bash cd sglang git pull origin main ``` ### Verified on - RTX 5090 (SM120 Blackwell), single GPU - `--kt-num-gpu-experts 0 --kt-method RAWINT4 --attention-backend triton` - CUDA graph capture: OK - Decode with CUDA graph: OK, correct output - `What is 2+3?` → `5` (correct reasoning + answer) Please update both SGLang and KTransformers to the latest main branch and let us know if the issue persists. --- *This reply was co-authored by an AI agent and a human.*
Author
Owner

@DocShotgun commented on GitHub (Mar 1, 2026):

Pulled everything to latest, got a bit further this time than last, but ran into a new error when the first inference request hits the server:

Traceback (most recent call last):
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/managers/scheduler.py", line 3157, in run_scheduler_process
    scheduler.event_loop_overlap()
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/utils/_contextlib.py", line 120, in decorate_context
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/managers/scheduler.py", line 1160, in event_loop_overlap
    batch_result = self.run_batch(batch)
                   ^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/managers/scheduler.py", line 2317, in run_batch
    batch_result = self.model_worker.forward_batch_generation(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/managers/tp_worker.py", line 456, in forward_batch_generation
    out = self.model_runner.forward(
          ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/model_executor/model_runner.py", line 2394, in forward
    output = self._forward_raw(
             ^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/model_executor/model_runner.py", line 2496, in _forward_raw
    ret, can_run_graph = self.forward_extend(
                         ^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/model_executor/model_runner.py", line 2331, in forward_extend
    self.model.forward(
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/models/kimi_k25.py", line 727, in forward
    hidden_states = general_mm_embed_routine(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/managers/mm_utils.py", line 1134, in general_mm_embed_routine
    hidden_states = language_model(
                    ^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1775, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1786, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/utils/_contextlib.py", line 120, in decorate_context
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/models/deepseek_v2.py", line 2999, in forward
    hidden_states = self.model(
                    ^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1775, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1786, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/models/deepseek_v2.py", line 2750, in forward
    hidden_states, residual = layer(
                              ^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1775, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1786, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/models/deepseek_v2.py", line 2440, in forward
    hidden_states = self.mlp(
                    ^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1775, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1786, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/models/deepseek_v2.py", line 585, in forward
    return self.forward_normal(
           ^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/models/deepseek_v2.py", line 683, in forward_normal
    final_hidden_states = self.experts(
                          ^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1775, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1786, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/layers/moe/fused_moe_triton/layer.py", line 983, in forward
    return self.forward_impl(hidden_states, topk_output)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/layers/moe/fused_moe_triton/layer.py", line 1002, in forward_impl
    combine_input = self.run_moe_core(
                    ^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/layers/moe/fused_moe_triton/layer.py", line 1023, in run_moe_core
    return self.quant_method.apply(
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/layers/moe/kt_ep_wrapper.py", line 2269, in apply
    ctx = self._build_full_context(layer)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/layers/moe/kt_ep_wrapper.py", line 2483, in _build_full_context
    _SHARED_FULL_CONTEXT.load(
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/layers/moe/kt_ep_wrapper.py", line 1214, in load
    self._prepare_weight_int4(wrapper)
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/layers/moe/kt_ep_wrapper.py", line 520, in _prepare_weight_int4
    num_bits = method.num_bits
               ^^^^^^^^^^^^^^^
AttributeError: 'CompressedTensorsFusedMoEMethod' object has no attribute 'num_bits'

Using this launch command:

python -m sglang.launch_server \
  --host 0.0.0.0 \
  --port 5000 \
  --model /mnt/data2/models/Kimi-K2.5 \
  --kt-method RAWINT4 \
  --kt-weight-path /mnt/data2/models/Kimi-K2.5 \
  --kt-cpuinfer 128 \
  --kt-threadpool-count 4 \
  --kt-num-gpu-experts 0 \
  --kt-max-deferred-experts-per-token 0 \
  --kt-gpu-prefill-token-threshold 512 \
  --record-kt-gpu-expert-distribution \
  --trust-remote-code \
  --mem-fraction-static 0.97 \
  --served-model-name moonshotai/Kimi-K2.5 \
  --enable-mixed-chunk \
  --tensor-parallel-size 1 \
  --enable-p2p-check \
  --disable-shared-experts-fusion \
  --chunked-prefill-size 4096 \
  --context-length 65536 \
  --max-total-tokens 65536 \
  --max-running-requests 1 \
  --attention-backend triton \
  --reasoning-parser kimi_k2 \
  --tool-call-parser kimi_k2

EDIT: Also, it seems like setting --kt-num-gpu-experts to anything above 0 results in a kernel launch error on CUDA graph capture:

Traceback (most recent call last):
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/model_executor/cuda_graph_runner.py", line 567, in __init__
    self.capture()
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/model_executor/cuda_graph_runner.py", line 723, in capture
    _capture_one_stream()
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/model_executor/cuda_graph_runner.py", line 710, in _capture_one_stream
    ) = self.capture_one_batch_size(bs, forward, stream_idx)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/model_executor/cuda_graph_runner.py", line 929, in capture_one_batch_size
    run_once()
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/model_executor/cuda_graph_runner.py", line 916, in run_once
    logits_output_or_pp_proxy_tensors = forward(
                                        ^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/models/kimi_k25.py", line 727, in forward
    hidden_states = general_mm_embed_routine(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/managers/mm_utils.py", line 1134, in general_mm_embed_routine
    hidden_states = language_model(
                    ^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1775, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1786, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/utils/_contextlib.py", line 120, in decorate_context
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/models/deepseek_v2.py", line 2999, in forward
    hidden_states = self.model(
                    ^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1775, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1786, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/models/deepseek_v2.py", line 2750, in forward
    hidden_states, residual = layer(
                              ^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1775, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1786, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/models/deepseek_v2.py", line 2440, in forward
    hidden_states = self.mlp(
                    ^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1775, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1786, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/layers/moe/fused_moe_triton/layer.py", line 983, in forward
    return self.forward_impl(hidden_states, topk_output)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/layers/moe/fused_moe_triton/layer.py", line 1002, in forward_impl
    combine_input = self.run_moe_core(
                    ^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/layers/moe/fused_moe_triton/layer.py", line 1023, in run_moe_core
    return self.quant_method.apply(
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/layers/moe/kt_ep_wrapper.py", line 2340, in apply
    gpu_combine_input = self.gpu_method.apply(layer, masked_dispatch_output)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/layers/quantization/compressed_tensors/compressed_tensors.py", line 1014, in apply
    return scheme.apply_weights(layer, dispatch_output)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/layers/quantization/compressed_tensors/schemes/compressed_tensors_wNa16_moe.py", line 387, in apply_weights
    output = fused_marlin_moe(
             ^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/layers/moe/fused_moe_triton/fused_marlin_moe.py", line 230, in fused_marlin_moe
    moe_sum_reduce(
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sgl_kernel/moe.py", line 88, in moe_sum_reduce
    torch.ops.sgl_kernel.moe_sum_reduce.default(
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/_ops.py", line 841, in __call__
    return self._op(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: moe_sum_reduce CUDA kernel (small-token) launch failed

I don't think this is a VRAM-related issue as I have over 50gb of VRAM free at this point.

<!-- gh-comment-id:3980584398 --> @DocShotgun commented on GitHub (Mar 1, 2026): Pulled everything to latest, got a bit further this time than last, but ran into a new error when the first inference request hits the server: ``` Traceback (most recent call last): File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/managers/scheduler.py", line 3157, in run_scheduler_process scheduler.event_loop_overlap() File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/utils/_contextlib.py", line 120, in decorate_context return func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/managers/scheduler.py", line 1160, in event_loop_overlap batch_result = self.run_batch(batch) ^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/managers/scheduler.py", line 2317, in run_batch batch_result = self.model_worker.forward_batch_generation( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/managers/tp_worker.py", line 456, in forward_batch_generation out = self.model_runner.forward( ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/model_executor/model_runner.py", line 2394, in forward output = self._forward_raw( ^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/model_executor/model_runner.py", line 2496, in _forward_raw ret, can_run_graph = self.forward_extend( ^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/model_executor/model_runner.py", line 2331, in forward_extend self.model.forward( File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/models/kimi_k25.py", line 727, in forward hidden_states = general_mm_embed_routine( ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/managers/mm_utils.py", line 1134, in general_mm_embed_routine hidden_states = language_model( ^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1775, in _wrapped_call_impl return self._call_impl(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1786, in _call_impl return forward_call(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/utils/_contextlib.py", line 120, in decorate_context return func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/models/deepseek_v2.py", line 2999, in forward hidden_states = self.model( ^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1775, in _wrapped_call_impl return self._call_impl(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1786, in _call_impl return forward_call(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/models/deepseek_v2.py", line 2750, in forward hidden_states, residual = layer( ^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1775, in _wrapped_call_impl return self._call_impl(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1786, in _call_impl return forward_call(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/models/deepseek_v2.py", line 2440, in forward hidden_states = self.mlp( ^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1775, in _wrapped_call_impl return self._call_impl(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1786, in _call_impl return forward_call(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/models/deepseek_v2.py", line 585, in forward return self.forward_normal( ^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/models/deepseek_v2.py", line 683, in forward_normal final_hidden_states = self.experts( ^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1775, in _wrapped_call_impl return self._call_impl(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1786, in _call_impl return forward_call(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/layers/moe/fused_moe_triton/layer.py", line 983, in forward return self.forward_impl(hidden_states, topk_output) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/layers/moe/fused_moe_triton/layer.py", line 1002, in forward_impl combine_input = self.run_moe_core( ^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/layers/moe/fused_moe_triton/layer.py", line 1023, in run_moe_core return self.quant_method.apply( ^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/layers/moe/kt_ep_wrapper.py", line 2269, in apply ctx = self._build_full_context(layer) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/layers/moe/kt_ep_wrapper.py", line 2483, in _build_full_context _SHARED_FULL_CONTEXT.load( File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/layers/moe/kt_ep_wrapper.py", line 1214, in load self._prepare_weight_int4(wrapper) File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/layers/moe/kt_ep_wrapper.py", line 520, in _prepare_weight_int4 num_bits = method.num_bits ^^^^^^^^^^^^^^^ AttributeError: 'CompressedTensorsFusedMoEMethod' object has no attribute 'num_bits' ``` Using this launch command: ``` python -m sglang.launch_server \ --host 0.0.0.0 \ --port 5000 \ --model /mnt/data2/models/Kimi-K2.5 \ --kt-method RAWINT4 \ --kt-weight-path /mnt/data2/models/Kimi-K2.5 \ --kt-cpuinfer 128 \ --kt-threadpool-count 4 \ --kt-num-gpu-experts 0 \ --kt-max-deferred-experts-per-token 0 \ --kt-gpu-prefill-token-threshold 512 \ --record-kt-gpu-expert-distribution \ --trust-remote-code \ --mem-fraction-static 0.97 \ --served-model-name moonshotai/Kimi-K2.5 \ --enable-mixed-chunk \ --tensor-parallel-size 1 \ --enable-p2p-check \ --disable-shared-experts-fusion \ --chunked-prefill-size 4096 \ --context-length 65536 \ --max-total-tokens 65536 \ --max-running-requests 1 \ --attention-backend triton \ --reasoning-parser kimi_k2 \ --tool-call-parser kimi_k2 ``` EDIT: Also, it seems like setting `--kt-num-gpu-experts` to anything above 0 results in a kernel launch error on CUDA graph capture: ``` Traceback (most recent call last): File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/model_executor/cuda_graph_runner.py", line 567, in __init__ self.capture() File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/model_executor/cuda_graph_runner.py", line 723, in capture _capture_one_stream() File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/model_executor/cuda_graph_runner.py", line 710, in _capture_one_stream ) = self.capture_one_batch_size(bs, forward, stream_idx) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/model_executor/cuda_graph_runner.py", line 929, in capture_one_batch_size run_once() File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/model_executor/cuda_graph_runner.py", line 916, in run_once logits_output_or_pp_proxy_tensors = forward( ^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/models/kimi_k25.py", line 727, in forward hidden_states = general_mm_embed_routine( ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/managers/mm_utils.py", line 1134, in general_mm_embed_routine hidden_states = language_model( ^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1775, in _wrapped_call_impl return self._call_impl(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1786, in _call_impl return forward_call(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/utils/_contextlib.py", line 120, in decorate_context return func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/models/deepseek_v2.py", line 2999, in forward hidden_states = self.model( ^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1775, in _wrapped_call_impl return self._call_impl(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1786, in _call_impl return forward_call(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/models/deepseek_v2.py", line 2750, in forward hidden_states, residual = layer( ^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1775, in _wrapped_call_impl return self._call_impl(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1786, in _call_impl return forward_call(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/models/deepseek_v2.py", line 2440, in forward hidden_states = self.mlp( ^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1775, in _wrapped_call_impl return self._call_impl(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1786, in _call_impl return forward_call(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/layers/moe/fused_moe_triton/layer.py", line 983, in forward return self.forward_impl(hidden_states, topk_output) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/layers/moe/fused_moe_triton/layer.py", line 1002, in forward_impl combine_input = self.run_moe_core( ^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/layers/moe/fused_moe_triton/layer.py", line 1023, in run_moe_core return self.quant_method.apply( ^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/layers/moe/kt_ep_wrapper.py", line 2340, in apply gpu_combine_input = self.gpu_method.apply(layer, masked_dispatch_output) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/layers/quantization/compressed_tensors/compressed_tensors.py", line 1014, in apply return scheme.apply_weights(layer, dispatch_output) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/layers/quantization/compressed_tensors/schemes/compressed_tensors_wNa16_moe.py", line 387, in apply_weights output = fused_marlin_moe( ^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/layers/moe/fused_moe_triton/fused_marlin_moe.py", line 230, in fused_marlin_moe moe_sum_reduce( File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sgl_kernel/moe.py", line 88, in moe_sum_reduce torch.ops.sgl_kernel.moe_sum_reduce.default( File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/torch/_ops.py", line 841, in __call__ return self._op(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^ RuntimeError: moe_sum_reduce CUDA kernel (small-token) launch failed ``` I don't think this is a VRAM-related issue as I have over 50gb of VRAM free at this point.
Author
Owner

@triplenom commented on GitHub (Mar 1, 2026):

I'm seeing the same as @DocShotgun with a similar setup (Nvidia RTX Pro 6000 + Epyc 9654)

With --kt-num-gpu-experts 0 and no layerwise prefill generation is as expected.

If I provide a long prompt that hits layerwise prefill, see the same error:

File "/home/mike/sglang-kimi-mar1/ktransformers/sglang/python/sglang/srt/layers/moe/kt_ep_wrapper.py", line 520, in _prepare_weight_int4
num_bits = method.num_bits
^^^^^^^^^^^^^^^
AttributeError: 'CompressedTensorsFusedMoEMethod' object has no attribute 'num_bits'

<!-- gh-comment-id:3981212768 --> @triplenom commented on GitHub (Mar 1, 2026): I'm seeing the same as @DocShotgun with a similar setup (Nvidia RTX Pro 6000 + Epyc 9654) With --kt-num-gpu-experts 0 and no layerwise prefill generation is as expected. If I provide a long prompt that hits layerwise prefill, see the same error: File "/home/mike/sglang-kimi-mar1/ktransformers/sglang/python/sglang/srt/layers/moe/kt_ep_wrapper.py", line 520, in _prepare_weight_int4 num_bits = method.num_bits ^^^^^^^^^^^^^^^ AttributeError: 'CompressedTensorsFusedMoEMethod' object has no attribute 'num_bits'
Author
Owner

@triplenom commented on GitHub (Mar 2, 2026):

If I force num_bits=4 and packed_factor=32 for the RAWINT case in kt_ep_wrapper.py then layerwise prefill seems to work fine, so that seems easy enough to resolve.

<!-- gh-comment-id:3981480268 --> @triplenom commented on GitHub (Mar 2, 2026): If I force num_bits=4 and packed_factor=32 for the RAWINT case in kt_ep_wrapper.py then layerwise prefill seems to work fine, so that seems easy enough to resolve.
Author
Owner

@DocShotgun commented on GitHub (Mar 2, 2026):

If I force num_bits=4 and packed_factor=32 for the RAWINT case in kt_ep_wrapper.py then layerwise prefill seems to work fine, so that seems easy enough to resolve.

After a few rounds of trial and error, I figured out that the correct values are:

num_bits = 4
packed_factor = 8
group_size = 32

and I managed to get it to load and infer with the following launch command:

python -m sglang.launch_server \
  --host 0.0.0.0 \
  --port 5000 \
  --model /mnt/data2/models/Kimi-K2.5 \
  --kt-method RAWINT4 \
  --kt-weight-path /mnt/data2/models/Kimi-K2.5 \
  --kt-cpuinfer 128 \
  --kt-threadpool-count 4 \
  --kt-num-gpu-experts 0 \
  --kt-max-deferred-experts-per-token 0 \
  --kt-gpu-prefill-token-threshold 512 \
  --trust-remote-code \
  --mem-fraction-static 0.97 \
  --served-model-name moonshotai/Kimi-K2.5 \
  --enable-mixed-chunk \
  --tensor-parallel-size 1 \
  --enable-p2p-check \
  --disable-shared-experts-fusion \
  --chunked-prefill-size 4096 \
  --context-length 65536 \
  --max-total-tokens 65536 \
  --max-running-requests 1 \
  --attention-backend triton \
  --reasoning-parser kimi_k2 \
  --tool-call-parser kimi_k2

however, the model is still outputting nonsense whenever it goes down the GPU prefill codepath. For those of you who are getting it to generate coherent text with GPU prefill, is your --kt-threadpool-count == --tensor-parallel-size?

Also increasing --kt-num-gpu-experts to a non-zero value still results in the above RuntimeError: moe_sum_reduce CUDA kernel (small-token) launch failed error.

<!-- gh-comment-id:3981639513 --> @DocShotgun commented on GitHub (Mar 2, 2026): > If I force num_bits=4 and packed_factor=32 for the RAWINT case in kt_ep_wrapper.py then layerwise prefill seems to work fine, so that seems easy enough to resolve. After a few rounds of trial and error, I figured out that the correct values are: ``` num_bits = 4 packed_factor = 8 group_size = 32 ``` and I managed to get it to load and infer with the following launch command: ``` python -m sglang.launch_server \ --host 0.0.0.0 \ --port 5000 \ --model /mnt/data2/models/Kimi-K2.5 \ --kt-method RAWINT4 \ --kt-weight-path /mnt/data2/models/Kimi-K2.5 \ --kt-cpuinfer 128 \ --kt-threadpool-count 4 \ --kt-num-gpu-experts 0 \ --kt-max-deferred-experts-per-token 0 \ --kt-gpu-prefill-token-threshold 512 \ --trust-remote-code \ --mem-fraction-static 0.97 \ --served-model-name moonshotai/Kimi-K2.5 \ --enable-mixed-chunk \ --tensor-parallel-size 1 \ --enable-p2p-check \ --disable-shared-experts-fusion \ --chunked-prefill-size 4096 \ --context-length 65536 \ --max-total-tokens 65536 \ --max-running-requests 1 \ --attention-backend triton \ --reasoning-parser kimi_k2 \ --tool-call-parser kimi_k2 ``` however, the model is still outputting nonsense whenever it goes down the GPU prefill codepath. For those of you who are getting it to generate coherent text with GPU prefill, is your ` --kt-threadpool-count` == `--tensor-parallel-size`? Also increasing `--kt-num-gpu-experts` to a non-zero value still results in the above `RuntimeError: moe_sum_reduce CUDA kernel (small-token) launch failed` error.
Author
Owner

@ErvinXie commented on GitHub (Mar 2, 2026):

Thanks for the continued debugging, @DocShotgun and @triplenom.

We've noted both issues:

  1. num_bits AttributeError — The upstream SGLang merge changed the MoE quantization scheme class (CompressedTensorsFusedMoEMethod), which no longer exposes num_bits. Our kt_ep_wrapper.py still references the old attribute. We'll fix this.

  2. moe_sum_reduce kernel launch failure & GPU prefill gibberish — These are likely caused by operator compatibility issues introduced by the upstream SGLang merge. The new marlin MoE kernel path behaves differently from the original one, and we need to verify compatibility across the full GPU offload prefill codepath.

We need some time to investigate and fix these properly. In the meantime, please use the kimi_k2.5 branch as a workaround, or set --kt-gpu-prefill-token-threshold to a very large value to disable GPU prefill.

Will update this issue once the fixes are ready.


This reply was co-authored by an AI agent and a human.

<!-- gh-comment-id:3981821196 --> @ErvinXie commented on GitHub (Mar 2, 2026): Thanks for the continued debugging, @DocShotgun and @triplenom. We've noted both issues: 1. **`num_bits` AttributeError** — The upstream SGLang merge changed the MoE quantization scheme class (`CompressedTensorsFusedMoEMethod`), which no longer exposes `num_bits`. Our `kt_ep_wrapper.py` still references the old attribute. We'll fix this. 2. **`moe_sum_reduce` kernel launch failure & GPU prefill gibberish** — These are likely caused by operator compatibility issues introduced by the upstream SGLang merge. The new marlin MoE kernel path behaves differently from the original one, and we need to verify compatibility across the full GPU offload prefill codepath. We need some time to investigate and fix these properly. In the meantime, please use the `kimi_k2.5` branch as a workaround, or set `--kt-gpu-prefill-token-threshold` to a very large value to disable GPU prefill. Will update this issue once the fixes are ready. --- *This reply was co-authored by an AI agent and a human.*
Author
Owner

@ErvinXie commented on GitHub (Mar 2, 2026):

It may take som time to fix this.

<!-- gh-comment-id:3981823204 --> @ErvinXie commented on GitHub (Mar 2, 2026): It may take som time to fix this.
Author
Owner

@DocShotgun commented on GitHub (Mar 2, 2026):

Alright, understood. Trying to test the kimi_k2.5 branches of both ktransformers and the sglang fork, but it's having some multimodal-related error on server launch:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/launch_server.py", line 32, in <module>
    run_server(server_args)
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/launch_server.py", line 25, in run_server
    launch_server(server_args)
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/entrypoints/http_server.py", line 1753, in launch_server
    _launch_subprocesses(
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/entrypoints/engine.py", line 1004, in _launch_subprocesses
    tokenizer_manager, template_manager = init_tokenizer_manager_func(
                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/entrypoints/engine.py", line 102, in init_tokenizer_manager
    tokenizer_manager = TokenizerManagerClass(server_args, port_args)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/managers/tokenizer_manager.py", line 206, in __init__
    self.init_tokenizer_and_processor()
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/managers/tokenizer_manager.py", line 276, in init_tokenizer_and_processor
    self.mm_processor = get_mm_processor(
                        ^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/managers/multimodal_processor.py", line 50, in get_mm_processor
    raise ValueError(
ValueError: No processor registered for architecture: ['KimiK25ForConditionalGeneration'].
Registered architectures: ['WhisperForConditionalGeneration']
<!-- gh-comment-id:3982512315 --> @DocShotgun commented on GitHub (Mar 2, 2026): Alright, understood. Trying to test the `kimi_k2.5` branches of both ktransformers and the sglang fork, but it's having some multimodal-related error on server launch: ``` Traceback (most recent call last): File "<frozen runpy>", line 198, in _run_module_as_main File "<frozen runpy>", line 88, in _run_code File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/launch_server.py", line 32, in <module> run_server(server_args) File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/launch_server.py", line 25, in run_server launch_server(server_args) File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/entrypoints/http_server.py", line 1753, in launch_server _launch_subprocesses( File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/entrypoints/engine.py", line 1004, in _launch_subprocesses tokenizer_manager, template_manager = init_tokenizer_manager_func( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/entrypoints/engine.py", line 102, in init_tokenizer_manager tokenizer_manager = TokenizerManagerClass(server_args, port_args) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/managers/tokenizer_manager.py", line 206, in __init__ self.init_tokenizer_and_processor() File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/managers/tokenizer_manager.py", line 276, in init_tokenizer_and_processor self.mm_processor = get_mm_processor( ^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/managers/multimodal_processor.py", line 50, in get_mm_processor raise ValueError( ValueError: No processor registered for architecture: ['KimiK25ForConditionalGeneration']. Registered architectures: ['WhisperForConditionalGeneration'] ```
Author
Owner

@ouqingliang commented on GitHub (Mar 2, 2026):

If I force num_bits=4 and packed_factor=32 for the RAWINT case in kt_ep_wrapper.py then layerwise prefill seems to work fine, so that seems easy enough to resolve.

After a few rounds of trial and error, I figured out that the correct values are:

num_bits = 4
packed_factor = 8
group_size = 32

and I managed to get it to load and infer with the following launch command:

python -m sglang.launch_server \
  --host 0.0.0.0 \
  --port 5000 \
  --model /mnt/data2/models/Kimi-K2.5 \
  --kt-method RAWINT4 \
  --kt-weight-path /mnt/data2/models/Kimi-K2.5 \
  --kt-cpuinfer 128 \
  --kt-threadpool-count 4 \
  --kt-num-gpu-experts 0 \
  --kt-max-deferred-experts-per-token 0 \
  --kt-gpu-prefill-token-threshold 512 \
  --trust-remote-code \
  --mem-fraction-static 0.97 \
  --served-model-name moonshotai/Kimi-K2.5 \
  --enable-mixed-chunk \
  --tensor-parallel-size 1 \
  --enable-p2p-check \
  --disable-shared-experts-fusion \
  --chunked-prefill-size 4096 \
  --context-length 65536 \
  --max-total-tokens 65536 \
  --max-running-requests 1 \
  --attention-backend triton \
  --reasoning-parser kimi_k2 \
  --tool-call-parser kimi_k2

however, the model is still outputting nonsense whenever it goes down the GPU prefill codepath. For those of you who are getting it to generate coherent text with GPU prefill, is your --kt-threadpool-count == --tensor-parallel-size?

Also increasing --kt-num-gpu-experts to a non-zero value still results in the above RuntimeError: moe_sum_reduce CUDA kernel (small-token) launch failed error.

We’ve reproduced and fixed this on our side.

Root cause:
In the layerwise prefill fallback path for RAWINT4 (compressed-tensors), INT4 metadata was read from the outer fused method, while in this path the required fields are on the wrapped scheme/method chain. This could break prefill/offload behavior.

Fixes applied:

  1. Harden INT4 param resolution in kt_ep_wrapper (resolve num_bits/packed_factor/group_size from wrapped method/scheme chain).
  2. Fix MoE routing handling for the kt_num_gpu_experts>0 case (invalid expert-id path), which was causing incorrect behavior in this configuration.

After the fix, --kt-gpu-prefill-token-threshold and --kt_num_gpu_experts can stay enabled and long prompts are stable/coherent again.

Both sglang and ktransformers are on the main branch.
Patch commit (our sglang side): f1a12b9a9


This reply was generated by an AI agent and reviewed by a human.

<!-- gh-comment-id:3983490771 --> @ouqingliang commented on GitHub (Mar 2, 2026): > > If I force num_bits=4 and packed_factor=32 for the RAWINT case in kt_ep_wrapper.py then layerwise prefill seems to work fine, so that seems easy enough to resolve. > > After a few rounds of trial and error, I figured out that the correct values are: > > ``` > num_bits = 4 > packed_factor = 8 > group_size = 32 > ``` > > and I managed to get it to load and infer with the following launch command: > > ``` > python -m sglang.launch_server \ > --host 0.0.0.0 \ > --port 5000 \ > --model /mnt/data2/models/Kimi-K2.5 \ > --kt-method RAWINT4 \ > --kt-weight-path /mnt/data2/models/Kimi-K2.5 \ > --kt-cpuinfer 128 \ > --kt-threadpool-count 4 \ > --kt-num-gpu-experts 0 \ > --kt-max-deferred-experts-per-token 0 \ > --kt-gpu-prefill-token-threshold 512 \ > --trust-remote-code \ > --mem-fraction-static 0.97 \ > --served-model-name moonshotai/Kimi-K2.5 \ > --enable-mixed-chunk \ > --tensor-parallel-size 1 \ > --enable-p2p-check \ > --disable-shared-experts-fusion \ > --chunked-prefill-size 4096 \ > --context-length 65536 \ > --max-total-tokens 65536 \ > --max-running-requests 1 \ > --attention-backend triton \ > --reasoning-parser kimi_k2 \ > --tool-call-parser kimi_k2 > ``` > > however, the model is still outputting nonsense whenever it goes down the GPU prefill codepath. For those of you who are getting it to generate coherent text with GPU prefill, is your ` --kt-threadpool-count` == `--tensor-parallel-size`? > > Also increasing `--kt-num-gpu-experts` to a non-zero value still results in the above `RuntimeError: moe_sum_reduce CUDA kernel (small-token) launch failed` error. We’ve reproduced and fixed this on our side. Root cause: In the layerwise prefill fallback path for RAWINT4 (compressed-tensors), INT4 metadata was read from the outer fused method, while in this path the required fields are on the wrapped scheme/method chain. This could break prefill/offload behavior. Fixes applied: 1. Harden INT4 param resolution in `kt_ep_wrapper` (resolve `num_bits/packed_factor/group_size` from wrapped method/scheme chain). 2. Fix MoE routing handling for the `kt_num_gpu_experts>0` case (invalid expert-id path), which was causing incorrect behavior in this configuration. After the fix, `--kt-gpu-prefill-token-threshold` and `--kt_num_gpu_experts` can stay enabled and long prompts are stable/coherent again. Both `sglang` and `ktransformers` are on the `main` branch. Patch commit (our sglang side): `f1a12b9a9` --- *This reply was generated by an AI agent and reviewed by a human.*
Author
Owner

@DocShotgun commented on GitHub (Mar 2, 2026):

Hmm, pulled to latest main on both and reinstalled, now getting this:

Traceback (most recent call last):
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/managers/scheduler.py", line 3118, in run_scheduler_process
    scheduler = Scheduler(
                ^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/managers/scheduler.py", line 363, in __init__
    self.init_model_worker()
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/managers/scheduler.py", line 559, in init_model_worker
    self.init_tp_model_worker()
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/managers/scheduler.py", line 517, in init_tp_model_worker
    self.tp_worker = TpModelWorker(
                     ^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/managers/tp_worker.py", line 247, in __init__
    self._init_model_runner()
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/managers/tp_worker.py", line 330, in _init_model_runner
    self._model_runner = ModelRunner(
                         ^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/model_executor/model_runner.py", line 415, in __init__
    self.initialize(min_per_gpu_memory)
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/model_executor/model_runner.py", line 461, in initialize
    compute_initial_expert_location_metadata(
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/eplb/expert_location.py", line 571, in compute_initial_expert_location_metadata
    return ExpertLocationMetadata.init_trivial(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/eplb/expert_location.py", line 92, in init_trivial
    common = ExpertLocationMetadata._init_common(server_args, model_config)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/eplb/expert_location.py", line 193, in _init_common
    ModelConfigForExpertLocation.from_model_config(model_config)
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/eplb/expert_location.py", line 525, in from_model_config
    model_class, _ = get_model_architecture(model_config)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/model_loader/utils.py", line 90, in get_model_architecture
    from sglang.srt.models.registry import ModelRegistry
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/models/registry.py", line 129, in <module>
    ModelRegistry.register("sglang.srt.models")
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/models/registry.py", line 25, in register
    new_models = import_model_classes(package_name, strict=strict)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/models/registry.py", line 116, in import_model_classes
    tmp.__name__ not in model_arch_name_to_cls
AssertionError: Duplicated model implementation for KimiK25ForConditionalGeneration

EDIT: I think switching to the kimi_k2.5 branch and back perhaps left some stray files somewhere that git didn't catch. Did a clean clone of latest main and now the model is loading. Fingers crossed for it to work...

<!-- gh-comment-id:3985764156 --> @DocShotgun commented on GitHub (Mar 2, 2026): Hmm, pulled to latest main on both and reinstalled, now getting this: ``` Traceback (most recent call last): File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/managers/scheduler.py", line 3118, in run_scheduler_process scheduler = Scheduler( ^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/managers/scheduler.py", line 363, in __init__ self.init_model_worker() File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/managers/scheduler.py", line 559, in init_model_worker self.init_tp_model_worker() File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/managers/scheduler.py", line 517, in init_tp_model_worker self.tp_worker = TpModelWorker( ^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/managers/tp_worker.py", line 247, in __init__ self._init_model_runner() File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/managers/tp_worker.py", line 330, in _init_model_runner self._model_runner = ModelRunner( ^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/model_executor/model_runner.py", line 415, in __init__ self.initialize(min_per_gpu_memory) File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/model_executor/model_runner.py", line 461, in initialize compute_initial_expert_location_metadata( File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/eplb/expert_location.py", line 571, in compute_initial_expert_location_metadata return ExpertLocationMetadata.init_trivial( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/eplb/expert_location.py", line 92, in init_trivial common = ExpertLocationMetadata._init_common(server_args, model_config) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/eplb/expert_location.py", line 193, in _init_common ModelConfigForExpertLocation.from_model_config(model_config) File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/eplb/expert_location.py", line 525, in from_model_config model_class, _ = get_model_architecture(model_config) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/model_loader/utils.py", line 90, in get_model_architecture from sglang.srt.models.registry import ModelRegistry File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/models/registry.py", line 129, in <module> ModelRegistry.register("sglang.srt.models") File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/models/registry.py", line 25, in register new_models = import_model_classes(package_name, strict=strict) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docshotgun/sglang-kt/.venv/lib/python3.12/site-packages/sglang/srt/models/registry.py", line 116, in import_model_classes tmp.__name__ not in model_arch_name_to_cls AssertionError: Duplicated model implementation for KimiK25ForConditionalGeneration ``` EDIT: I think switching to the `kimi_k2.5` branch and back perhaps left some stray files somewhere that git didn't catch. Did a clean clone of latest main and now the model is loading. Fingers crossed for it to work...
Author
Owner

@trilog-inc commented on GitHub (Mar 2, 2026):

The update has worked for me. No gibberish 👍

Only detail, update xgrammar to 0.1.31 as some of the function/thinking parsing is broken in previous versions. Also ensure the thinking argument is sent. Currently running a 75K context and everything is coherent and fast.

Thanks kt team!

<!-- gh-comment-id:3985963824 --> @trilog-inc commented on GitHub (Mar 2, 2026): The update has worked for me. No gibberish 👍 Only detail, update xgrammar to 0.1.31 as some of the function/thinking parsing is broken in previous versions. Also ensure the thinking argument is sent. Currently running a 75K context and everything is coherent and fast. Thanks kt team!
Author
Owner

@DocShotgun commented on GitHub (Mar 2, 2026):

Okay, everything runs without errors on the current main branches: github.com/kvcache-ai/ktransformers@9e69fccb02 github.com/kvcache-ai/sglang@f1a12b9a93

Unfortunately the model is still producing nonsense for me when using GPU offload prefill:
Image

With settings:

python -m sglang.launch_server \
  --host 0.0.0.0 \
  --port 5000 \
  --model /mnt/data2/models/Kimi-K2.5 \
  --kt-method RAWINT4 \
  --kt-weight-path /mnt/data2/models/Kimi-K2.5 \
  --kt-cpuinfer 128 \
  --kt-threadpool-count 4 \
  --kt-num-gpu-experts 0 \
  --kt-max-deferred-experts-per-token 0 \
  --kt-gpu-prefill-token-threshold 512 \
  --trust-remote-code \
  --mem-fraction-static 0.98 \
  --served-model-name moonshotai/Kimi-K2.5 \
  --enable-mixed-chunk \
  --tensor-parallel-size 1 \
  --enable-p2p-check \
  --disable-shared-experts-fusion \
  --chunked-prefill-size 4096 \
  --context-length 65536 \
  --max-total-tokens 65536 \
  --max-running-requests 1 \
  --attention-backend flashinfer \
  --reasoning-parser kimi_k2 \
  --tool-call-parser kimi_k2

Using the recommended temp 0.6, top p 0.95 for non-thinking mode.

My hunch is still that it has something to do with NUMA TP != GPU TP since that seems to be the main factor unique to my machine here, in my case NUMA TP=4 with GPU TP=1.

<!-- gh-comment-id:3986331914 --> @DocShotgun commented on GitHub (Mar 2, 2026): Okay, everything runs without errors on the current main branches: https://github.com/kvcache-ai/ktransformers/commit/9e69fccb026b1359bb850b8b7bef09be23b6cbb7 https://github.com/kvcache-ai/sglang/commit/f1a12b9a934331396716809b391ff4f2bc492983 Unfortunately the model is still producing nonsense for me when using GPU offload prefill: <img width="853" height="768" alt="Image" src="https://github.com/user-attachments/assets/ef06e582-518d-4987-97c7-6211b61402b9" /> With settings: ``` python -m sglang.launch_server \ --host 0.0.0.0 \ --port 5000 \ --model /mnt/data2/models/Kimi-K2.5 \ --kt-method RAWINT4 \ --kt-weight-path /mnt/data2/models/Kimi-K2.5 \ --kt-cpuinfer 128 \ --kt-threadpool-count 4 \ --kt-num-gpu-experts 0 \ --kt-max-deferred-experts-per-token 0 \ --kt-gpu-prefill-token-threshold 512 \ --trust-remote-code \ --mem-fraction-static 0.98 \ --served-model-name moonshotai/Kimi-K2.5 \ --enable-mixed-chunk \ --tensor-parallel-size 1 \ --enable-p2p-check \ --disable-shared-experts-fusion \ --chunked-prefill-size 4096 \ --context-length 65536 \ --max-total-tokens 65536 \ --max-running-requests 1 \ --attention-backend flashinfer \ --reasoning-parser kimi_k2 \ --tool-call-parser kimi_k2 ``` Using the recommended temp 0.6, top p 0.95 for non-thinking mode. My hunch is still that it has something to do with NUMA TP != GPU TP since that seems to be the main factor unique to my machine here, in my case NUMA TP=4 with GPU TP=1.
Author
Owner

@ouqingliang commented on GitHub (Mar 3, 2026):

Okay, everything runs without errors on the current main branches: 9e69fcc kvcache-ai/sglang@f1a12b9

Unfortunately the model is still producing nonsense for me when using GPU offload prefill: Image

With settings:

python -m sglang.launch_server \
  --host 0.0.0.0 \
  --port 5000 \
  --model /mnt/data2/models/Kimi-K2.5 \
  --kt-method RAWINT4 \
  --kt-weight-path /mnt/data2/models/Kimi-K2.5 \
  --kt-cpuinfer 128 \
  --kt-threadpool-count 4 \
  --kt-num-gpu-experts 0 \
  --kt-max-deferred-experts-per-token 0 \
  --kt-gpu-prefill-token-threshold 512 \
  --trust-remote-code \
  --mem-fraction-static 0.98 \
  --served-model-name moonshotai/Kimi-K2.5 \
  --enable-mixed-chunk \
  --tensor-parallel-size 1 \
  --enable-p2p-check \
  --disable-shared-experts-fusion \
  --chunked-prefill-size 4096 \
  --context-length 65536 \
  --max-total-tokens 65536 \
  --max-running-requests 1 \
  --attention-backend flashinfer \
  --reasoning-parser kimi_k2 \
  --tool-call-parser kimi_k2

Using the recommended temp 0.6, top p 0.95 for non-thinking mode.

My hunch is still that it has something to do with NUMA TP != GPU TP since that seems to be the main factor unique to my machine here, in my case NUMA TP=4 with GPU TP=1.

Thanks for the very clear repro, this helped a lot.

We dug into this in detail, and the root cause is not the CPU TP/GPU TP mapping formula itself.
The main issue was a double-buffer reuse race in SGLang's RAWINT4 layerwise prefill fallback path.

Root cause

In kt_ep_wrapper.py (_prepare_weight_int4), we use a 2-slot pinned host buffer pipeline:

  • write expert e+1 into slot (e+1)%2
  • async H2D copy expert e from slot e%2
  • postprocess expert e-1

For INT4, before reusing the next slot, we were missing the same synchronization guard that FP8/BF16 already had.
So under some topologies, CPU starts writing the next expert into a slot while GPU DMA is still reading that slot.

Why your machine is easier to trigger

Your case (NUMA TP=4, GPU TP=1) makes this race window much larger:

  • GPU TP=1 => per-slot H2D payload is large (copy takes longer)
  • CPU TP=4 => writes are faster/more parallel (slot gets reused sooner)

So this is very consistent with "runs without errors but output quality collapses under GPU offload prefill".

Fix

We added slot-reuse synchronization in the INT4 path before submitting the next write (same pattern as FP8/BF16).

  • SGLang commit: b3356b6c4
  • Repo: kvcache-ai/sglang (main)

Please pull latest main for both sglang and ktransformers and retest with the same command.


This reply was generated by an AI agent and reviewed by a human.

<!-- gh-comment-id:3988952485 --> @ouqingliang commented on GitHub (Mar 3, 2026): > Okay, everything runs without errors on the current main branches: [9e69fcc](https://github.com/kvcache-ai/ktransformers/commit/9e69fccb026b1359bb850b8b7bef09be23b6cbb7) [kvcache-ai/sglang@f1a12b9](https://github.com/kvcache-ai/sglang/commit/f1a12b9a934331396716809b391ff4f2bc492983) > > Unfortunately the model is still producing nonsense for me when using GPU offload prefill: <img alt="Image" width="853" height="768" src="https://private-user-images.githubusercontent.com/126566557/557073241-ef06e582-518d-4987-97c7-6211b61402b9.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzI1MTk0MDksIm5iZiI6MTc3MjUxOTEwOSwicGF0aCI6Ii8xMjY1NjY1NTcvNTU3MDczMjQxLWVmMDZlNTgyLTUxOGQtNDk4Ny05N2M3LTYyMTFiNjE0MDJiOS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjYwMzAzJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI2MDMwM1QwNjI1MDlaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT0yYjBmMzk2Nzc0N2U3MTdiOThjYzM0ZWZkODEwNjE1OWFhMDgxYjkzN2QwM2RhNjBiMDZkNTgzZGEwNmRmYWY1JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.2GmeNPwmcC5Yoi2FyRdNGTS_NU5YtNKIA5IAKISFqPE"> > > With settings: > > ``` > python -m sglang.launch_server \ > --host 0.0.0.0 \ > --port 5000 \ > --model /mnt/data2/models/Kimi-K2.5 \ > --kt-method RAWINT4 \ > --kt-weight-path /mnt/data2/models/Kimi-K2.5 \ > --kt-cpuinfer 128 \ > --kt-threadpool-count 4 \ > --kt-num-gpu-experts 0 \ > --kt-max-deferred-experts-per-token 0 \ > --kt-gpu-prefill-token-threshold 512 \ > --trust-remote-code \ > --mem-fraction-static 0.98 \ > --served-model-name moonshotai/Kimi-K2.5 \ > --enable-mixed-chunk \ > --tensor-parallel-size 1 \ > --enable-p2p-check \ > --disable-shared-experts-fusion \ > --chunked-prefill-size 4096 \ > --context-length 65536 \ > --max-total-tokens 65536 \ > --max-running-requests 1 \ > --attention-backend flashinfer \ > --reasoning-parser kimi_k2 \ > --tool-call-parser kimi_k2 > ``` > > Using the recommended temp 0.6, top p 0.95 for non-thinking mode. > > My hunch is still that it has something to do with NUMA TP != GPU TP since that seems to be the main factor unique to my machine here, in my case NUMA TP=4 with GPU TP=1. Thanks for the very clear repro, this helped a lot. We dug into this in detail, and the root cause is not the CPU TP/GPU TP mapping formula itself. The main issue was a double-buffer reuse race in SGLang's RAWINT4 layerwise prefill fallback path. ## Root cause In `kt_ep_wrapper.py` (`_prepare_weight_int4`), we use a 2-slot pinned host buffer pipeline: - write expert `e+1` into slot `(e+1)%2` - async H2D copy expert `e` from slot `e%2` - postprocess expert `e-1` For INT4, before reusing the next slot, we were missing the same synchronization guard that FP8/BF16 already had. So under some topologies, CPU starts writing the next expert into a slot while GPU DMA is still reading that slot. ## Why your machine is easier to trigger Your case (`NUMA TP=4`, `GPU TP=1`) makes this race window much larger: - `GPU TP=1` => per-slot H2D payload is large (copy takes longer) - `CPU TP=4` => writes are faster/more parallel (slot gets reused sooner) So this is very consistent with "runs without errors but output quality collapses under GPU offload prefill". ## Fix We added slot-reuse synchronization in the INT4 path before submitting the next write (same pattern as FP8/BF16). - SGLang commit: `b3356b6c4` - Repo: `kvcache-ai/sglang` (main) Please pull latest `main` for both `sglang` and `ktransformers` and retest with the same command. --- *This reply was generated by an AI agent and reviewed by a human.*
Author
Owner

@DocShotgun commented on GitHub (Mar 4, 2026):

  • SGLang commit: b3356b6c4
  • Repo: kvcache-ai/sglang (main)

By golly, that did it! This time I managed to generate coherent text with GPU layerwise prefill! Token gen speed dropped a tad compared to when it was generating nonsense, but the significance of that is unclear.

A few observations:

  1. kt-kernel's token gen speed is noticeably faster than llama.cpp with NUMA distribute and memory interleave (on an equivalent GGUF with the INT4-32g QAT mapped to q4_0) due to proper NUMA awareness.
  2. kt-kernel's GPU offload prefill is slower than llama.cpp's and doesn't manage to saturate my PCIe 5.0 x16, peaking at around RX 10s-20s GB/s while llama.cpp is able to hit 50+ GB/s at times. I'm not sure if this is because kt-kernel has to do additional work to prepare the weights before transferring to GPU (around 350-500ms per layer) compared to llama.cpp's host buffer.

The tokenization endpoint also keeps failing with TypeError: Integer exceeds 64-bit range on JSON decode, although I don't think this error is related to ktransformers.

Anyhow, thanks for your hard work and attention!

This is the current launch command I've gotten, not sure if there's any more room for adjustment. --record-kt-gpu-expert-distribution didn't seem to write out anything while the server was running or after shutting it down.

PYTORCH_ALLOC_CONF=expandable_segments:True \
python -m sglang.launch_server \
  --host 0.0.0.0 \
  --port 5000 \
  --model /mnt/data2/models/Kimi-K2.5 \
  --kt-method RAWINT4 \
  --kt-weight-path /mnt/data2/models/Kimi-K2.5 \
  --kt-cpuinfer 128 \
  --kt-threadpool-count 4 \
  --kt-num-gpu-experts 36 \
  --kt-max-deferred-experts-per-token 0 \
  --kt-gpu-prefill-token-threshold 512 \
  --kt-enable-dynamic-expert-update \
  --trust-remote-code \
  --mem-fraction-static 0.98 \
  --served-model-name moonshotai/Kimi-K2.5 \
  --enable-mixed-chunk \
  --tensor-parallel-size 1 \
  --enable-p2p-check \
  --disable-shared-experts-fusion \
  --chunked-prefill-size 16384 \
  --context-length 65536 \
  --max-total-tokens 65536 \
  --max-running-requests 1 \
  --attention-backend flashinfer \
  --reasoning-parser kimi_k2 \
  --tool-call-parser kimi_k2
<!-- gh-comment-id:3995303338 --> @DocShotgun commented on GitHub (Mar 4, 2026): > * SGLang commit: `b3356b6c4` > * Repo: `kvcache-ai/sglang` (main) By golly, that did it! This time I managed to generate coherent text with GPU layerwise prefill! Token gen speed dropped a tad compared to when it was generating nonsense, but the significance of that is unclear. A few observations: 1. `kt-kernel`'s token gen speed is noticeably faster than `llama.cpp` with NUMA distribute and memory interleave (on an equivalent GGUF with the INT4-32g QAT mapped to q4_0) due to proper NUMA awareness. 2. `kt-kernel`'s GPU offload prefill is slower than `llama.cpp`'s and doesn't manage to saturate my PCIe 5.0 x16, peaking at around RX 10s-20s GB/s while llama.cpp is able to hit 50+ GB/s at times. I'm not sure if this is because `kt-kernel` has to do additional work to prepare the weights before transferring to GPU (around 350-500ms per layer) compared to `llama.cpp`'s host buffer. The tokenization endpoint also keeps failing with `TypeError: Integer exceeds 64-bit range` on JSON decode, although I don't think this error is related to `ktransformers`. Anyhow, thanks for your hard work and attention! This is the current launch command I've gotten, not sure if there's any more room for adjustment. `--record-kt-gpu-expert-distribution` didn't seem to write out anything while the server was running or after shutting it down. ``` PYTORCH_ALLOC_CONF=expandable_segments:True \ python -m sglang.launch_server \ --host 0.0.0.0 \ --port 5000 \ --model /mnt/data2/models/Kimi-K2.5 \ --kt-method RAWINT4 \ --kt-weight-path /mnt/data2/models/Kimi-K2.5 \ --kt-cpuinfer 128 \ --kt-threadpool-count 4 \ --kt-num-gpu-experts 36 \ --kt-max-deferred-experts-per-token 0 \ --kt-gpu-prefill-token-threshold 512 \ --kt-enable-dynamic-expert-update \ --trust-remote-code \ --mem-fraction-static 0.98 \ --served-model-name moonshotai/Kimi-K2.5 \ --enable-mixed-chunk \ --tensor-parallel-size 1 \ --enable-p2p-check \ --disable-shared-experts-fusion \ --chunked-prefill-size 16384 \ --context-length 65536 \ --max-total-tokens 65536 \ --max-running-requests 1 \ --attention-backend flashinfer \ --reasoning-parser kimi_k2 \ --tool-call-parser kimi_k2 ```
Author
Owner

@DocShotgun commented on GitHub (Mar 6, 2026):

Closing this as the titular issue has been resolved.

<!-- gh-comment-id:4009408266 --> @DocShotgun commented on GitHub (Mar 6, 2026): Closing this as the titular issue has been resolved.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
kvcache-ai/ktransformers#1163
No description provided.