kvcache-ai / kvcache-ai/ktransformers

Error with Deepskeep 4 flash with trtllm_fp4_block_scale_moe

Open
#2,106 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
19.5k
Forks
1.6k
Avg merge
19h 32m
Merged PRs (30d)
27

Description

### Reminder

- [x] I have read the above rules and searched the existing issues.

### System Info

Here I attempted to run sglang server with ktransformers, in a virtual machine with a B200 GPU. An error appears in a CUDA kernel flashinfer::trtllm_fp4_block_scale_moe . The machine has 24 virtual processors Xeon Platinum 8570, with instructions AMX

```
[2026-07-23 23:08:50] Scheduler hit an exception: Traceback (most recent call last):
File "/home/ramon/kt-deepseek/lib/python3.12/site-packages/sglang/srt/model_executor/cuda_graph_runner.py", line 570, in __init__
self.capture()
File "/home/ramon/kt-deepseek/lib/python3.12/site-packages/sglang/srt/model_executor/cuda_graph_runner.py", line 726, in capture
_capture_one_stream()
File "/home/ramon/kt-deepseek/lib/python3.12/site-packages/sglang/srt/model_executor/cuda_graph_runner.py", line 713, in _capture_one_stream
) = self.capture_one_batch_size(bs, forward, stream_idx)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ramon/kt-deepseek/lib/python3.12/site-packages/sglang/srt/model_executor/cuda_graph_runner.py", line 938, in capture_one_batch_size
run_once()
File "/home/ramon/kt-deepseek/lib/python3.12/site-packages/sglang/srt/model_executor/cuda_graph_runner.py", line 925, in run_once
logits_output_or_pp_proxy_tensors = forward(
^^^^^^^^
File "/home/ramon/kt-deepseek/lib/python3.12/site-packages/torch/utils/_contextlib.py", line 120, in decorate_context
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/home/ramon/kt-deepseek/lib/python3.12/site-packages/sglang/srt/models/deepseek_v4.py", line 1533, in forward
hidden_states = self.model.forward(
^^^^^^^^^^^^^^^^^^^
File "/home/ramon/kt-deepseek/lib/python3.12/site-packages/sglang/srt/models/deepseek_v4.py", line 1392, in forward
hidden_states = layer(
^^^^^^
File "/home/ramon/kt-deepseek/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1775, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ramon/kt-deepseek/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1786, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ramon/kt-deepseek/lib/python3.12/site-packages/sglang/srt/models/deepseek_v4.py", line 1219, in forward
hidden_states = self.mlp(
^^^^^^^^^
File "/home/ramon/kt-deepseek/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1775, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ramon/kt-deepseek/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1786, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ramon/kt-deepseek/lib/python3.12/site-packages/sglang/srt/models/deepseek_v2.py", line 688, in forward
return self.forward_normal(
^^^^^^^^^^^^^^^^^^^^
File "/home/ramon/kt-deepseek/lib/python3.12/site-packages/sglang/srt/models/deepseek_v2.py", line 806, in forward_normal
final_hidden_states = self.experts(
^^^^^^^^^^^^^
File "/home/ramon/kt-deepseek/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1775, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ramon/kt-deepseek/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1786, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ramon/kt-deepseek/lib/python3.12/site-packages/sglang/srt/layers/moe/fused_moe_triton/layer.py", line 998, in forward
return self.forward_impl(hidden_states, topk_output)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ramon/kt-deepseek/lib/python3.12/site-packages/sglang/srt/layers/moe/fused_moe_triton/layer.py", line 1017, in forward_impl
combine_input = self.run_moe_core(
^^^^^^^^^^^^^^^^^^
File "/home/ramon/kt-deepseek/lib/python3.12/site-packages/sglang/srt/layers/moe/fused_moe_triton/layer.py", line 1038, in run_moe_core
return self.quant_method.apply(
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ramon/kt-deepseek/lib/python3.12/site-packages/sglang/srt/layers/moe/kt_ep_wrapper.py", line 3112, in apply
gpu_combine_input = self.gpu_method.apply(layer, masked_dispatch_output)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ramon/kt-deepseek/lib/python3.12/site-packages/sglang/srt/layers/quantization/mxfp4_deepseek.py", line 594, in apply
output = trtllm_fp4_block_scale_routed_moe(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ramon/kt-deepseek/lib/python3.12/site-packages/flashinfer/api_logging.py", line 2333, in _auto_dump_wrapper
return _inner(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ramon/kt-deepseek/lib/python3.12/site-packages/flashinfer/fused_moe/core.py", line 4053, in trtllm_fp4_block_scale_routed_moe
return get_trtllm_moe_sm100_module().trtllm_fp4_block_scale_moe(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ramon/kt-deepseek/lib/python3.12/site-packages/flashinfer/fused_moe/core.py", line 2381, in trtllm_fp4_block_scale_moe_op
intermediate_output = moe_op.trtllm_fp4_block_scale_moe(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "python/tvm_ffi/cython/function.pxi", line 968, in tvm_ffi.core.Function.__call__
File "", line 0, in __tvm_ffi_trtllm_fp4_block_scale_moe
File "/home/ramon/kt-deepseek/lib/python3.12/site-packages/flashinfer/data/csrc/trtllm_fused_moe_kernel_launcher.cu", line 2423, in tvm::ffi::Array flashinfer::trtllm_fp4_block_scale_moe(int64_t, tvm::ffi::Optional, tvm::ffi::TensorView, tvm::ffi::TensorView, tvm::ffi::Optional, tvm::ffi::TensorView, tvm::ffi::Optional, tvm::ffi::TensorView, tvm::ffi::TensorView, tvm::ffi::Optional, tvm::ffi::Optional, tvm::ffi::Optional, tvm::ffi::Optional, tvm::ffi::TensorView, tvm::ffi::TensorView, tvm::ffi::Optional, tvm::ffi::Optional, tvm::ffi::Optional, tvm::ffi::Optional, tvm::ffi::Optional, int64_t, int64_t, tvm::ffi::Optional, tvm::ffi::Optional, int64_t, int64_t, int64_t, tvm::ffi::Optional, int64_t, bool, bool, int64_t, tvm::ffi::TensorView, tvm::ffi::Array, bool, tvm::ffi::Optional)
TVM_FFI_ICHECK(gemm1_weights_scale.numel() >= expected_unpadded)

tvm.error.InternalError: Check failed: (gemm1_weights_scale.numel() >= expected_unpadded) is false: weight scale tensor too small: numel=62914560 but expected at least 134217728 for sf_vec_size=32

```

Both flashinfer-cubin and flashinfer-python are in version 0.6.13.
Full log attached (see bellow)

### Reproduction

Attached is the full log of the run[ktransfomers_deepseekflash_run.log](https://github.com/user-attachments/files/30327006/ktransfomers_deepseekflash_run.log)

The command executed is
```text
python -m sglang.launch_server \
--host ::0 --port 30000 \
--model deepseek-ai/DeepSeek-V4-Flash \
--kt-weight-path ~/.cache/huggingface/hub/models--deepseek-ai--DeepSeek-V4-Flash \
--kt-method MXFP4 \
--kt-num-gpu-experts 120 \
--kt-cpuinfer 24 \
--kt-threadpool-count 1 \
--kt-gpu-prefill-token-threshold 4096 \
--kt-enable-dynamic-expert-update \
--tensor-parallel-size 1 \
--context-length 16384 \
--attention-backend flashinfer \
--mem-fraction-static 0.85 \
--chunked-prefill-size 2048 \
--max-prefill-tokens 2048 \
--max-running-requests 2 \
--watchdog-timeout 1200 \
--disable-shared-experts-fusion \
--trust-remote-code \
--cuda-graph-bs 1 \
--cuda-graph-max-bs 1 \
--disable-radix-cache \
--skip-server-warmup

```
(24 is the number of available cores)

### Others

_No response_

Contributor guide

Open the contributing guide

Research direction

Reproduce the supplied launch command and inspect the attached log first. Trace the call through sglang/srt/layers/quantization/mxfp4_deepseek.py, sglang/srt/layers/moe/kt_ep_wrapper.py, and fused_moe_triton/layer.py, then compare the weight-scale tensor with the reported expected size. Done means the DeepSeek-V4-Flash server no longer fails on the trtllm_fp4_block_scale_moe assertion.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
backend, machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.