Skip to content

HIP/ROCm: two crash fixes for TurboQuant KV cache on RDNA - #4

Merged
Ooooze merged 2 commits into
AtomicBot-ai:feature/turboquant-kv-cachefrom
dedesite:fix-hip-crash
May 7, 2026
Merged

HIP/ROCm: two crash fixes for TurboQuant KV cache on RDNA #4
Ooooze merged 2 commits into
AtomicBot-ai:feature/turboquant-kv-cachefrom
dedesite:fix-hip-crash

Conversation

@dedesite

@dedesite dedesite commented May 7, 2026

Copy link
Copy Markdown

Overview

This PR fixes a linking problem and a runtime crash when using mtp models like Gemma 4 assistant.

Tested on a Ryzen AI HX 470 (gfx1150, RDNA3.5) running Gemma 4 E4B with:

./build/bin/llama-server \
    -m         ./models/gemma-4-E4B-it-Q4_K_M.gguf \
    --mtp-head ./models/gemma-4-E4B-it-assistant.Q4_K_M.gguf \
    --spec-type mtp \
    --draft-block-size 3 --draft-max 8 --draft-min 0 \
    -ngl 99 -ngld 99 \
    -ctk turbo3 -ctv turbo3 -ctkd turbo3 -ctvd turbo3 \
    -fa on -c 16384 --host 127.0.0.1 --port 8080

OS : Linux Mint 22.3 (based on Ubuntu 20.04.04) with ROCm 7.2.1 installed

Fix 1 — HIP linker error: missing fattn-vec template instances

ggml/src/ggml-hip/CMakeLists.txt was missing three cross-type flash-attention VEC instances (f16 key × turbo2/3/4 value) that were already present in ggml/src/ggml-cuda/CMakeLists.txt.

This produced link errors at the final llama-server link step:

  undefined reference to void ggml_cuda_flash_attn_ext_vec_case<                                                                                                                        
      256, (ggml_type)1, (ggml_type)42>                                                                                                                                                 
  undefined reference to void ggml_cuda_flash_attn_ext_vec_case<                                                                                                                        
      256, (ggml_type)1, (ggml_type)43>                                                                                                                                                 
  undefined reference to void ggml_cuda_flash_attn_ext_vec_case<                                                                                                                        
      256, (ggml_type)1, (ggml_type)44>                                                                                                                                                 

Fix: added the three files to the HIP CMake list.

Fix 2 — Runtime GGML_ABORT in fattn-tile.cuh for head_dim=512

Gemma 4 E4B has head_dim = 4096 / 8 = 512. For head_dim=512, all fast FA paths are excluded on AMD:

  • VEC — capped at head_dim ≤ 256
  • WMMA — explicitly excludes Q->ne[0] == 512
  • MFMA — explicitly excludes Q->ne[0] == 512

So TILE is always selected. Inside launch_fattn_tile_switch_ncols2<512, 512>, the DKQ ≤ 512 block only handled gqa_ratio % 4 == 0 and gqa_ratio % 8 == 0, then a DV ≤ 256 guard for smaller ratios. For DV=512 with gqa_ratio=2 (Gemma 4: 8 Q-heads / 4 KV-heads) the code fell straight through to GGML_ABORT("fatal error").
Fix:

  1. Dispatch — added ncols2=2 (for gqa_ratio % 2 == 0) and ncols2=1 (unconditional fallback) inside the DKQ ≤ 512 block after the DV ≤ 256 guard, mirroring the pattern that already exists for DV ≤ 256.
  2. Kernel configs — added (512, 512, ncols=2, nthreads=64, occupancy=2, nbatch_fa=32, nbatch_K=64) to all four config tables (nvidia_fp16, nvidia_fp32, amd, amd_rdna). Without these entries the device-side static_assert inside flash_attn_tile<512,512,1,2> would fire at compile time.

What fix this PR

Before fix 1: linker error, binary not produced.
Before fix 2: crash during first decode step with fattn-tile.cuh:1263: fatal error.
After both fixes: server runs without crash, MTP speculative decoding functional.

Test procedure

Build

cmake -B build -DGGML_HIP=ON -DAMDGPU_TARGETS=gfx1150 -DCMAKE_BUILD_TYPE=Release                                                                                                      
cmake --build build --target llama-server -j$(nproc)                                                                                                                                  ```

### Start server

```bash                                                                                                                                                     
./build/bin/llama-server \
    -m         ./models/gemma-4-E4B-it-Q4_K_M.gguf \
    --mtp-head ./models/gemma-4-E4B-it-assistant.Q4_K_M.gguf \
    --spec-type mtp \
    --draft-block-size 3 --draft-max 8 --draft-min 0 \
    -ngl 99 -ngld 99 \
    -ctk turbo3 -ctv turbo3 -ctkd turbo3 -ctvd turbo3 \
    -fa on -c 16384 --host 127.0.0.1 --port 8080

Benchmark

Here is a table with all tests result made.
Details of the command use to launch the server :
Baseline - Standard llama.cpp from llamacpp-rocm : ./llama-server -m ../atomic-llama-cpp-turboquant/models/gemma-4-E4B-it-Q4_K_M.gguf -ngl 99 -ngld 99 -fa on -c 16384 --host 127.0.0.1 --port 8080
KV Cache + MTP-HEAD : ./build/bin/llama-server -m ./models/gemma-4-E4B-it-Q4_K_M.gguf --mtp-head ./models/gemma-4-E4B-it-assistant.Q4_K_M.gguf --spec-type mtp --draft-block-size 3 --draft-max 8 --draft-min 0 -ngl 99 -ngld 99 -ctk turbo3 -ctvd turbo3 -fa on -c 16384 --host 127.0.0.1 --port 8080
MTP-HEAD Only : ./build/bin/llama-server -m ./models/gemma-4-E4B-it-Q4_K_M.gguf --mtp-head ./models/gemma-4-E4B-it-assistant.Q4_K_M.gguf --spec-type mtp --draft-block-size 3 --draft-max 8 --draft-min 0 -ngl 99 -ngld 99 -fa on -c 16384 --host 127.0.0.1 --port 8080;
KV Cache Only : ./build/bin/llama-server -m ./models/gemma-4-E4B-it-Q4_K_M.gguf -ngl 99 -ngld 99 -ctk turbo3 -ctvd turbo3 -fa on -c 16384 --host 127.0.0.1 --port 8080;

All test are runs with :

PORT=8080 PARALLEL=1 N_PREDICT=200 ./scripts/bench-parallel.sh
PORT=8080 PARALLEL=4 N_PREDICT=200 ./scripts/bench-parallel.sh
Type PARALLEL=1 (per_seq_tps) Speed (compare to baseline) PARALLEL=4 (per_seq_tps) Speed (compare to baseline)
Baseline 25.15 x1.0 14.10 x1.0
KV Cache + MTP Head 30.84 x1.22 18.96 x1.34
MTP Head Only 32.51 x1.29 18.52 x1.31
KV Cache Only 23.69 x0.94 13.03 x0.92

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES, to be honest the dev has entirely be done by Claude Code, I never worked on llama.cpp code, just wanted to run gemma with mtp assistant on my machine. If this doesn't match llama.cpp requirement then at least the code will be somewhere public.

Andreas Livet and others added 2 commits May 7, 2026 13:59
The HIP fattn-vec build list was missing three cross-type instances
(f16 key + turbo2/3/4 value) that were already present in the CUDA
CMakeLists.  This caused linker errors of the form:

  undefined reference to void ggml_cuda_flash_attn_ext_vec_case<
      256, (ggml_type)1, (ggml_type)42/43/44>

when building llama-server with GGML_HIP=ON and TurboQuant KV cache
enabled.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Models with head_dim=512 (e.g. Gemma 4 E4B: n_embd=4096, n_head=8)
always use the TILE flash-attention path on AMD/HIP because VEC is
capped at head_dim<=256 and WMMA/MFMA explicitly exclude D=512.

Inside launch_fattn_tile_switch_ncols2<512,512>, the DKQ<=512 block
only had fallback cases for gqa_ratio divisible by 4 or 8, then a
DV<=256 guard for ratio=2/1.  For DV=512 with gqa_ratio=2 (Gemma 4:
8 Q-heads / 4 KV-heads) the code fell through to GGML_ABORT.

Fix two things:
1. Dispatch: add ncols2=2 and ncols2=1 fallbacks inside the DKQ<=512
   block for the DV>256 case, mirroring what already exists for DV<=256.
2. Kernel configs: add the missing ncols=2 entry for DKQ=DV=512 in all
   four config tables (nvidia_fp16, nvidia_fp32, amd, amd_rdna).
   Without these entries the device-side static_assert would fire at
   compile time for flash_attn_tile<512,512,{1,2},2,*>.

Tested on gfx1150 (Ryzen AI HX 470, RDNA3.5) running Gemma 4 E4B
with -ctk turbo3 -ctv turbo3 and --mtp-head speculative decoding.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Ooooze
Ooooze merged commit 2e81dc5 into AtomicBot-ai:feature/turboquant-kv-cache May 7, 2026
1 check passed
@Ooooze

Ooooze commented May 7, 2026

Copy link
Copy Markdown

Thanks for the fix and the detailed writeup — much appreciated!

@dedesite

dedesite commented May 9, 2026 via email

Copy link
Copy Markdown
Author

fukuro-kun pushed a commit to fukuro-kun/fukuro-llama-cpp-turboquant that referenced this pull request Jul 5, 2026
…gml-org#16038)

Initalizing RESERVED_NAME in is_reserved_name() is not thread
safe and leads to corrupted memory when used from multiple threads
as can be seen in the asan trace below. This fixes the initialization
to make it thread-safe.

    #0 0x000100abd018 in std::__1::pair<std::__1::__hash_iterator<std::__1::__hash_node<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, void*>*>, bool> std::__1::__hash_table<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::hash<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>, std::__1::equal_to<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>>::__emplace_unique_key_args<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&) __hash_table:1565
    AtomicBot-ai#1 0x000100ab0320 in SchemaConverter::visit(nlohmann::json_abi_v3_12_0::basic_json<nlohmann::json_abi_v3_12_0::ordered_map, std::__1::vector, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, bool, long long, unsigned long long, double, std::__1::allocator, nlohmann::json_abi_v3_12_0::adl_serializer, std::__1::vector<unsigned char, std::__1::allocator<unsigned char>>, void> const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&) json-schema-to-grammar.cpp:802
    AtomicBot-ai#2 0x000100aafc48 in std::__1::__function::__func<build_grammar(std::__1::function<void (common_grammar_builder const&)> const&, common_grammar_options const&)::$_2, std::__1::allocator<build_grammar(std::__1::function<void (common_grammar_builder const&)> const&, common_grammar_options const&)::$_2>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> (std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, nlohmann::json_abi_v3_12_0::basic_json<nlohmann::json_abi_v3_12_0::ordered_map, std::__1::vector, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, bool, long long, unsigned long long, double, std::__1::allocator, nlohmann::json_abi_v3_12_0::adl_serializer, std::__1::vector<unsigned char, std::__1::allocator<unsigned char>>, void> const&)>::operator()(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, nlohmann::json_abi_v3_12_0::basic_json<nlohmann::json_abi_v3_12_0::ordered_map, std::__1::vector, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, bool, long long, unsigned long long, double, std::__1::allocator, nlohmann::json_abi_v3_12_0::adl_serializer, std::__1::vector<unsigned char, std::__1::allocator<unsigned char>>, void> const&) function.h:319
    AtomicBot-ai#3 0x000100a2c938 in std::__1::__function::__func<common_chat_params_init_llama_3_x(minja::chat_template const&, templates_params const&, bool)::$_0::operator()(common_grammar_builder const&) const::'lambda'(nlohmann::json_abi_v3_12_0::basic_json<nlohmann::json_abi_v3_12_0::ordered_map, std::__1::vector, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, bool, long long, unsigned long long, double, std::__1::allocator, nlohmann::json_abi_v3_12_0::adl_serializer, std::__1::vector<unsigned char, std::__1::allocator<unsigned char>>, void> const&), std::__1::allocator<common_chat_params_init_llama_3_x(minja::chat_template const&, templates_params const&, bool)::$_0::operator()(common_grammar_builder const&) const::'lambda'(nlohmann::json_abi_v3_12_0::basic_json<nlohmann::json_abi_v3_12_0::ordered_map, std::__1::vector, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, bool, long long, unsigned long long, double, std::__1::allocator, nlohmann::json_abi_v3_12_0::adl_serializer, std::__1::vector<unsigned char, std::__1::allocator<unsigned char>>, void> const&)>, void (nlohmann::json_abi_v3_12_0::basic_json<nlohmann::json_abi_v3_12_0::ordered_map, std::__1::vector, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, bool, long long, unsigned long long, double, std::__1::allocator, nlohmann::json_abi_v3_12_0::adl_serializer, std::__1::vector<unsigned char, std::__1::allocator<unsigned char>>, void> const&)>::operator()(nlohmann::json_abi_v3_12_0::basic_json<nlohmann::json_abi_v3_12_0::ordered_map, std::__1::vector, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, bool, long long, unsigned long long, double, std::__1::allocator, nlohmann::json_abi_v3_12_0::adl_serializer, std::__1::vector<unsigned char, std::__1::allocator<unsigned char>>, void> const&) function.h:319
    AtomicBot-ai#4 0x000100a139f8 in foreach_function(nlohmann::json_abi_v3_12_0::basic_json<nlohmann::json_abi_v3_12_0::ordered_map, std::__1::vector, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, bool, long long, unsigned long long, double, std::__1::allocator, nlohmann::json_abi_v3_12_0::adl_serializer, std::__1::vector<unsigned char, std::__1::allocator<unsigned char>>, void> const&, std::__1::function<void (nlohmann::json_abi_v3_12_0::basic_json<nlohmann::json_abi_v3_12_0::ordered_map, std::__1::vector, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, bool, long long, unsigned long long, double, std::__1::allocator, nlohmann::json_abi_v3_12_0::adl_serializer, std::__1::vector<unsigned char, std::__1::allocator<unsigned char>>, void> const&)> const&) chat.cpp:762
    AtomicBot-ai#5 0x000100a2a7f4 in std::__1::__function::__func<common_chat_params_init_llama_3_x(minja::chat_template const&, templates_params const&, bool)::$_0, std::__1::allocator<common_chat_params_init_llama_3_x(minja::chat_template const&, templates_params const&, bool)::$_0>, void (common_grammar_builder const&)>::operator()(common_grammar_builder const&) function.h:319
    AtomicBot-ai#6 0x000100aa98f4 in build_grammar(std::__1::function<void (common_grammar_builder const&)> const&, common_grammar_options const&) json-schema-to-grammar.cpp:982
    AtomicBot-ai#7 0x0001009c9314 in common_chat_params_init_llama_3_x(minja::chat_template const&, templates_params const&, bool) chat.cpp:1110
    AtomicBot-ai#8 0x0001009b8afc in common_chat_templates_apply_jinja(common_chat_templates const*, common_chat_templates_inputs const&) chat.cpp:1992
    AtomicBot-ai#9 0x0001009b533c in common_chat_templates_apply(common_chat_templates const*, common_chat_templates_inputs const&) chat.cpp:2074
    AtomicBot-ai#10 0x000100810120 in llamacpp_apply_chat_template+0x724 (predict_oai-98384e17fb94e863:arm64+0x100090120)
    ...

==45482==Register values:
 x[0] = 0x00006020004147f8   x[1] = 0x00006080000013c8   x[2] = 0x0000000000000000   x[3] = 0x0000604006289738
 x[4] = 0x0000000000000002   x[5] = 0x0000000000000001   x[6] = 0x04034000004b4000   x[7] = 0x0000000000000001
 x[8] = 0xbebebebebebebebe   x[9] = 0x17d7d7d7d7d7d7d7  x[10] = 0x00000c04000828ff  x[11] = 0x0000000000000001
x[12] = 0x000000002018d383  x[13] = 0x0000000000000000  x[14] = 0xfa0000000000fafa  x[15] = 0x000010700001ffff
x[16] = 0x000000019dc012c0  x[17] = 0x00000001021284f8  x[18] = 0x0000000000000000  x[19] = 0x00000001700acdc0
x[20] = 0x0000000000000002  x[21] = 0x000000002018d384  x[22] = 0x16dd16fd2e731151  x[23] = 0x0000007000020000
x[24] = 0x0000000100c69c08  x[25] = 0x0000000100c69c20  x[26] = 0x00006080000013c7  x[27] = 0x0000000100c69c00
x[28] = 0x00000001700acd60     fp = 0x00000001700aceb0     lr = 0x0000000100abce30     sp = 0x00000001700acd60
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV __hash_table:1565 in std::__1::pair<std::__1::__hash_iterator<std::__1::__hash_node<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, void*>*>, bool> std::__1::__hash_table<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::hash<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>, std::__1::equal_to<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>>::__emplace_unique_key_args<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&)
Thread T5 created by T0 here:
    #0 0x0001020b99d4 in pthread_create+0x5c (libclang_rt.asan_osx_dynamic.dylib:arm64e+0x359d4)
    AtomicBot-ai#1 0x000100873910 in std::sys::pal::unix::thread::Thread::new::h77254fdd87a28e05+0x118 (predict_oai-98384e17fb94e863:arm64+0x1000f3910)
    AtomicBot-ai#2 0x0001007c7a1c in test::run_test::haeb3c2bcd5ed6cf6+0x76c (predict_oai-98384e17fb94e863:arm64+0x100047a1c)
    AtomicBot-ai#3 0x0001007aedb0 in test::console::run_tests_console::he9d142d704f3a986+0x149c (predict_oai-98384e17fb94e863:arm64+0x10002edb0)
    AtomicBot-ai#4 0x0001007c5758 in test::test_main::hf86a5e20735245b9+0x118 (predict_oai-98384e17fb94e863:arm64+0x100045758)
    AtomicBot-ai#5 0x0001007c5da0 in test::test_main_static::h61ee9c8fd30abca0+0x54 (predict_oai-98384e17fb94e863:arm64+0x100045da0)
    ...

==45482==ABORTING
fukuro-kun pushed a commit to fukuro-kun/fukuro-llama-cpp-turboquant that referenced this pull request Jul 5, 2026
* Add buffer label and enable dawn-specific toggles to turn off some checks

* Minor set_rows optimization (AtomicBot-ai#4)

* updated optimization, fixed errors

* non vectorized version now dispatches one thread per element

* Simplify

* Change logic for set_rows pipelines

---------

Co-authored-by: Neha Abbas <nehaabbas@macbookpro.lan>
Co-authored-by: Neha Abbas <nehaabbas@ReeseLevines-MacBook-Pro.local>
Co-authored-by: Reese Levine <reeselevine1@gmail.com>

* Comment on dawn toggles

* Remove some comments

* Implement overlap binary operators

* Revert "Implement overlap binary operators"

This reverts commit ed710b3.

* Disable support for non-contiguous binary_op tensors and leave note for future support

---------

Co-authored-by: neha-ha <137219201+neha-ha@users.noreply.github.com>
Co-authored-by: Neha Abbas <nehaabbas@macbookpro.lan>
Co-authored-by: Neha Abbas <nehaabbas@ReeseLevines-MacBook-Pro.local>
fukuro-kun pushed a commit to fukuro-kun/fukuro-llama-cpp-turboquant that referenced this pull request Jul 5, 2026
* Faster tensors (AtomicBot-ai#8)

Add fast matrix and matrix/vector multiplication.

* Use map for shader replacements instead of pair of strings

* Wasm (AtomicBot-ai#9)

* webgpu : fix build on emscripten

* more debugging stuff

* test-backend-ops: force single thread on wasm

* fix single-thread case for init_tensor_uniform

* use jspi

* add pthread

* test: remember to set n_thread for cpu backend

* Add buffer label and enable dawn-specific toggles to turn off some checks

* Intermediate state

* Fast working f16/f32 vec4

* Working float fast mul mat

* Clean up naming of mul_mat to match logical model, start work on q mul_mat

* Setup for subgroup matrix mat mul

* Basic working subgroup matrix

* Working subgroup matrix tiling

* Handle weirder sg matrix sizes (but still % sg matrix size)

* Working start to gemv

* working f16 accumulation with shared memory staging

* Print out available subgroup matrix configurations

* Vectorize dst stores for sg matrix shader

* Gemv working scalar

* Minor set_rows optimization (AtomicBot-ai#4)

* updated optimization, fixed errors

* non vectorized version now dispatches one thread per element

* Simplify

* Change logic for set_rows pipelines

---------

Co-authored-by: Neha Abbas <nehaabbas@macbookpro.lan>
Co-authored-by: Neha Abbas <nehaabbas@ReeseLevines-MacBook-Pro.local>
Co-authored-by: Reese Levine <reeselevine1@gmail.com>

* Comment on dawn toggles

* Working subgroup matrix code for (semi)generic sizes

* Remove some comments

* Cleanup code

* Update dawn version and move to portable subgroup size

* Try to fix new dawn release

* Update subgroup size comment

* Only check for subgroup matrix configs if they are supported

* Add toggles for subgroup matrix/f16 support on nvidia+vulkan

* Make row/col naming consistent

* Refactor shared memory loading

* Move sg matrix stores to correct file

* Working q4_0

* Formatting

* Work with emscripten builds

* Fix test-backend-ops emscripten for f16/quantized types

* Use emscripten memory64 to support get_memory

* Add build flags and try ci

---------

Co-authored-by: Xuan Son Nguyen <son@huggingface.co>

* Remove extra whitespace

* Move wasm single-thread logic out of test-backend-ops for cpu backend

* Disable multiple threads for emscripten single-thread builds in ggml_graph_plan

* Fix .gitignore

* Add memory64 option and remove unneeded macros for setting threads to 1

---------

Co-authored-by: Xuan Son Nguyen <son@huggingface.co>
fukuro-kun pushed a commit to fukuro-kun/fukuro-llama-cpp-turboquant that referenced this pull request Jul 5, 2026
* FlashAttention (AtomicBot-ai#13)

* Add inplace softmax

* Move rms_norm to split row approach

* Update debug for supports_op

* clean up debug statements

* neg f16xf32xip builds and runs, havent actually ran a model that uses neg kernel yet though

* neg passes backend test

* unary operators pass ggml tests

* rms_norm double declaration bug atoned

* abides by editor-config

* removed vestigial files

* fixed autoconfig

* All operators (inlcluding xielu) working

* removed unnecesarry checking if node->src[1] exists for unary operators

* responded and dealt with PR comments

* implemented REPL_Template support and removed bug in unary operators kernel

* formatted embed wgsl and ggml-webgpu.cpp

* Faster tensors (AtomicBot-ai#8)

Add fast matrix and matrix/vector multiplication.

* Use map for shader replacements instead of pair of strings

* Wasm (AtomicBot-ai#9)

* webgpu : fix build on emscripten

* more debugging stuff

* test-backend-ops: force single thread on wasm

* fix single-thread case for init_tensor_uniform

* use jspi

* add pthread

* test: remember to set n_thread for cpu backend

* Add buffer label and enable dawn-specific toggles to turn off some checks

* Intermediate state

* Fast working f16/f32 vec4

* Working float fast mul mat

* Clean up naming of mul_mat to match logical model, start work on q mul_mat

* Setup for subgroup matrix mat mul

* Basic working subgroup matrix

* Working subgroup matrix tiling

* Handle weirder sg matrix sizes (but still % sg matrix size)

* Working start to gemv

* working f16 accumulation with shared memory staging

* Print out available subgroup matrix configurations

* Vectorize dst stores for sg matrix shader

* Gemv working scalar

* Minor set_rows optimization (AtomicBot-ai#4)

* updated optimization, fixed errors

* non vectorized version now dispatches one thread per element

* Simplify

* Change logic for set_rows pipelines

---------

Co-authored-by: Neha Abbas <nehaabbas@macbookpro.lan>
Co-authored-by: Neha Abbas <nehaabbas@ReeseLevines-MacBook-Pro.local>
Co-authored-by: Reese Levine <reeselevine1@gmail.com>

* Comment on dawn toggles

* Working subgroup matrix code for (semi)generic sizes

* Remove some comments

* Cleanup code

* Update dawn version and move to portable subgroup size

* Try to fix new dawn release

* Update subgroup size comment

* Only check for subgroup matrix configs if they are supported

* Add toggles for subgroup matrix/f16 support on nvidia+vulkan

* Make row/col naming consistent

* Refactor shared memory loading

* Move sg matrix stores to correct file

* Working q4_0

* Formatting

* Work with emscripten builds

* Fix test-backend-ops emscripten for f16/quantized types

* Use emscripten memory64 to support get_memory

* Add build flags and try ci

---------

Co-authored-by: Xuan Son Nguyen <son@huggingface.co>

* Remove extra whitespace

* Move wasm single-thread logic out of test-backend-ops for cpu backend

* Disable multiple threads for emscripten single-thread builds in ggml_graph_plan

* Refactored pipelines and workgroup calculations (AtomicBot-ai#10)

* refactored pipelines

* refactored workgroup calculation

* removed commented out block of prior maps

* Clean up ceiling division pattern

---------

Co-authored-by: Neha Abbas <nehaabbas@eduroam-169-233-141-223.ucsc.edu>
Co-authored-by: Reese Levine <reeselevine1@gmail.com>

* Start work on flash attention

* Shader structure set up (many bugs still)

* debugging

* Working first test

* Working with head grouping, head sizes to 128, logit softcap, mask/sinks enabled, f32

* Generalize softmax to work with multiple subgroups, f16 accumulation, mask shared memory tiling

* Start work on integrating pre-wgsl

* Separate structs/initial shader compilation library into separate files

* Work on compilation choices for flashattention

* Work on subgroup matrix/tile size portability

* subgroup size agnostic online softmax

* Cleanups, quantization types

* more cleanup

* fix wasm build

* Refactor flashattention to increase parallelism, use direct loads for KV in somce cases

* Checkpoint

* formatting

* Update to account for default kv cache padding

* formatting shader

* Add workflow for ggml-ci webgpu

* Try passing absolute path to dawn in ggml-ci

* Avoid error on device destruction, add todos for proper cleanup

* Fix unused warning

* Forgot one parameter unused

* Move some flashattn computation to f32 for correctness
fukuro-kun pushed a commit to fukuro-kun/fukuro-llama-cpp-turboquant that referenced this pull request Jul 5, 2026
Complete experiment log:
  AtomicBot-ai#1  4-mag LUT:           15.1 at 8K (BEST, +38%)
  AtomicBot-ai#2  Batched extract:     13.7 (+25%)
  AtomicBot-ai#3  Inline FA block:     13.5 (I-cache pressure)
  AtomicBot-ai#4  Deferred norm:       12.9 (loses ILP)
  AtomicBot-ai#5  2-pair half2:        12.0 (ternary overhead)
  AtomicBot-ai#6  Select chain:        11.9 (branches kill)
  AtomicBot-ai#7  Bit-arithmetic:      11.6 (ALU too heavy)
  AtomicBot-ai#8  FMA branchless:      11.4 (ALU still too heavy)
  AtomicBot-ai#9  Named-reg ternary:   10.3 (branches worst)
  AtomicBot-ai#10 Main (8-LUT):        10.95 (baseline)
  AtomicBot-ai#11 Non-vec FA:          10.2 (wrong kernel)
  Ceiling:                 24.5 (no dequant)

Apple8 hardware truth:
  1 divergent constant read < 7 ALU ops (even with fma)
  Branches cost MORE than divergent constant reads
  Array indexing ALWAYS spills on Metal
  4 constant addresses is the sweet spot

The 4-mag LUT is the dequant-level ceiling on Apple Silicon.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: tturney@psyguard.ai
fukuro-kun pushed a commit to fukuro-kun/fukuro-llama-cpp-turboquant that referenced this pull request Jul 5, 2026
…oquant-kv-cache"

This reverts commit 065ef53, reversing
changes made to 7d1bd95.
fukuro-kun pushed a commit to fukuro-kun/fukuro-llama-cpp-turboquant that referenced this pull request Jul 5, 2026
HIP/ROCm: two crash fixes for TurboQuant KV cache on RDNA
fukuro-kun pushed a commit to fukuro-kun/fukuro-llama-cpp-turboquant that referenced this pull request Jul 12, 2026
Status nach Solo-Session 05:00-14:00:
- AtomicBot-ai#2 Tensor Split Regex ✅ angewendet
- AtomicBot-ai#5 GTT Size Tuning ✅ bereits konfiguriert
- AtomicBot-ai#4 n-gram Decoding ⏳ verfügbar, Benchmark ausstehend
- AtomicBot-ai#1 MTP Logits Copy ❌ 19 Konflikte, skipped
- AtomicBot-ai#6 MUL_MAT_ID Subgroup ❌ 23 Konflikte, revertiert
- AtomicBot-ai#7 Vulkan FA Refactor ⏭️ verschoben (abhängig von AtomicBot-ai#6)
- AtomicBot-ai#9 Vulkan Shmem-Staging ❌ PR closed, manuell portieren
fukuro-kun pushed a commit to fukuro-kun/fukuro-llama-cpp-turboquant that referenced this pull request Jul 12, 2026
AtomicBot-ai#4 n-gram Decoding Benchmark (E2B, Mars):
- Baseline: 39.2 t/s, ngram-mod: 39.1 t/s — kein Speedup
- Verfügbar für User, aber kein Default-Speedup auf kleinen Modellen

M1 Status: ✅ abgeschlossen (AtomicBot-ai#2AtomicBot-ai#4AtomicBot-ai#5AtomicBot-ai#1❌)
M2 Status: ⏳ blockiert (AtomicBot-ai#6AtomicBot-ai#7⏭️ AtomicBot-ai#9❌)
fukuro-kun pushed a commit to fukuro-kun/fukuro-llama-cpp-turboquant that referenced this pull request Jul 19, 2026
… maps (UAF, state leaks)

P0 AtomicBot-ai#1 (Use-After-Free): invalidate() cleared only role_base but left
blk_down_base/blk_down_kb/blk_pair_pool/blk_down_pool stale. After a host
buffer free, moe_cache_backfill_next() would build jobs reading from freed
memory. Now clears ALL per-blk pointers that point into the freed range and
resets pool indices to -1 for affected blocks.

P1 AtomicBot-ai#3 (State leaks on model unload): glu_learn, learn_gate_dst,
learn_up_dst, redirect, g_disc (seen/pending/stable_count/any_repeat) and
backfill cursor survived invalidate() — a new model loaded at the same
addresses would hit stale learned entries and pool decisions. All cleared
now.

P2 AtomicBot-ai#7: removed unused 'self' variable in moe_cache_begin(). Added comment
documenting the owner-lock limitation (P1 AtomicBot-ai#4: not reset on model reload —
acceptable for one-model-per-process, the common case).
fukuro-kun pushed a commit to fukuro-kun/fukuro-llama-cpp-turboquant that referenced this pull request Jul 19, 2026
…OADMAP TheTom#77-TheTom#87

4 parallele Subagents (Vulkan/AMD, CUDA/MoE, arXiv, Multi-GPU/Batching).
26 neue Ansätze identifiziert, davon 3 Tier 1 Quick Wins (TheTom#77-TheTom#79),
8 Tier 2 (TheTom#80-TheTom#87), 10 Tier 3, 5 Tier 4. Verifiziert: PR ggml-org#23056 und
ggml-org#16829 bereits im Fork. Top-Empfehlungen: K-Quant MMVQ Fix (TheTom#77),
GEAR (TheTom#80), PEARL (TheTom#81), Fiddler (TheTom#82), Vulkan Pipeline Cache (TheTom#78).
fukuro-kun pushed a commit to fukuro-kun/fukuro-llama-cpp-turboquant that referenced this pull request Jul 22, 2026
P1 AtomicBot-ai#1: /cancel false-positive bei nicht-existierender task_id
  - METRICS-Check jetzt für ALLE task_ids (nicht nur bei leerem Body)
  - task_id wird gegen laufende Slots validiert vor Cancel-Post
  - Nicht-existierende task_id → {cancelled: false, error: 'task not found'}
  - Leerer Body ohne laufende Tasks → {cancelled: false, message: 'no running tasks'}
  - Zusätzlich: ältester Task (nach start_time) statt niedrigster Slot-Index

P1 AtomicBot-ai#2: ggml_backend_cuda_device_reset thread-safety
  - device_mutex Lock hinzugefügt (wie ggml_backend_cuda_device_get_memory)
  - active_count > 0 → Reset verweigert (verhindert Context-Crash)
  - cudaGetLastError-Details in GGML_LOG_WARN

P1 AtomicBot-ai#3: Test-Skript — Cancel-Wirkung verifiziert
  - Test 3: Stream muss abgebrochen sein (aborted=True oder wenige chunks)
  - Test 3b neu: nicht-existierende task_id → cancelled=false + error
  - Test akzeptiert nicht mehr normal beendeten Stream als Erfolg

P1 AtomicBot-ai#4: dev_reset Rückgabewert nicht ignorieren
  - SRV_WRN bei fehlgeschlagenem Reset mit Device-Name

P2 AtomicBot-ai#7: proxy_post try/catch bei leerem/ungültigem Body
  - Statt 500-Exception → 400 'Invalid JSON body'
  - res_err() statt nicht-existenter .error() Methode

P2 AtomicBot-ai#8: Ältester Task statt niedrigster Slot-Index (in P1 AtomicBot-ai#1 fix enthalten)
fukuro-kun pushed a commit to fukuro-kun/fukuro-llama-cpp-turboquant that referenced this pull request Jul 22, 2026
…ging, cstdint

P1 AtomicBot-ai#1: start_time Feld in server_slot::to_json() hinzugefügt
  - t_start_process_prompt (int64_t, Mikrosekunden) als 'start_time' exportiert
  - post_cancel liest jetzt int64_t statt int — kein Überlauf mehr
  - Ältester-Task-Auswahl funktioniert jetzt tatsächlich (vorher immer 0 → erster Slot)

P1 AtomicBot-ai#2: dev_reset failure — Kommentar erklärt warum Sleep trotzdem betreten wird
  - Modell ist bereits zerstört wenn Reset fehlschlägt → Abbruch = unrecoverable
  - load_model() beim Aufwecken wird OOM-failen wenn VRAM noch belegt → geloggt

P1 AtomicBot-ai#3: cudaSetDevice Fehlerlogging mit cudaGetLastError() korrigiert
  - Return-Wert von cudaSetDevice prüfen, cudaGetLastError() für Fehlermeldung
  - Vorher: cudaGetLastError() konnte veralteten/no-error Zustand loggen

P2 AtomicBot-ai#4: <cstdint> explizit inkludiert für INT64_MAX (portabilität)
fukuro-kun pushed a commit to fukuro-kun/fukuro-llama-cpp-turboquant that referenced this pull request Aug 2, 2026
…ne, invalidate

P1 AtomicBot-ai#1: Set-assoc lookup erkennt jetzt queued-Slots (key match bei
queued=true) → kein Duplikat-Insert mehr im selben Set. Backfill
entsprechend angepasst.
P1 AtomicBot-ai#2: Workload window reset off-by-one — reset nach wsize Aufrufen,
nicht am Start des wsize-ten Aufrufs.
P1 AtomicBot-ai#4: invalidate() cleart jetzt set_lru_head/tail/n_used und
window_count in allen Pools (wie trim() es schon tut).
P1 AtomicBot-ai#5: Kommentar 'Aufrunden' → 'Abrunden' (korrigiert).

Review: review-swe Subagent, 5 P1 + 7 P2 Issues gefunden.
P1 AtomicBot-ai#3 (pool-init locking) ist bestehendes Problem, nicht neu.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants