Skip to content

Eval bug: VRAM spike when kvarn5/kvarn4 is used #112

Closed

Description

@mkey

Name and Version

version: 10857 (f7ca480)
built with GNU 14.2.0 for Linux x86_64

Operating systems

Linux

GGML backends

CUDA

Hardware

GTX 1070 8GB VRAM

Models

Ornith-1.0-35B-MTP-APEX-I-Balanced.gguf from https://huggingface.co/SC117/Ornith-1.0-35B-MTP-APEX-GGUF

This is a model with up to Q6 quant and inbuilt MTP.

Problem description & steps to reproduce

The mentioned Ornith model based on Qwen 3.6 35B A3B works surprisingly well on my ageing machine. With a few patches applied I can get up 600 PP and 20 something TG. Which, in my view, is quite extraordinary.

I'm aiming for 128k context as 64k is just way too low for my purposes. On TurboQuant I could pull 128k with turbo4/turbo2 and things worked reasonably well. My 8GB VRAM would be almost fully used and another 25GB went into RAM + cached. Since I have 48 GB DDR4 RAM, I usually had a comfy 8GB RAM cushion. I have ZRAM enabled on my system, maybe relevant.

Anyhow, switching over to Beellama, I tried using kvarn5/kvarn4 which looked like the sweet spot. With this combo it became apparent with 128k context BL wanted to consume all of my RAM. So I turned on logging to LVL 4, turned off all the extra stuff (mmproj, MTP) and set a small 8192 context.

It became apparent that q5_0/q4_1 allocated about 350 MB for compute while kvarn5/kvarn4 allocated 3,5 GB for the same. Here's my llama-server command:

#!/bin/bash

args=(
	-m ~/models/Ornith-1.0-35B-MTP-APEX-I-Balanced.gguf

	### GENERAL
	--metrics -lv 4 --parallel 1 -t 5 --poll 100
	--no-mmap --cors-origins localhost
	-fit on --flash-attn on
	
	### CONTEXT
	--predict 8192 -c 8192
	#~ -ctk q5_0 -ctv q4_1
	-ctk kvarn5 -ctv kvarn4
	--reasoning off

	### CACHING
	--cache-ram 2048 -b 2048 -ub 1024
	--cache-prompt

	### MODEL SETTINGS
	--temp 0.85 --top-p 0.95 --top-k 20 --min-p 0.0
	--presence-penalty 1.1 --repeat-penalty 1.0

	--jinja
)

/media/mkey/data/bin/beellama.cpp/build/bin/llama-server "${args[@]}"

And here's my build command:

cmake -B build -DGGML_CUDA=ON -DGGML_NATIVE=ON -DGGML_CUDA_FA=ON -DCMAKE_BUILD_TYPE=Release
cmake --build build -j

First Bad Commit

IDK

Relevant log output

Logs
#~ -ctk q5_0 -ctv q4_1

0.33.658.673 I common_memory_breakdown_print: | memory breakdown [MiB] | total   free     self   model   context   compute    unaccounted |
0.33.658.676 I common_memory_breakdown_print: |   - CUDA0 (GTX 1070)   |  8084 = 1113 + ( 6348 =  5890 +     113 +     345) +         622 |
0.33.658.676 I common_memory_breakdown_print: |   - Host               |                 18917 = 18859 +       2 +      56                |

# -ctk kvarn5 -ctv kvarn4

0.45.614.752 I common_memory_breakdown_print: | memory breakdown [MiB] | total   free     self   model   context   compute    unaccounted |
0.45.614.754 I common_memory_breakdown_print: |   - CUDA0 (GTX 1070)   |  8084 = 1073 + ( 6382 =  2663 +     116 +    3602) +         628 |
0.45.614.755 I common_memory_breakdown_print: |   - Host               |                 22151 = 22086 +       2 +      62                |

log-level-4.log

Activity

  1. Anbeeld commented on Jul 28, 2026

    @Anbeeld
    Owner

    Native KVarN wasn't enabled for pre-Turing GPUs. I implemented some fixes for that, please try building the latest v0.4.2 branch and check if it helps.

  2. mkey commented on Jul 29, 2026

    @mkey
    Author

    @Anbeeld Thanks for looking into it. It doesn't seem to work out on my end.

    [mkey@lmde program]$ /media/mkey/data/bin/beellama.cpp-2/build/bin/llama-server --version
    version: 10857 (f7ca480ed)
    built with GNU 14.2.0 for Linux x86_64

    I tried to start with 128k context with kvarn5/kvarn4 instead of q5_0/q4_1 and got this.

    0.00.013.468 I cmn  common_param: common_params_print_info: verbosity = 3 (adjust with the `-lv N` CLI arg)
    0.00.084.451 I srv    load_model: loading model '/home/mkey/models/ornith-apex'
    0.01.239.990 W common_fit_params: failed to fit params to free device memory: n_gpu_layers already set by user to 99, abort
    0.27.281.727 E ggml_backend_cuda_buffer_type_alloc_buffer: allocating 17099.75 MiB on device 0: cudaMalloc failed: out of memory
    0.27.281.731 E ggml_gallocr_reserve_n_impl: failed to allocate CUDA0 buffer of size 17930387584
    0.27.281.732 E graph_reserve: failed to allocate compute buffers
    0.27.293.464 E llama_init_from_model: failed to initialize the context: failed to allocate compute pp buffers
    0.27.293.470 E cmn  common_init_: failed to create context with model '/home/mkey/models/ornith-apex'
    0.27.293.474 E cmn  common_init_: failed to create context with model '/home/mkey/models/ornith-apex'
    /home/mkey/.llama-server/llama-ornith-beellama.sh: line 54: 824190 Segmentation fault      (core dumped) /media/mkey/data/bin/beellama.cpp-2/build/bin/llama-server "${args[@]}"
  3. Anbeeld commented on Aug 2, 2026

    @Anbeeld
    Owner

    You version says version: 10857 (f7ca480ed) in both cases, so you probably haven't tested the change.

    Please try v0.4.2 release (or v0.4.3 preview).

  4. mkey commented on Aug 3, 2026

    @mkey
    Author

    Silly me. I thought I checked out 0.4.2 but apparently not. Here's 0.4.3. It's not the same issue, but it still crashes.

    llama-server --version
    version: 11003 (6b365df15)
    built with GNU 14.2.0 for Linux x86_64
    0.00.023.932 W DEPRECATED: --mmap and --no-mmap are deprecated. use --load-mode mmap instead
    0.00.024.313 I cmn  common_param: common_params_print_info: build 11003 (6b365df15) with GNU 14.2.0 for Linux x86_64
    0.00.024.315 I cmn  common_param: common_params_print_info: verbosity = 4 (adjust with the `-lv N` CLI arg)
    0.00.024.315 I cmn  common_param: device_info:
    0.00.099.965 I cmn  common_param:   - CUDA0   : NVIDIA GeForce GTX 1070 (8084 MiB, 7406 MiB free)
    0.00.099.975 I cmn  common_param:   - CPU     : AMD Ryzen 7 3700X 8-Core Processor (48104 MiB, 48104 MiB free)
    0.00.100.068 I cmn  common_param: system_info: n_threads = 5 (n_threads_batch = 5) / 16 | CUDA : ARCHS = 610 | USE_GRAPHS = 1 | CPU : SSE3 = 1 | SSSE3 = 1 | AVX = 1 | AVX2 = 1 | F16C = 1 | FMA = 1 | BMI2 = 1 | LLAMAFILE = 1 | OPENMP = 1 | REPACK = 1 | 
    0.00.100.113 I srv          init: running without SSL
    0.00.100.184 I srv          init: using 15 threads for HTTP server
    0.00.100.672 I srv         start: binding port with default address family
    0.00.101.975 I srv    load_model: loading model '/home/mkey/models/ornith-apex'
    0.00.101.978 I srv    load_model: local path '/home/mkey/models/ornith-apex'
    0.00.182.476 I llama_model_loader: loaded meta data with 49 key-value pairs and 753 tensors from /home/mkey/models/ornith-apex (version GGUF V3 (latest))
    0.00.182.506 I llama_model_loader: Dumping metadata keys/values. Note: KV overrides do not apply in this output.
    0.00.182.515 I llama_model_loader: - kv   0:                       general.architecture str              = qwen35moe
    0.00.182.516 I llama_model_loader: - kv   1:                               general.type str              = model
    0.00.182.518 I llama_model_loader: - kv   2:                     general.sampling.top_k i32              = 20
    0.00.182.529 I llama_model_loader: - kv   3:                     general.sampling.top_p f32              = 0.950000
    0.00.182.530 I llama_model_loader: - kv   4:                      general.sampling.temp f32              = 1.000000
    0.00.182.531 I llama_model_loader: - kv   5:                               general.name str              = Ornith 1.0 35B MTP
    0.00.182.531 I llama_model_loader: - kv   6:                           general.finetune str              = MTP
    0.00.182.532 I llama_model_loader: - kv   7:                           general.basename str              = Ornith-1.0
    0.00.182.532 I llama_model_loader: - kv   8:                         general.size_label str              = 35B
    0.00.182.533 I llama_model_loader: - kv   9:                            general.license str              = mit
    0.00.182.534 I llama_model_loader: - kv  10:                       general.license.link str              = https://huggingface.co/deepreinforce-...
    0.00.182.550 I llama_model_loader: - kv  11:                               general.tags arr[str,1]       = ["text-generation"]
    0.00.182.551 I llama_model_loader: - kv  12:                      qwen35moe.block_count u32              = 41
    0.00.182.551 I llama_model_loader: - kv  13:                   qwen35moe.context_length u32              = 262144
    0.00.182.552 I llama_model_loader: - kv  14:                 qwen35moe.embedding_length u32              = 2048
    0.00.182.552 I llama_model_loader: - kv  15:             qwen35moe.attention.head_count u32              = 16
    0.00.182.553 I llama_model_loader: - kv  16:          qwen35moe.attention.head_count_kv u32              = 2
    0.00.182.555 I llama_model_loader: - kv  17:          qwen35moe.rope.dimension_sections arr[i32,4]       = [11, 11, 10, 0]
    0.00.182.557 I llama_model_loader: - kv  18:                   qwen35moe.rope.freq_base f32              = 10000000.000000
    0.00.182.558 I llama_model_loader: - kv  19: qwen35moe.attention.layer_norm_rms_epsilon f32              = 0.000001
    0.00.182.558 I llama_model_loader: - kv  20:                     qwen35moe.expert_count u32              = 256
    0.00.182.559 I llama_model_loader: - kv  21:                qwen35moe.expert_used_count u32              = 8
    0.00.182.559 I llama_model_loader: - kv  22:             qwen35moe.attention.key_length u32              = 256
    0.00.182.559 I llama_model_loader: - kv  23:           qwen35moe.attention.value_length u32              = 256
    0.00.182.560 I llama_model_loader: - kv  24:       qwen35moe.expert_feed_forward_length u32              = 512
    0.00.182.560 I llama_model_loader: - kv  25: qwen35moe.expert_shared_feed_forward_length u32              = 512
    0.00.182.561 I llama_model_loader: - kv  26:                  qwen35moe.ssm.conv_kernel u32              = 4
    0.00.182.561 I llama_model_loader: - kv  27:                   qwen35moe.ssm.state_size u32              = 128
    0.00.182.562 I llama_model_loader: - kv  28:                  qwen35moe.ssm.group_count u32              = 16
    0.00.182.562 I llama_model_loader: - kv  29:               qwen35moe.ssm.time_step_rank u32              = 32
    0.00.182.562 I llama_model_loader: - kv  30:                   qwen35moe.ssm.inner_size u32              = 4096
    0.00.182.563 I llama_model_loader: - kv  31:          qwen35moe.full_attention_interval u32              = 4
    0.00.182.563 I llama_model_loader: - kv  32:             qwen35moe.rope.dimension_count u32              = 64
    0.00.182.564 I llama_model_loader: - kv  33:             qwen35moe.nextn_predict_layers u32              = 1
    0.00.182.564 I llama_model_loader: - kv  34:                       tokenizer.ggml.model str              = gpt2
    0.00.182.565 I llama_model_loader: - kv  35:                         tokenizer.ggml.pre str              = qwen35
    0.00.216.139 I llama_model_loader: - kv  36:                      tokenizer.ggml.tokens arr[str,248320]  = ["!", "\"", "#", "$", "%", "&", "'", ...
    0.00.223.739 I llama_model_loader: - kv  37:                  tokenizer.ggml.token_type arr[i32,248320]  = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ...
    0.00.255.360 I llama_model_loader: - kv  38:                      tokenizer.ggml.merges arr[str,247587]  = ["Ġ Ġ", "ĠĠ ĠĠ", "i n", "Ġ t",...
    0.00.255.367 I llama_model_loader: - kv  39:                tokenizer.ggml.eos_token_id u32              = 248046
    0.00.255.368 I llama_model_loader: - kv  40:            tokenizer.ggml.padding_token_id u32              = 248044
    0.00.255.369 I llama_model_loader: - kv  41:                tokenizer.ggml.bos_token_id u32              = 248044
    0.00.255.371 I llama_model_loader: - kv  42:                    tokenizer.chat_template str              = {%- set image_count = namespace(value...
    0.00.255.372 I llama_model_loader: - kv  43:               general.quantization_version u32              = 2
    0.00.255.373 I llama_model_loader: - kv  44:                          general.file_type u32              = 17
    0.00.255.374 I llama_model_loader: - kv  45:                      quantize.imatrix.file str              = J:\Models\Qwen3.5-35B-A3B.imatrix.gguf
    0.00.255.374 I llama_model_loader: - kv  46:                   quantize.imatrix.dataset str              = imatrix-training-full-3
    0.00.255.375 I llama_model_loader: - kv  47:             quantize.imatrix.entries_count u32              = 510
    0.00.255.375 I llama_model_loader: - kv  48:              quantize.imatrix.chunks_count u32              = 319
    0.00.255.379 I llama_model_loader: - type  f32:  310 tensors
    0.00.255.380 I llama_model_loader: - type q8_0:  123 tensors
    0.00.255.380 I llama_model_loader: - type q5_K:   92 tensors
    0.00.255.381 I llama_model_loader: - type q6_K:  228 tensors
    0.00.255.383 I print_info: file format = GGUF V3 (latest)
    0.00.255.385 I print_info: file type   = Q5_K - Medium
    0.00.255.388 I print_info: file size   = 24.17 GiB (5.85 BPW) 
    0.00.256.105 I llama_prepare_model_devices: using device CUDA0 (NVIDIA GeForce GTX 1070) (0000:09:00.0) - 7406 MiB free
    0.00.398.220 I load: 0 unused tokens
    0.00.434.870 I load: printing all EOG tokens:
    0.00.434.876 I load:   - 248044 ('<|endoftext|>')
    0.00.434.877 I load:   - 248046 ('<|im_end|>')
    0.00.434.877 I load:   - 248063 ('<|fim_pad|>')
    0.00.434.878 I load:   - 248064 ('<|repo_name|>')
    0.00.434.878 I load:   - 248065 ('<|file_sep|>')
    0.00.435.326 I load: special tokens cache size = 33
    0.00.527.265 I load: token to piece cache size = 1.7581 MB
    0.00.527.283 I print_info: arch                  = qwen35moe
    0.00.527.284 I print_info: vocab_only            = 0
    0.00.527.284 I print_info: no_alloc              = 0
    0.00.527.285 I print_info: n_ctx_train           = 262144
    0.00.527.286 I print_info: n_embd_inp            = 2048
    0.00.527.287 I print_info: n_embd                = 2048
    0.00.527.288 I print_info: n_embd_out            = 2048
    0.00.527.288 I print_info: n_layer               = 40
    0.00.527.288 I print_info: n_layer_all           = 41
    0.00.527.296 I print_info: n_head                = 16
    0.00.527.298 I print_info: n_head_kv             = 2
    0.00.527.298 I print_info: n_rot                 = 64
    0.00.527.299 I print_info: n_swa                 = 0
    0.00.527.300 I print_info: is_swa_any            = 0
    0.00.527.301 I print_info: n_embd_head_k         = 256
    0.00.527.301 I print_info: n_embd_head_v         = 256
    0.00.527.303 I print_info: n_gqa                 = 8
    0.00.527.308 I print_info: n_embd_k_gqa          = 512
    0.00.527.311 I print_info: n_embd_v_gqa          = 512
    0.00.527.311 I print_info: f_norm_eps            = 0.0e+00
    0.00.527.312 I print_info: f_norm_rms_eps        = 1.0e-06
    0.00.527.312 I print_info: f_clamp_kqv           = 0.0e+00
    0.00.527.313 I print_info: f_max_alibi_bias      = 0.0e+00
    0.00.527.313 I print_info: f_logit_scale         = 0.0e+00
    0.00.527.313 I print_info: f_attn_scale          = 0.0e+00
    0.00.527.313 I print_info: f_attn_value_scale    = 0.0000
    0.00.527.315 I print_info: n_ff                  = 0
    0.00.527.315 I print_info: n_expert              = 256
    0.00.527.316 I print_info: n_expert_used         = 8
    0.00.527.316 I print_info: n_expert_groups       = 0
    0.00.527.316 I print_info: n_group_used          = 0
    0.00.527.317 I print_info: causal attn           = 1
    0.00.527.317 I print_info: pooling type          = -1
    0.00.527.317 I print_info: rope type             = 40
    0.00.527.317 I print_info: rope scaling          = linear
    0.00.527.318 I print_info: freq_base_train       = 10000000.0
    0.00.527.319 I print_info: freq_scale_train      = 1
    0.00.527.319 I print_info: n_ctx_orig_yarn       = 262144
    0.00.527.319 I print_info: rope_yarn_log_mul     = 0.0000
    0.00.527.320 I print_info: rope_finetuned        = unknown
    0.00.527.320 I print_info: mrope sections        = [11, 11, 10, 0]
    0.00.527.320 I print_info: ssm_d_conv            = 4
    0.00.527.321 I print_info: ssm_d_inner           = 4096
    0.00.527.321 I print_info: ssm_d_state           = 128
    0.00.527.321 I print_info: ssm_dt_rank           = 32
    0.00.527.321 I print_info: ssm_n_group           = 16
    0.00.527.322 I print_info: ssm_dt_b_c_rms        = 0
    0.00.527.322 I print_info: model type            = 35B.A3B
    0.00.527.323 I print_info: model params          = 35.51 B
    0.00.527.323 I print_info: general.name          = Ornith 1.0 35B MTP
    0.00.527.327 I print_info: vocab type            = BPE
    0.00.527.328 I print_info: n_vocab               = 248320
    0.00.527.328 I print_info: n_merges              = 247587
    0.00.527.329 I print_info: BOS token             = 248044 '<|endoftext|>'
    0.00.527.329 I print_info: EOS token             = 248046 '<|im_end|>'
    0.00.527.329 I print_info: EOT token             = 248046 '<|im_end|>'
    0.00.527.329 I print_info: PAD token             = 248044 '<|endoftext|>'
    0.00.527.330 I print_info: LF token              = 198 'Ċ'
    0.00.527.330 I print_info: FIM PRE token         = 248060 '<|fim_prefix|>'
    0.00.527.330 I print_info: FIM SUF token         = 248062 '<|fim_suffix|>'
    0.00.527.330 I print_info: FIM MID token         = 248061 '<|fim_middle|>'
    0.00.527.330 I print_info: FIM PAD token         = 248063 '<|fim_pad|>'
    0.00.527.331 I print_info: FIM REP token         = 248064 '<|repo_name|>'
    0.00.527.331 I print_info: FIM SEP token         = 248065 '<|file_sep|>'
    0.00.527.332 I print_info: EOG token             = 248044 '<|endoftext|>'
    0.00.527.332 I print_info: EOG token             = 248046 '<|im_end|>'
    0.00.527.332 I print_info: EOG token             = 248063 '<|fim_pad|>'
    0.00.527.332 I print_info: EOG token             = 248064 '<|repo_name|>'
    0.00.527.333 I print_info: EOG token             = 248065 '<|file_sep|>'
    0.00.527.333 I print_info: max token length      = 256
    0.00.527.336 I load_tensors: loading model tensors, this can take a while... (load_mode = none)
    0.13.071.825 I load_tensors: offloading output layer to GPU
    0.13.071.829 I load_tensors: offloading 40 repeating layers to GPU
    0.13.071.829 I load_tensors: offloaded 42/42 layers to GPU
    0.13.071.840 I load_tensors:        CUDA0 model buffer size =  3536.01 MiB
    0.13.071.841 I load_tensors:    CUDA_Host model buffer size = 21213.44 MiB
    0.28.578.952 I cmn  common_init_: added <|endoftext|> logit bias = -inf
    0.28.578.956 I cmn  common_init_: added <|im_end|> logit bias = -inf
    0.28.578.957 I cmn  common_init_: added <|fim_pad|> logit bias = -inf
    0.28.578.957 I cmn  common_init_: added <|repo_name|> logit bias = -inf
    0.28.578.958 I cmn  common_init_: added <|file_sep|> logit bias = -inf
    0.28.590.450 I llama_init_from_model: enabling structured KVarN cache type kvarn_k5v4_g128
    0.28.590.495 I llama_context: constructing llama_context
    0.28.590.501 I KVarN exact tail: group=full raw=0 requested=128 effective=128 window=131072 representation=overlay
    0.28.590.504 I llama_context: n_seq_max     = 1
    0.28.590.504 I llama_context: n_ctx         = 131072
    0.28.590.505 I llama_context: n_ctx_seq     = 131072
    0.28.590.505 I llama_context: n_batch       = 2048
    0.28.590.505 I llama_context: n_ubatch      = 1024
    0.28.590.505 I llama_context: causal_attn   = 1
    0.28.590.507 I llama_context: flash_attn    = enabled
    0.28.590.508 I llama_context: kv_unified    = false
    0.28.590.511 I llama_context: freq_base     = 10000000.0
    0.28.590.514 I llama_context: freq_scale    = 1
    0.28.590.515 I llama_context: n_rs_seq      = 2
    0.28.590.515 I llama_context: n_outputs_max = 3
    0.28.590.516 I llama_context: n_ctx_seq (131072) < n_ctx_train (262144) -- the full capacity of the model will not be utilized
    0.28.592.351 I llama_context:  CUDA_Host  output buffer size =     0.95 MiB
    0.28.596.350 I llama_kv_cache: standard KV tail plan: storage=compact_overlay requested=128 effective=128 window=131072 body=f16/f16 actual=f16/f16 physical_rows=131072 arena=1280 sink=0 overlay_rows=1280 promotion=0.00 MiB overlay=0.00 MiB
    0.28.596.359 I llama_kv_cache: size =    0.00 MiB (131072 cells,   0 layers,  1/1 seqs), K (none):    0.00 MiB, V (none):    0.00 MiB
    0.28.596.360 I llama_kv_cache: attn_rot_k = 0, n_embd_head_k_all = 0
    0.28.596.361 I llama_kv_cache: attn_rot_v = 0, n_embd_head_k_all = 0
    0.28.596.363 I KVarN cache: stage_groups=3 tail_groups=2 n_batch=2048 n_ubatch=1024
    0.28.606.858 I llama_kv_cache_kvarn:      CUDA0 KVarN buffer size =   787.50 MiB
    0.28.608.060 I KV tail: group=full layer=39 dev=CUDA0 route=native body=kvarn/kvarn exact=f16/f16 presence=body current=current execution_rows=256 requested=128 effective=128
    0.28.608.063 I KV tail: group=full layer=35 dev=CUDA0 route=native body=kvarn/kvarn exact=f16/f16 presence=body current=current execution_rows=256 requested=128 effective=128
    0.28.608.064 I KV tail: group=full layer=31 dev=CUDA0 route=native body=kvarn/kvarn exact=f16/f16 presence=body current=current execution_rows=256 requested=128 effective=128
    0.28.608.065 I KV tail: group=full layer=27 dev=CUDA0 route=native body=kvarn/kvarn exact=f16/f16 presence=body current=current execution_rows=256 requested=128 effective=128
    0.28.608.066 I KV tail: group=full layer=23 dev=CUDA0 route=native body=kvarn/kvarn exact=f16/f16 presence=body current=current execution_rows=256 requested=128 effective=128
    0.28.608.066 I KV tail: group=full layer=19 dev=CUDA0 route=native body=kvarn/kvarn exact=f16/f16 presence=body current=current execution_rows=256 requested=128 effective=128
    0.28.608.067 I KV tail: group=full layer=15 dev=CUDA0 route=native body=kvarn/kvarn exact=f16/f16 presence=body current=current execution_rows=256 requested=128 effective=128
    0.28.608.068 I KV tail: group=full layer=11 dev=CUDA0 route=native body=kvarn/kvarn exact=f16/f16 presence=body current=current execution_rows=256 requested=128 effective=128
    0.28.608.069 I KV tail: group=full layer=7 dev=CUDA0 route=native body=kvarn/kvarn exact=f16/f16 presence=body current=current execution_rows=256 requested=128 effective=128
    0.28.608.070 I KV tail: group=full layer=3 dev=CUDA0 route=native body=kvarn/kvarn exact=f16/f16 presence=body current=current execution_rows=256 requested=128 effective=128
    0.28.608.367 I llama_kv_cache_kvarn:      CUDA0 KVarN tail buffer size =     2.54 MiB
    0.28.608.375 I llama_kv_cache_kvarn: type = kvarn_k5v4_g128, layers = 10, groups/stream = 1024, streams = 1, KVarN = 790.04 MiB, equivalent F16 = 2560.00 MiB
    0.28.609.586 I llama_memory_recurrent:      CUDA0 RS buffer size =   188.44 MiB
    0.28.609.593 I llama_memory_recurrent: size =  188.44 MiB (     1 cells,  40 layers,  1 seqs  2 rs_seq), R (f32):    8.44 MiB, S (f32):  180.00 MiB
    0.28.609.720 I sched_reserve: reserving ...
    0.28.625.058 I resolve_fused_ops: resolving fused Gated Delta Net support:
    0.28.642.325 E llama_init_from_model: failed to initialize the context: KV tail layer 3 native operation is unsupported by its planned backend CUDA0; refusing scheduler fallback
    0.28.642.333 E cmn  common_init_: failed to create context with model '/home/mkey/models/ornith-apex'
    0.28.642.337 E cmn  common_init_: failed to create context with model '/home/mkey/models/ornith-apex'
    0.28.642.340 E srv    load_model: failed to create_context with model '/home/mkey/models/ornith-apex'
    0.28.642.342 I srv    operator(): operator(): cleaning up before exit...
    0.28.643.496 E srv  llama_server: exiting due to model loading error
  5. AddisonJGambhir commented on Aug 9, 2026

    @AddisonJGambhir

    Also affects Vulkan/RADV on AMD, and v0.4.3 trades the memory spike for a large speed regression

    Same class of issue on a different backend. On Vulkan + RADV (RX 7900 XTX, gfx1100), kvarn5/kvarn4 and q8_0 differ enormously in speed on v0.4.3, and in memory on v0.4.2 — because the two releases pick opposite routes.

    Environment

    • AMD RX 7900 XTX (gfx1100), RADV, Linux, Vulkan backend
    • BeeLlama v0.4.3 (32040e7) and v0.4.2 (d71585e), both built locally
    • Qwen3.6-27B-MTP-Q4_K_M, -c 131072, --flash-attn on, -ub 192, --spec-type draft-mtp --spec-draft-n-max 2, --kv-tail-tokens unset (0)

    Speed, v0.4.3, same build and session, 16384-char prompt

    cache encode tps decode tps peak VRAM peak GTT
    q8_0 588.0 71.5 20.43 GiB 0.16 GiB
    kvarn5/kvarn4 310.4 41.2 18.84 GiB 0.16 GiB

    KVarN is 47% slower on encode, 42% on decode. GTT peak is identical and ~5 GiB of VRAM is free during the run (polled every 0.4s via amdgpu fdinfo), so this is not spill or memory pressure.

    Route evidence — GGML_KVARN_DEBUG_ROUTES=1, counted per server start:

    • v0.4.3: 21 × route=portable-native entry=compact-tail, 0 materialize — including large prefill batches (nq=192 nkv=2048 gqa=6)
    • v0.4.2: 100% route=materialize fallback=explicit-materialization

    Cause appears to be 0c5034c1b, which changed ggml_backend_vk_kvarn_native_rotated_max_query_tokens in ggml/src/ggml-vulkan/ggml-vulkan.cpp:

    -    return ggml_backend_vk_kvarn_native_ops(dev) ? 16u : 0u;
    +    return ggml_backend_vk_kvarn_native_ops(dev) ? UINT32_MAX : 0u;

    With the intrinsic 128-token exact suffix, every KVarN Vulkan layer is permanently in the mixed compressed-body + exact-tail class. Under 16u that vetoed to materialize + tiled FA; under UINT32_MAX every prefill batch goes to kvarn_flash_attn.comp, which is a single unspecialized shader with local_size_x = 128, one query row per workgroup, and no cooperative-matrix path — against q8_0's coopmat FA.

    This also seems to contradict docs/beellama-features.md:131:

    That policy is intentional: hardware measurements found the mixed direct shader slower than the materialized upstream-style route.

    The v0.4.2 side is the memory half, and matches this issue. With the 16u/materialize route on the same card:

    • 128k: 21.66 GiB VRAM + 2.37 GiB spilled to GTT
    • 220k: 21.67 GiB VRAM + 7.92 GiB spilled to GTT

    So on Vulkan/AMD the two releases sit at opposite ends of the same tradeoff: v0.4.2 materializes and blows up memory (this issue), v0.4.3 stays native and loses ~45% throughput. v0.4.2 KVarN encode was 331.0 tps, still well below q8_0.

    Question: should Vulkan report a bounded cap on backends without a specialized KVarN decode kernel, rather than UINT32_MAX? CUDA reports rotated_query_max_specialized because it has specialized_decode_split / specialized_decode_vector behind it; Vulkan has one portable shader. Note docs/records/kvarn-tail-fit-remediation-completion-20260809.md states the Vulkan route work for that commit was validated on an RTX 3090 and explicitly not on an AMD runtime.

    Happy to run patches or collect more data on RADV/gfx1100.

  6. Anbeeld commented on Aug 9, 2026

    @Anbeeld
    Owner

    What a load-bearing report. I'll check what can be done.

  7. AddisonJGambhir commented on Aug 9, 2026

    @AddisonJGambhir

    @Anbeeld Sorry it was Claude-generated, but I proof read it an the description is accurate. If there's anything I can do, in terms of proving more data or forking the branch and fixing it locally, I would be glad to do that as well.

  8. skewty commented on Aug 12, 2026

    @skewty

    I just cloned repo (so current master) and compiled with:

    cmake -B build -DGGML_VULKAN=ON
    cmake --build build --config Release

    ran with:

          ${env.HOME}/Projects/beellama.cpp/build/bin/llama-server --port ${PORT} --device Vulkan1 --no-log-prefix --no-log-timestamps
          --model ${models}/unsloth/dyn2.0/Qwen3.6-27B-MTP-UD-Q5_K_XL.gguf --no-mmproj --jinja
          --ctx-size 65536 --kv-unified --parallel 1 --batch-size 2048 --ubatch-size 512 --n-gpu-layers 999 --flash-attn on
          --top-k 20 --top-p 0.95 --min-p 0.05 --repeat-penalty 1.0
          --reasoning on --reasoning-preserve --reasoning-budget 8192 --reasoning-budget-message "${reasoning-budget-message}"
          --cache-type-k kvarn5 --cache-type-v kvarn5 --cache-type-k-draft q4_0 --cache-type-v-draft q4_0 --kv-tail-tokens 1024
          --ctx-checkpoints 128 --checkpoint-min-step 2048 --cache-prompt --cache-ram -1 --keep -1
          --spec-type draft-mtp,ngram-mod --spec-draft-n-max 3 --spec-draft-p-min 0.65
          --spec-ngram-mod-n-match 24 --spec-ngram-mod-n-min 8 --spec-ngram-mod-n-max 32
          --no-spec-draft-backend-sampling

    usage is 30.08 GB

    when I was running upstream llama.cpp with:

          llama-server --port ${PORT} --device Vulkan1 --no-log-prefix --no-log-timestamps
          --model ${models}/unsloth/dyn2.0/Qwen3.6-27B-MTP-Q4_K_M.gguf --no-mmproj --jinja
          --ctx-size 388608 --kv-unified --parallel 3 --batch-size 2048 --ubatch-size 512 --n-gpu-layers 999 --flash-attn on
          --top-k 20 --top-p 0.95 --min-p 0.05 --repeat-penalty 1.0
          --reasoning on --reasoning-preserve --reasoning-budget 8192 --reasoning-budget-message "${reasoning-budget-message}"
          --cache-type-k q8_0 --cache-type-v q5_0 --cache-type-k-draft q4_0 --cache-type-v-draft q4_0
          --ctx-checkpoints 128 --checkpoint-min-step 2048 --cache-prompt --cache-ram -1 --keep -1
          --spec-type draft-mtp,ngram-mod --spec-draft-n-max 3 --spec-draft-p-min 0.65
          --spec-ngram-mod-n-match 24 --spec-ngram-mod-n-min 8 --spec-ngram-mod-n-max 32
          --no-spec-draft-backend-sampling

    usage is 29.058 GB

    388608 ctx with parallel 3 (multiple MTP) vs. 65536 with parallel 1 to avoid
    "ggml_vulkan: Failed to allocate pinned memory (Requested buffer size exceeds device buffer size limit: ErrorOutOfDeviceMemory)" error.

    beellama.cpp (llama-server --version) after compile gives:
    version: 11001 (5a35792)
    built with GNU 16.1.1 for Linux x86_64

    Something seems very wrong with the memory allocation.

  9. Anbeeld commented on Aug 12, 2026

    @Anbeeld
    Owner

    @skewty try v0.4.3 branch.

  10. skewty commented on Aug 12, 2026

    @skewty

    re-built
    version: 11192 (ee8754c)

    That did it! Wow.

    388608 ctx -> 29.058 GB (using Q8_0 keys and Q5_0 values)
    493312 ctx -> 29.218 GB (using kvarn5 keys and values)

    Haven't tested performance yet but that is huge! 😻

    edit: adding speed comparison

    with q8/q5 k/v cache and upstream llama.cpp
    PP 897 t/s -> 808 t/s with generation at around 56 t/s

    with kvarn5 k/v cache and beellama.cpp (0.4.3 branch)
    PP 420 t/s -> 155 t/s with generation at around 13 t/s

  11. mkey commented on Aug 12, 2026

    @mkey
    Author

    I can report that I have installed a second GPU (3060 12GB) and on it kvarn seems to work OK, even if I'm seeing a mild performance hit. Currently I'm trying to make the most out of my setup where I will use 3060 as the main GPU, then offload to 1070 and finally to RAM. 1070 allows for a very reasonable performance boost, it may be old, but still faster VRAM than RAM.

    I did run llama.cpp for comparison and over there I'm seeing very questionable performance degradation, on my otherwise very conservative hardware. For example, with beellama I get about 900 PP on Qwen 35B 3AB APEX vs miserably 50 PP on llama.cpp.

    How could I further troubleshoot performance? I have a feeling I'm leaving a lot of performance on the table.

  12. Anbeeld commented on Sep 6, 2026

    @Anbeeld
    Owner

    Performance and stability should be much better with the newly released v0.4.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions