[GH-ISSUE #1074] balance_serve loses cache between prompts #756

Closed
opened 2026-10-29 14:44:01 +00:00 by bsakaguchi · 12 comments
Owner

Originally created by @createthis on GitHub (Apr 7, 2025).
Original GitHub issue: https://github.com/kvcache-ai/ktransformers/issues/1074

Maybe this is by design, but I've noticed the ktransformers backend does not have any delay in responding after a huge prompt. However, the balance_serve backend has a long delay in responding after a huge prompt.

Here's the test case I ran to prove this:

Evaluating ktransformers backends as they pertain to context length and kv cache.
ktransformers

added prompt 0, waited for Title and Tag responses from Open WebUI before continuing so the cache is uninterrupted
18:47:56 added prompt 1 - 12116 tokens
18:50:09 started responding
18:50:36 response complete (2 minutes 40 seconds)
18:51:12 added prompt 2 - 154 tokens
18:51:15 ** immediate response **
18:51:52 response complete - probably 13406 tokens total (it doesn't say total tokens so I'm doing math - 40 seconds)
total elapsed time - 3 minutes 20 seconds
balance_serve

added prompt 0, waited for Title and Tag responses from Open WebUI before continuing so the cache is uninterrupted
19:04:16 added prompt 1 - 12116 tokens
19:06:?? started responding (nothing in the log)
19:06:28 response complete (2 minutes 12 seconds - faster than ktransformers backend - shorter response I think)
19:07:07 added prompt 2 - 154 tokens
19:08:?? started responding (after more than a minute wait! - nothing in the log)
19:09:35 response complete - 13227 tokens total (2 minutes 28 seconds - way slower than ktransformers backend)
total elapsed time - 4 minutes 40 seconds

Is this a bug, or is it just a consequence of multi-concurrency?

Originally created by @createthis on GitHub (Apr 7, 2025). Original GitHub issue: https://github.com/kvcache-ai/ktransformers/issues/1074 Maybe this is by design, but I've noticed the `ktransformers` backend does not have any delay in responding after a huge prompt. However, the `balance_serve` backend has a long delay in responding after a huge prompt. Here's the test case I ran to prove this: ``` Evaluating ktransformers backends as they pertain to context length and kv cache. ktransformers added prompt 0, waited for Title and Tag responses from Open WebUI before continuing so the cache is uninterrupted 18:47:56 added prompt 1 - 12116 tokens 18:50:09 started responding 18:50:36 response complete (2 minutes 40 seconds) 18:51:12 added prompt 2 - 154 tokens 18:51:15 ** immediate response ** 18:51:52 response complete - probably 13406 tokens total (it doesn't say total tokens so I'm doing math - 40 seconds) total elapsed time - 3 minutes 20 seconds ``` ``` balance_serve added prompt 0, waited for Title and Tag responses from Open WebUI before continuing so the cache is uninterrupted 19:04:16 added prompt 1 - 12116 tokens 19:06:?? started responding (nothing in the log) 19:06:28 response complete (2 minutes 12 seconds - faster than ktransformers backend - shorter response I think) 19:07:07 added prompt 2 - 154 tokens 19:08:?? started responding (after more than a minute wait! - nothing in the log) 19:09:35 response complete - 13227 tokens total (2 minutes 28 seconds - way slower than ktransformers backend) total elapsed time - 4 minutes 40 seconds ``` Is this a bug, or is it just a consequence of multi-concurrency?
Author
Owner

@qiyuxinlin commented on GitHub (Apr 8, 2025):

Hi @createthis, could you please post the model execution times printed in the terminal before and after the error occurred?

<!-- gh-comment-id:2785160884 --> @qiyuxinlin commented on GitHub (Apr 8, 2025): Hi @createthis, could you please post the model execution times printed in the terminal before and after the error occurred?
Author
Owner

@magikRUKKOLA commented on GitHub (Apr 8, 2025):

Please post the commands how you running the inference in both cases. This is becoming interesting.

<!-- gh-comment-id:2785258438 --> @magikRUKKOLA commented on GitHub (Apr 8, 2025): Please post the commands how you running the inference in both cases. This is becoming interesting.
Author
Owner

@createthis commented on GitHub (Apr 8, 2025):

@magikRUKKOLA here you go:

python ktransformers/server/main.py \
  --port 11434 \
  --model_path /data/DeepSeek-V3 \
  --model_name "DeepSeek-V3-0324:671b-q4_k_m" \
  --gguf_path /data/DeepSeek-V3-0324/q4_files/Q4_K_M \
  --optimize_config_path ktransformers/optimize/optimize_rules/DeepSeek-V3-Chat-serve.yaml \
  --max_new_tokens 1024 \
  --cache_lens 131072 \
  --chunk_size 256 \
  --max_batch_size 4 \
  --temperature 0.3 \
  --backend_type balance_serve
python ktransformers/server/main.py \
  --port 11434 \
  --model_path /data/DeepSeek-V3 \
  --model_name "DeepSeek-V3-0324:671b-q4_k_m" \
  --gguf_path /data/DeepSeek-V3-0324/q4_files/Q4_K_M \
  --temperature 0.3 \
  --cpu_infer 30 \
  --max_new_tokens 1024 \
  --cache_lens 131072 \
  --chunk_size 256 \
  --backend_type ktransformers

@qiyuxinlin there's no error. I think I'd need to record a video to get the logs. There's a lot of them and I'm bound to mix them up.

<!-- gh-comment-id:2786400645 --> @createthis commented on GitHub (Apr 8, 2025): @magikRUKKOLA here you go: ```bash python ktransformers/server/main.py \ --port 11434 \ --model_path /data/DeepSeek-V3 \ --model_name "DeepSeek-V3-0324:671b-q4_k_m" \ --gguf_path /data/DeepSeek-V3-0324/q4_files/Q4_K_M \ --optimize_config_path ktransformers/optimize/optimize_rules/DeepSeek-V3-Chat-serve.yaml \ --max_new_tokens 1024 \ --cache_lens 131072 \ --chunk_size 256 \ --max_batch_size 4 \ --temperature 0.3 \ --backend_type balance_serve ``` ```bash python ktransformers/server/main.py \ --port 11434 \ --model_path /data/DeepSeek-V3 \ --model_name "DeepSeek-V3-0324:671b-q4_k_m" \ --gguf_path /data/DeepSeek-V3-0324/q4_files/Q4_K_M \ --temperature 0.3 \ --cpu_infer 30 \ --max_new_tokens 1024 \ --cache_lens 131072 \ --chunk_size 256 \ --backend_type ktransformers ``` @qiyuxinlin there's no error. I think I'd need to record a video to get the logs. There's a lot of them and I'm bound to mix them up.
Author
Owner

@magikRUKKOLA commented on GitHub (Apr 8, 2025):

@qiyuxinlin

@createthis Yes, I am having the same behaviour with

ktransformers \
  --gguf_path /opt/unsloth/DeepSeek-V3-0324-GGUF/UD-Q4_K_XL/DeepSeek-V3/DeepSeek-V3-0324-UD-Q4_K_XL-00001-of-00009.gguf \
  --model_path /opt/unsloth/DeepSeek-V3-0324-GGUF/UD-Q4_K_XL/DeepSeek-V3/ \
  --model_name unsloth/DeepSeek-V3-0324-GGUF \
  --cpu_infer $(grep ^cpu\\scores /proc/cpuinfo | uniq | awk '{print $4}' | xargs -I{} echo "{}-0" | bc) \
  --cache_lens 131072 \
  --chunk_size 256 \
  --max_new_tokens 32768 \
  --max_batch_size 4 \
  --cache_8bit True \
  --cache_q4 False \
  --temperature 0.6 \
  --top_p 0.95 \
  --optimize_config_path /opt/ktransformers/ktransformers/ktransformers/optimize/optimize_rules/DeepSeek-V3-Chat-serve.yaml \
  --use_cuda_graph \
  --host 0.0.0.0 \
  --port 8080 \
  --fast_safetensors True \
  --backend_type balance_serve \
  --log_level DEBUG

log of two requests to the same session (via the mods --continue):


Apr 08 14:46:44 llm1 run-ktransformers.sh[5249]: INFO:     127.0.0.1:42534 - "POST /v1/chat/completions HTTP/1.1" 200 OK
Apr 08 14:46:45 llm1 run-ktransformers.sh[5249]: 2025-04-08 14:46:45,017 DEBUG /opt/ktransformers/.ktransformers/lib/python3.12/site-package
s/ktransformers/server/backend/interfaces/balance_serve.py[335]: get input ids of shape torch.Size([1, 7768])

Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: prefill length: 52, prefill time: 1.85536789894104, prefill tps 28.02678650939215, decode length: 766, decode time: 102.70727777481079, decode tps 7.458088818978156
Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: 5
Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: decode_batch_i: 1,
Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: Model execution time (GPU): 129.308 ms
Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: 223
Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: decode_batch_i: 1,
Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: Model execution time (GPU): 128.778 ms
Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: 21
Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: add query id: 23, batch.query_lengths: 7768, batch_query_tokens: torch.Size([40536]), batch
.block_indexes: tensor([  0,   1,   2,   3,   4,   5,   6,   7,   8,   9,  10,  11,  12,  13,
Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]:          14,  15,  16,  17,  18,  19,  20,  21,  22,  23,  24,  25,  26,  27,
Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]:          28,  29,  30,  31,  32,  33,  34,  35,  36,  37,  38,  39,  40,  41,
Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]:          42,  43,  44,  45,  46,  47,  48,  49,  50,  51,  52,  53,  54,  55,
Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]:          56,  57,  58,  59,  60,  61,  62,  63,  64,  65,  66,  67,  68,  69,
Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]:          70,  71,  72,  73,  74,  75,  76,  77,  78,  79,  80,  81,  82,  83,
Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]:          84,  85,  86,  87,  88,  89,  90,  91,  92,  93,  94,  95,  96,  97,
Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]:          98,  99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]:         112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125,
Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]:         126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139,
Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]:         140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153,
Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]:         154, 155, 156, 157, 158], dtype=torch.int32)


Apr 08 14:56:34 llm1 run-ktransformers.sh[5249]: 2025-04-08 14:56:34,647 INFO /opt/ktransformers/.ktransformers/lib/python3.12/site-packages
/ktransformers/server/backend/interfaces/balance_serve.py[90]: Performance(T/s): prefill 57.26238385180121, decode 7.372676400422852. Time(s
): tokenize 0.12717437744140625, prefill 135.656245470047, decode 453.973539352417
Apr 08 14:57:00 llm1 run-ktransformers.sh[5249]: INFO:     127.0.0.1:51766 - "POST /v1/chat/completions HTTP/1.1" 200 OK
Apr 08 14:57:01 llm1 run-ktransformers.sh[5249]: 2025-04-08 14:57:01,077 DEBUG /opt/ktransformers/.ktransformers/lib/python3.12/site-packages/ktransformers/server/backend/interfaces/balance_serve.py[335]: get input ids of shape torch.Size([1, 11134])
Apr 08 15:00:29 llm1 run-ktransformers.sh[5377]: 2645
Apr 08 15:00:29 llm1 run-ktransformers.sh[5377]: decode_batch_i: 1,
Apr 08 15:00:29 llm1 run-ktransformers.sh[5377]: Model execution time (GPU): 135.434 ms

EDIT:

uv pip list | grep cu
Using Python 3.12.8 environment at: /opt/ktransformers/.ktransformers
ktransformers            0.2.4.post1+cu128torch28avx2
nvidia-cublas-cu12       12.8.3.14
nvidia-cuda-cupti-cu12   12.8.57
nvidia-cuda-nvrtc-cu12   12.8.61
nvidia-cuda-runtime-cu12 12.8.57
nvidia-cudnn-cu12        9.8.0.87
nvidia-cufft-cu12        11.3.3.41
nvidia-cufile-cu12       1.13.0.11
nvidia-curand-cu12       10.3.9.55
nvidia-cusolver-cu12     11.7.2.55
nvidia-cusparse-cu12     12.5.7.53
nvidia-cusparselt-cu12   0.6.3
nvidia-nccl-cu12         2.26.2
nvidia-nvjitlink-cu12    12.8.61
nvidia-nvtx-cu12         12.8.55
torch                    2.8.0.dev20250407+cu128
torchaudio               2.6.0.dev20250407+cu128
torchvision              0.22.0.dev20250407+cu128

uv pip list | grep flash
Using Python 3.12.8 environment at: /opt/ktransformers/.ktransformers
flash-attn               2.7.4.post1
flashinfer-python        0.2.3
<!-- gh-comment-id:2786785812 --> @magikRUKKOLA commented on GitHub (Apr 8, 2025): @qiyuxinlin @createthis Yes, I am having the same behaviour with ```bash ktransformers \ --gguf_path /opt/unsloth/DeepSeek-V3-0324-GGUF/UD-Q4_K_XL/DeepSeek-V3/DeepSeek-V3-0324-UD-Q4_K_XL-00001-of-00009.gguf \ --model_path /opt/unsloth/DeepSeek-V3-0324-GGUF/UD-Q4_K_XL/DeepSeek-V3/ \ --model_name unsloth/DeepSeek-V3-0324-GGUF \ --cpu_infer $(grep ^cpu\\scores /proc/cpuinfo | uniq | awk '{print $4}' | xargs -I{} echo "{}-0" | bc) \ --cache_lens 131072 \ --chunk_size 256 \ --max_new_tokens 32768 \ --max_batch_size 4 \ --cache_8bit True \ --cache_q4 False \ --temperature 0.6 \ --top_p 0.95 \ --optimize_config_path /opt/ktransformers/ktransformers/ktransformers/optimize/optimize_rules/DeepSeek-V3-Chat-serve.yaml \ --use_cuda_graph \ --host 0.0.0.0 \ --port 8080 \ --fast_safetensors True \ --backend_type balance_serve \ --log_level DEBUG ``` log of two requests to the same session (via the mods --continue): ```text Apr 08 14:46:44 llm1 run-ktransformers.sh[5249]: INFO: 127.0.0.1:42534 - "POST /v1/chat/completions HTTP/1.1" 200 OK Apr 08 14:46:45 llm1 run-ktransformers.sh[5249]: 2025-04-08 14:46:45,017 DEBUG /opt/ktransformers/.ktransformers/lib/python3.12/site-package s/ktransformers/server/backend/interfaces/balance_serve.py[335]: get input ids of shape torch.Size([1, 7768]) Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: prefill length: 52, prefill time: 1.85536789894104, prefill tps 28.02678650939215, decode length: 766, decode time: 102.70727777481079, decode tps 7.458088818978156 Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: 5 Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: decode_batch_i: 1, Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: Model execution time (GPU): 129.308 ms Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: 223 Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: decode_batch_i: 1, Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: Model execution time (GPU): 128.778 ms Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: 21 Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: add query id: 23, batch.query_lengths: 7768, batch_query_tokens: torch.Size([40536]), batch .block_indexes: tensor([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: 154, 155, 156, 157, 158], dtype=torch.int32) Apr 08 14:56:34 llm1 run-ktransformers.sh[5249]: 2025-04-08 14:56:34,647 INFO /opt/ktransformers/.ktransformers/lib/python3.12/site-packages /ktransformers/server/backend/interfaces/balance_serve.py[90]: Performance(T/s): prefill 57.26238385180121, decode 7.372676400422852. Time(s ): tokenize 0.12717437744140625, prefill 135.656245470047, decode 453.973539352417 Apr 08 14:57:00 llm1 run-ktransformers.sh[5249]: INFO: 127.0.0.1:51766 - "POST /v1/chat/completions HTTP/1.1" 200 OK Apr 08 14:57:01 llm1 run-ktransformers.sh[5249]: 2025-04-08 14:57:01,077 DEBUG /opt/ktransformers/.ktransformers/lib/python3.12/site-packages/ktransformers/server/backend/interfaces/balance_serve.py[335]: get input ids of shape torch.Size([1, 11134]) Apr 08 15:00:29 llm1 run-ktransformers.sh[5377]: 2645 Apr 08 15:00:29 llm1 run-ktransformers.sh[5377]: decode_batch_i: 1, Apr 08 15:00:29 llm1 run-ktransformers.sh[5377]: Model execution time (GPU): 135.434 ms ``` EDIT: ```text uv pip list | grep cu Using Python 3.12.8 environment at: /opt/ktransformers/.ktransformers ktransformers 0.2.4.post1+cu128torch28avx2 nvidia-cublas-cu12 12.8.3.14 nvidia-cuda-cupti-cu12 12.8.57 nvidia-cuda-nvrtc-cu12 12.8.61 nvidia-cuda-runtime-cu12 12.8.57 nvidia-cudnn-cu12 9.8.0.87 nvidia-cufft-cu12 11.3.3.41 nvidia-cufile-cu12 1.13.0.11 nvidia-curand-cu12 10.3.9.55 nvidia-cusolver-cu12 11.7.2.55 nvidia-cusparse-cu12 12.5.7.53 nvidia-cusparselt-cu12 0.6.3 nvidia-nccl-cu12 2.26.2 nvidia-nvjitlink-cu12 12.8.61 nvidia-nvtx-cu12 12.8.55 torch 2.8.0.dev20250407+cu128 torchaudio 2.6.0.dev20250407+cu128 torchvision 0.22.0.dev20250407+cu128 uv pip list | grep flash Using Python 3.12.8 environment at: /opt/ktransformers/.ktransformers flash-attn 2.7.4.post1 flashinfer-python 0.2.3 ```
Author
Owner

@qiyuxinlin commented on GitHub (Apr 8, 2025):

@qiyuxinlin

@createthis Yes, I am having the same behaviour with是的,我也有同样的行为

ktransformers
--gguf_path /opt/unsloth/DeepSeek-V3-0324-GGUF/UD-Q4_K_XL/DeepSeek-V3/DeepSeek-V3-0324-UD-Q4_K_XL-00001-of-00009.gguf
--model_path /opt/unsloth/DeepSeek-V3-0324-GGUF/UD-Q4_K_XL/DeepSeek-V3/
--model_name unsloth/DeepSeek-V3-0324-GGUF
--cpu_infer $(grep ^cpu\scores /proc/cpuinfo | uniq | awk '{print $4}' | xargs -I{} echo "{}-0" | bc)
--cache_lens 131072
--chunk_size 256
--max_new_tokens 32768
--max_batch_size 4
--cache_8bit True
--cache_q4 False
--temperature 0.6
--top_p 0.95
--optimize_config_path /opt/ktransformers/ktransformers/ktransformers/optimize/optimize_rules/DeepSeek-V3-Chat-serve.yaml
--use_cuda_graph
--host 0.0.0.0
--port 8080
--fast_safetensors True
--backend_type balance_serve
--log_level DEBUG
log of two requests to the same session (via the mods --continue):将两个请求记录到同一会话(通过 mods --continue):


Apr 08 14:46:44 llm1 run-ktransformers.sh[5249]: INFO:     127.0.0.1:42534 - "POST /v1/chat/completions HTTP/1.1" 200 OK
Apr 08 14:46:45 llm1 run-ktransformers.sh[5249]: 2025-04-08 14:46:45,017 DEBUG /opt/ktransformers/.ktransformers/lib/python3.12/site-package
s/ktransformers/server/backend/interfaces/balance_serve.py[335]: get input ids of shape torch.Size([1, 7768])

Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: prefill length: 52, prefill time: 1.85536789894104, prefill tps 28.02678650939215, decode length: 766, decode time: 102.70727777481079, decode tps 7.458088818978156
Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: 5
Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: decode_batch_i: 1,
Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: Model execution time (GPU): 129.308 ms
Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: 223
Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: decode_batch_i: 1,
Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: Model execution time (GPU): 128.778 ms
Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: 21
Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: add query id: 23, batch.query_lengths: 7768, batch_query_tokens: torch.Size([40536]), batch
.block_indexes: tensor([  0,   1,   2,   3,   4,   5,   6,   7,   8,   9,  10,  11,  12,  13,
Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]:          14,  15,  16,  17,  18,  19,  20,  21,  22,  23,  24,  25,  26,  27,
Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]:          28,  29,  30,  31,  32,  33,  34,  35,  36,  37,  38,  39,  40,  41,
Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]:          42,  43,  44,  45,  46,  47,  48,  49,  50,  51,  52,  53,  54,  55,
Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]:          56,  57,  58,  59,  60,  61,  62,  63,  64,  65,  66,  67,  68,  69,
Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]:          70,  71,  72,  73,  74,  75,  76,  77,  78,  79,  80,  81,  82,  83,
Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]:          84,  85,  86,  87,  88,  89,  90,  91,  92,  93,  94,  95,  96,  97,
Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]:          98,  99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]:         112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125,
Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]:         126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139,
Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]:         140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153,
Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]:         154, 155, 156, 157, 158], dtype=torch.int32)


Apr 08 14:56:34 llm1 run-ktransformers.sh[5249]: 2025-04-08 14:56:34,647 INFO /opt/ktransformers/.ktransformers/lib/python3.12/site-packages
/ktransformers/server/backend/interfaces/balance_serve.py[90]: Performance(T/s): prefill 57.26238385180121, decode 7.372676400422852. Time(s
): tokenize 0.12717437744140625, prefill 135.656245470047, decode 453.973539352417
Apr 08 14:57:00 llm1 run-ktransformers.sh[5249]: INFO:     127.0.0.1:51766 - "POST /v1/chat/completions HTTP/1.1" 200 OK
Apr 08 14:57:01 llm1 run-ktransformers.sh[5249]: 2025-04-08 14:57:01,077 DEBUG /opt/ktransformers/.ktransformers/lib/python3.12/site-packages/ktransformers/server/backend/interfaces/balance_serve.py[335]: get input ids of shape torch.Size([1, 11134])
Apr 08 15:00:29 llm1 run-ktransformers.sh[5377]: 2645
Apr 08 15:00:29 llm1 run-ktransformers.sh[5377]: decode_batch_i: 1,
Apr 08 15:00:29 llm1 run-ktransformers.sh[5377]: Model execution time (GPU): 135.434 ms

EDIT:  编辑:

uv pip list | grep cu
Using Python 3.12.8 environment at: /opt/ktransformers/.ktransformers
ktransformers            0.2.4.post1+cu128torch28avx2
nvidia-cublas-cu12       12.8.3.14
nvidia-cuda-cupti-cu12   12.8.57
nvidia-cuda-nvrtc-cu12   12.8.61
nvidia-cuda-runtime-cu12 12.8.57
nvidia-cudnn-cu12        9.8.0.87
nvidia-cufft-cu12        11.3.3.41
nvidia-cufile-cu12       1.13.0.11
nvidia-curand-cu12       10.3.9.55
nvidia-cusolver-cu12     11.7.2.55
nvidia-cusparse-cu12     12.5.7.53
nvidia-cusparselt-cu12   0.6.3
nvidia-nccl-cu12         2.26.2
nvidia-nvjitlink-cu12    12.8.61
nvidia-nvtx-cu12         12.8.55
torch                    2.8.0.dev20250407+cu128
torchaudio               2.6.0.dev20250407+cu128
torchvision              0.22.0.dev20250407+cu128

uv pip list | grep flash
Using Python 3.12.8 environment at: /opt/ktransformers/.ktransformers
flash-attn               2.7.4.post1
flashinfer-python        0.2.3

容我理解下,您是想问一个 prefill 进入队列后会影响前一个任务的 decode 速率吗?

<!-- gh-comment-id:2786867487 --> @qiyuxinlin commented on GitHub (Apr 8, 2025): > [@qiyuxinlin](https://github.com/qiyuxinlin) > > [@createthis](https://github.com/createthis) Yes, I am having the same behaviour with是的,我也有同样的行为 > > ktransformers \ > --gguf_path /opt/unsloth/DeepSeek-V3-0324-GGUF/UD-Q4_K_XL/DeepSeek-V3/DeepSeek-V3-0324-UD-Q4_K_XL-00001-of-00009.gguf \ > --model_path /opt/unsloth/DeepSeek-V3-0324-GGUF/UD-Q4_K_XL/DeepSeek-V3/ \ > --model_name unsloth/DeepSeek-V3-0324-GGUF \ > --cpu_infer $(grep ^cpu\\scores /proc/cpuinfo | uniq | awk '{print $4}' | xargs -I{} echo "{}-0" | bc) \ > --cache_lens 131072 \ > --chunk_size 256 \ > --max_new_tokens 32768 \ > --max_batch_size 4 \ > --cache_8bit True \ > --cache_q4 False \ > --temperature 0.6 \ > --top_p 0.95 \ > --optimize_config_path /opt/ktransformers/ktransformers/ktransformers/optimize/optimize_rules/DeepSeek-V3-Chat-serve.yaml \ > --use_cuda_graph \ > --host 0.0.0.0 \ > --port 8080 \ > --fast_safetensors True \ > --backend_type balance_serve \ > --log_level DEBUG > log of two requests to the same session (via the mods --continue):将两个请求记录到同一会话(通过 mods --continue): > > ``` > > Apr 08 14:46:44 llm1 run-ktransformers.sh[5249]: INFO: 127.0.0.1:42534 - "POST /v1/chat/completions HTTP/1.1" 200 OK > Apr 08 14:46:45 llm1 run-ktransformers.sh[5249]: 2025-04-08 14:46:45,017 DEBUG /opt/ktransformers/.ktransformers/lib/python3.12/site-package > s/ktransformers/server/backend/interfaces/balance_serve.py[335]: get input ids of shape torch.Size([1, 7768]) > > Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: prefill length: 52, prefill time: 1.85536789894104, prefill tps 28.02678650939215, decode length: 766, decode time: 102.70727777481079, decode tps 7.458088818978156 > Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: 5 > Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: decode_batch_i: 1, > Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: Model execution time (GPU): 129.308 ms > Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: 223 > Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: decode_batch_i: 1, > Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: Model execution time (GPU): 128.778 ms > Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: 21 > Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: add query id: 23, batch.query_lengths: 7768, batch_query_tokens: torch.Size([40536]), batch > .block_indexes: tensor([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, > Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, > Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, > Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, > Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, > Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, > Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, > Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, > Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, > Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, > Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, > Apr 08 14:49:08 llm1 run-ktransformers.sh[5377]: 154, 155, 156, 157, 158], dtype=torch.int32) > > > Apr 08 14:56:34 llm1 run-ktransformers.sh[5249]: 2025-04-08 14:56:34,647 INFO /opt/ktransformers/.ktransformers/lib/python3.12/site-packages > /ktransformers/server/backend/interfaces/balance_serve.py[90]: Performance(T/s): prefill 57.26238385180121, decode 7.372676400422852. Time(s > ): tokenize 0.12717437744140625, prefill 135.656245470047, decode 453.973539352417 > Apr 08 14:57:00 llm1 run-ktransformers.sh[5249]: INFO: 127.0.0.1:51766 - "POST /v1/chat/completions HTTP/1.1" 200 OK > Apr 08 14:57:01 llm1 run-ktransformers.sh[5249]: 2025-04-08 14:57:01,077 DEBUG /opt/ktransformers/.ktransformers/lib/python3.12/site-packages/ktransformers/server/backend/interfaces/balance_serve.py[335]: get input ids of shape torch.Size([1, 11134]) > Apr 08 15:00:29 llm1 run-ktransformers.sh[5377]: 2645 > Apr 08 15:00:29 llm1 run-ktransformers.sh[5377]: decode_batch_i: 1, > Apr 08 15:00:29 llm1 run-ktransformers.sh[5377]: Model execution time (GPU): 135.434 ms > ``` > > EDIT:  编辑: > > ``` > uv pip list | grep cu > Using Python 3.12.8 environment at: /opt/ktransformers/.ktransformers > ktransformers 0.2.4.post1+cu128torch28avx2 > nvidia-cublas-cu12 12.8.3.14 > nvidia-cuda-cupti-cu12 12.8.57 > nvidia-cuda-nvrtc-cu12 12.8.61 > nvidia-cuda-runtime-cu12 12.8.57 > nvidia-cudnn-cu12 9.8.0.87 > nvidia-cufft-cu12 11.3.3.41 > nvidia-cufile-cu12 1.13.0.11 > nvidia-curand-cu12 10.3.9.55 > nvidia-cusolver-cu12 11.7.2.55 > nvidia-cusparse-cu12 12.5.7.53 > nvidia-cusparselt-cu12 0.6.3 > nvidia-nccl-cu12 2.26.2 > nvidia-nvjitlink-cu12 12.8.61 > nvidia-nvtx-cu12 12.8.55 > torch 2.8.0.dev20250407+cu128 > torchaudio 2.6.0.dev20250407+cu128 > torchvision 0.22.0.dev20250407+cu128 > > uv pip list | grep flash > Using Python 3.12.8 environment at: /opt/ktransformers/.ktransformers > flash-attn 2.7.4.post1 > flashinfer-python 0.2.3 > ``` 容我理解下,您是想问一个 prefill 进入队列后会影响前一个任务的 decode 速率吗?
Author
Owner

@magikRUKKOLA commented on GitHub (Apr 8, 2025):

容我理解下,您是想问一个 prefill 进入队列后会影响前一个任务的 decode 速率吗?

Well, basically we are asking to clarify how the caching mechanism of a KV-cache pertained to a certain task/session is handled in a different backends. In case with a large context (in terms of tokens that have to be prefilled to get a certain context to continue the task/session/conversation) the behaviour of a ktransformers is different. Specifically, in the original ktransformers backend, it was possible to ask model a question and within a short term (like 30 sec or one minute) submit the next question and the time for a first token was minimal (pointing to some caching mechanisms to pull it out). So unfortunately, in the recent balance_serve backend no such behaviour can be seen -- it just skips some "cache" and starting all over (like having some kind of stateless behaviour). The question is -- is it possible for example to save such cache pertaining to the unique conversation somewhere in order just to preload it? For example, RTX series videocards have P2P capabilities (pcie master etc.) so if more than one GPU is presend it might be possible to save such caches and just switch between several GPUs in case if the subsequent request from the user to continue the session had been made (of course its not always the case, but often enough).

Please point to the right direction to enable or implement it.

<!-- gh-comment-id:2786956335 --> @magikRUKKOLA commented on GitHub (Apr 8, 2025): > 容我理解下,您是想问一个 prefill 进入队列后会影响前一个任务的 decode 速率吗? Well, basically we are asking to clarify how the caching mechanism of a KV-cache pertained to a certain task/session is handled in a different backends. In case with a large context (in terms of tokens that have to be prefilled to get a certain context to continue the task/session/conversation) the behaviour of a ktransformers is different. Specifically, in the original ktransformers backend, it was possible to ask model a question and within a short term (like 30 sec or one minute) submit the next question and the time for a first token was minimal (pointing to some caching mechanisms to pull it out). So unfortunately, in the recent balance_serve backend no such behaviour can be seen -- it just skips some "cache" and starting all over (like having some kind of stateless behaviour). The question is -- is it possible for example to save such cache pertaining to the unique conversation somewhere in order just to preload it? For example, RTX series videocards have P2P capabilities (pcie master etc.) so if more than one GPU is presend it might be possible to save such caches and just switch between several GPUs in case if the subsequent request from the user to continue the session had been made (of course its not always the case, but often enough). Please point to the right direction to enable or implement it.
Author
Owner

@magikRUKKOLA commented on GitHub (Apr 8, 2025):

@qiyuxinlin just to make sure what we are talking about does make sense.
Consider any chat-like app with a bunch of chats for a single user. Be it mods or openhands ai or chatbox ai or whatever. The requirement here is to use Chain of Thought in the llm inference. That is, get the response, process it by other LLMs or just a reanimation of the previous conversation/session. With a prefill speed of 100 tps it would take a lot of time to process ... close to three minutes with 16k context?! ... this doesn't make sense. I would strongly advise you to look towards the export of the caches to revive the sessions. It is much cheaper to store the cache on some storage device (close to 10GB/s possible with raid0). It would be nice to have some SDK/API to get the current state and save/restore it.

Right?

<!-- gh-comment-id:2787729138 --> @magikRUKKOLA commented on GitHub (Apr 8, 2025): @qiyuxinlin just to make sure what we are talking about does make sense. Consider any chat-like app with a bunch of chats for a single user. Be it [mods](https://github.com/charmbracelet/mods?tab=readme-ov-file#saved-conversations) or [openhands ai](https://github.com/All-Hands-AI/OpenHands/) or chatbox ai or whatever. The requirement here is to use Chain of Thought in the llm inference. That is, get the response, process it by other LLMs or just a reanimation of the previous conversation/session. With a prefill speed of 100 tps it would take a lot of time to process ... close to three minutes with 16k context?! ... this doesn't make sense. I would strongly advise you to look towards the export of the caches to revive the sessions. It is much cheaper to store the cache on some storage device (close to 10GB/s possible with raid0). It would be nice to have some SDK/API to get the current state and save/restore it. Right?
Author
Owner

@magikRUKKOLA commented on GitHub (Apr 9, 2025):

@qiyuxinlin

is that it?

github.com/kvcache-ai/ktransformers@94476ce5cc/csrc/balance_serve/kvc2/src/gpu_cache.cpp (L32)

<!-- gh-comment-id:2788076695 --> @magikRUKKOLA commented on GitHub (Apr 9, 2025): @qiyuxinlin is that it? https://github.com/kvcache-ai/ktransformers/blob/94476ce5cc0f97ec244729a5c70b509bedec4732/csrc/balance_serve/kvc2/src/gpu_cache.cpp#L32
Author
Owner

@qiyuxinlin commented on GitHub (Apr 9, 2025):

Hi @createthis and @magikRUKKOLA, Currently balance_serve does not support prefix cache. We plan to improve this feature in the next few versions.

<!-- gh-comment-id:2788095929 --> @qiyuxinlin commented on GitHub (Apr 9, 2025): Hi @createthis and @magikRUKKOLA, Currently balance_serve does not support prefix cache. We plan to improve this feature in the next few versions.
Author
Owner

@magikRUKKOLA commented on GitHub (Apr 9, 2025):

Hi @createthis and @magikRUKKOLA, Currently balance_serve does not support prefix cache. We plan to improve this feature in the next few versions.

what about the dumps ?
github.com/kvcache-ai/ktransformers@94476ce5cc/ktransformers/server/balance_serve/settings.py (L52)

got any docs?

<!-- gh-comment-id:2788108154 --> @magikRUKKOLA commented on GitHub (Apr 9, 2025): > Hi [@createthis](https://github.com/createthis) and [@magikRUKKOLA](https://github.com/magikRUKKOLA), Currently balance_serve does not support prefix cache. We plan to improve this feature in the next few versions. what about the dumps ? https://github.com/kvcache-ai/ktransformers/blob/94476ce5cc0f97ec244729a5c70b509bedec4732/ktransformers/server/balance_serve/settings.py#L52 got any docs?
Author
Owner

@magikRUKKOLA commented on GitHub (Apr 9, 2025):

@qiyuxinlin
is it possible to run multiple instances of ktransformers with different backends (ktransformer, balance_serve) on a separate GPUs (the regions of RAM with the weights of the model are handled via the OS mappings, right? so because the data is static, the same physical mapping can be used by multiple processes, huh?)

<!-- gh-comment-id:2788111571 --> @magikRUKKOLA commented on GitHub (Apr 9, 2025): @qiyuxinlin is it possible to run multiple instances of ktransformers with different backends (ktransformer, balance_serve) on a separate GPUs (the regions of RAM with the weights of the model are handled via the OS mappings, right? so because the data is static, the same physical mapping can be used by multiple processes, huh?)
Author
Owner

@createthis commented on GitHub (Apr 9, 2025):

Hi @createthis and @magikRUKKOLA, Currently balance_serve does not support prefix cache. We plan to improve this feature in the next few versions.

@qiyuxinlin Thank you. That's what I suspected. This makes balance_serve unsuitable for agentic coding and long single user coding conversation use cases. Please don't deprecate the ktransformers backend, as it is ideal for these use cases.

This project is awesome!

<!-- gh-comment-id:2789644379 --> @createthis commented on GitHub (Apr 9, 2025): > Hi [@createthis](https://github.com/createthis) and [@magikRUKKOLA](https://github.com/magikRUKKOLA), Currently balance_serve does not support prefix cache. We plan to improve this feature in the next few versions. @qiyuxinlin Thank you. That's what I suspected. This makes `balance_serve` unsuitable for agentic coding and long single user coding conversation use cases. Please don't deprecate the `ktransformers` backend, as it is ideal for these use cases. This project is awesome!
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#756
No description provided.