kvcache-ai / kvcache-ai/ktransformers
[Bug] Using "--ep 4" with Kimi K2 Thinking on 4x Blackwell GPU causes the model to enter a repeat loop of outputting garbage
- Dominant language
- Python
- Stars
- 19.5k
- Forks
- 1.6k
- Avg merge
- 19h 32m
- Merged PRs (30d)
- 27
Description
### Checklist
- [x] 1. I have searched related issues but cannot get the expected help.
- [x] 2. The bug has not been fixed in the latest version.
- [x] 3. Please note that if the bug-related issue you submitted lacks corresponding environment info and a minimal reproducible demo, it will be challenging for us to reproduce and resolve the issue, reducing the likelihood of receiving feedback.
- [x] 4. If the issue you raised is not a bug but a question, please raise a discussion at https://github.com/kvcache-ai/ktransformers/discussions. Otherwise, it will be closed.
- [x] 5. To help the community, I will use Chinese/English or attach an Chinese/English translation if using another language. Non-Chinese/English content without translation may be closed.
### Describe the bug
Adding the flag `--ep 4` to the sglang/ktransformers command line causes the model to output garbage, such as "bbbbbbbbbbbbbbbbbbbbbbbb", ad infinitum.
### Reproduction
Load Kimi with sglang/kransformers and `--ep 4`:
```bash
$ CUDA_VISIBLE_DEVICES=0,1,2,3 python -m sglang.launch_server \
--host 0.0.0.0 \
--port 8080 \
--model moonshotai/Kimi-K2-Thinking \
--kt-amx-weight-path ~/.cache/huggingface/hub/models--KVCache-ai--Kimi-K2-Thinking-CPU-weight/snapshots/690ffacb9203d3b5e05ee8167ff1f5d4ae027c83/ \
--kt-cpuinfer 252 \
--kt-threadpool-count 2 \
--kt-num-gpu-experts 32 \
--kt-amx-method AMXINT4 \
--trust-remote-code \
--mem-fraction-static 0.985 \
--max-running-requests 1 \
--max-total-tokens 32768 \
--enable-p2p-check \
--served-model-name kimi \
--attention-backend flashinfer \
--tp 4 \
--ep 4
```
Then use the `qq` tool to send a `say hello` prompt to Kimi:
```bash
$ qq -srn say hello
assistant apt user apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt apt^C
```
When loaded with out `--ep 4` the response works as expected:
```bash
$ qq -srn say hello
The user is asking me to "say hello". This is a very simple request. According to my instructions, I should help users with command-line, programming, system administration, and technical computing tasks.
...
```
### Environment
### Server details
- Linux Ubuntu
- AMD EPYC 9755 CPU
- 768GB system RAM
- 4x RTX 6000 PRO Workstation GPUs
- Nvidia drivers 580.95.05
- CUDA 13.0
- Python 3.11 with uv 0.7.20
### Software setup
```bash
# setup virtual python environment
cd
mkdir ktransformers-sglang; cd ktransformers-sglang
uv venv --python 3.11 --seed
. .venv/bin/activate
# install sglang
uv pip install "sglang" --prerelease=allow
# download and initialize ktransformers repo
git clone https://github.com/kvcache-ai/ktransformers
git submodule update --init --recursive
# Install ktransformers CPU kernel for sglang
cd kt-kernel
export CPUINFER_CPU_INSTRUCT=AVX512
export CPUINFER_ENABLE_AMX=OFF
uv pip install .
cd ..
# download Kimi K2 Thinking GPU & CPU parts
uv pip install -U hf hf_transfer
hf download moonshotai/Kimi-K2-Thinking
hf download KVCache-ai/Kimi-K2-Thinking-CPU-weight
```
Contributor guide
Research direction
Start by running the provided sglang.launch_server command on the four-GPU environment, first with --ep 4 and then without it, and compare the responses to the `say hello` prompt. Trace the --ep 4 execution path and validate the fix by confirming normal output with expert parallelism while preserving the existing behavior without that flag.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- ai-infra-agents
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100