Commit Graph

600 Commits

Author SHA1 Message Date
Kawrakow 847e191936
Graph parallel for Gemma4 MoE (#1600)
* Use build_std_attention for Gemma4 when possible

It is possible for the 26b MoE and 31b dense models.
It is not possible for the E4B/E2B vaiants because they
don't have KV cache in each layer.

* Standardize Gemma4 dense ffn

* WIP: Gemma4 split mode graph

Runs but produces NaNs

* WIP: Gemma4 split mode graph

Runs but very high PPL. At least it is no longer NaN.

* WIP

* This works!

* Put attn_norm, attn_post_norm, ffn_norm, ffn_post_norm on all GPUs

* Fix crash when saving/loading KV cache

* WIP: split mode graph for Gemma4-MoE - crashes

* Split mode graph for Gemma4-MoE - this works

* Disable SWA optimization

Something goes wrong there

* Consolidate MoE and dense graph parallel
2026-04-09 14:07:29 +02:00
Kawrakow fac404509c
Enable Hadamard tranform for head size of 512 (#1598) 2026-04-08 12:04:38 +02:00
Nexes the Elder 0a6e4335f7
Little maintenance (#1579)
* Little maintenance

* llama-quantize : Add the missing items in the help

* Add GGML_MAX_CONTEXTS define in the general cmakelist.txt

* Make the KV cache (CPU) based warnings clearer

* Correct placement of GGML_MAX_CONTEXTS definition

* Revert wrong indents

This reverts commit d0728cbb6c6d4d6d8dc13f062e542d232647a38d.

* Moving the GGML_MAX_CONTEXTS definition to src/CMakeLists.txt

* Update warning message for unsupported KV cache types

* forgotten antislash
2026-04-08 07:58:49 +02:00
Kawrakow 67fc9c5eb9
Fix Gemma4 quantized KV cache CPU FA performance (#1590) 2026-04-06 19:36:55 +02:00
Kawrakow a22778b984
Fix Gemma4 quantized KV cache on CUDA (#1592) 2026-04-06 19:35:38 +02:00
Kawrakow 86e33fd6f4
Initial Gemma4 support (#1581)
* Gemma4: WIP

* Gemma4: WIP - runs with totally wrong results

* Gemma4: WIP - add CPU 512, 512 FA

* Gemma4: WIP

It gives a meaningful response in llama-cli, but PPL is still much too
high. Is this due to tokenizer issues?

* Gemma4: this works

I had forgotten the softcap on the final output.

* Remove log

* Gemma4: WIP E4B/E2B

* Gemma4: Q4B/E2B appear to work now

* gemma4: tokenizer fixes
2026-04-06 10:01:08 +02:00
Adam Caldwell 6d4cdef511
Optimize mul_mat_q8_1_r8_q8_2 with AVX-512 for faster Q4_K/Q5_K prompt processing (#1578)
Add HAVE_FANCY_SIMD path that processes 16 rows at a time using 512-bit
operations, combining two R8 groups via _mm512_inserti32x8. Reuses the
existing qx_r8_q8_dot_product 512-bit overload for the inner dot product.
Also updates num_rows for Q8_1 to 16 under HAVE_FANCY_SIMD.

Co-authored-by: Adam Caldwell <accaldwell@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-06 09:07:23 +02:00
Kawrakow 0147cf4837
Add additional explanations to the pinned memory log (#1582) 2026-04-04 08:53:58 +02:00
Kawrakow bc89aedd2b
Bonsai support (ARM_NEON) (#1571)
* Bonsai: ARM_NEON

* Bonsai: this is faster on AVX2

* Remove forgotten debug logs

---------

Co-authored-by: Iwan Kawrakow <iwan.kawrakow@gmail.com>
2026-04-03 08:29:15 +02:00
Kawrakow 90ec1b80c4
Bonsai support (AVX2, generic) (#1570)
* Bonsai support (AVX2, generic)

* Fix ARM build

---------

Co-authored-by: Iwan Kawrakow <iwan.kawrakow@gmail.com>
2026-04-02 16:54:08 +02:00
Kawrakow 73742c5db9
mtmd: be able to use alternative types for the K*Q multiplication (#1567)
* mtmd: allow using types other than f32 for K*Q

* Do not cast q if kq_type is quantized

* Fix formatting

* More formatting
2026-04-02 08:04:05 +02:00
Kawrakow 93c1e241d8
Fix BF16 mmproj on the CPU (#1564) 2026-04-01 09:17:58 +02:00
Kawrakow bc78a1e93b
CPU FA: check if types are supported (#1562) 2026-03-31 16:19:21 +02:00
Kawrakow bd7daa7176
Even better Q4_0 KV cache (CPU) (#1556) 2026-03-31 08:08:34 +02:00
Kawrakow b9a2ce4677
Even better Q4_0 KV cache (#1547) 2026-03-30 10:06:54 +02:00
Kawrakow bc2c74c9db
Add --fit to llama-bench (#1542) 2026-03-29 08:05:07 +02:00
Kawrakow 93ae47e167
Fix CUDA Hadamard transfrom bug (#1526) 2026-03-27 10:37:35 +01:00
Kawrakow 8ab016e2d5
Fix bug in CPU floash attention for bf16 KV cache (#1521) 2026-03-26 17:22:27 +01:00
Kawrakow 9eaf105ae8
Print info when allocating large amounts of pinned host memory (#1517) 2026-03-26 10:42:35 +01:00
Alec Koumjian aa7fdb3259
ggml-cuda: fix shared memory sizing in OpenAI argsort kernel (#1512) 2026-03-26 08:00:00 +01:00
Adam Caldwell 3c4a7d18bd
mul_mat_q8_0_r8_q8_2: combine first/second half dot products before float conversion (#1505)
Co-authored-by: Adam Caldwell <accaldwell@users.noreply.github.com>
2026-03-25 09:47:10 +01:00
Kawrakow 5451b149d4
Revert "Slightly better CPU performance for SWA models (#1496)" (#1503)
This reverts commit f4125e8b1f.
2026-03-25 07:20:34 +01:00
Kawrakow f4125e8b1f
Slightly better CPU performance for SWA models (#1496) 2026-03-24 07:53:16 +01:00
Adam Caldwell 47e4015337
Enable AVX-VNNI 256-bit path for Q3_K R4 matmul (#1472)
Add a separate HAVE_VNNI256 code path using _mm256_dpwssd_epi32 and
_mm256_dpbusd_epi32 for the Q3_K R4 kernel. The existing HAVE_FANCY_SIMD
(AVX-512 VNNI) path is preserved unchanged.

Co-authored-by: Adam Caldwell <accaldwell@users.noreply.github.com>
2026-03-23 09:47:29 +01:00
Kawrakow 3633a7cfca
Log HAVE_FANCY_SIMD via LLAMA_LOG_INFO (#1492) 2026-03-23 08:43:29 +01:00
Adam Caldwell 87e4b9260b
Enable AVX-VNNI 256-bit path for Q6_K R4 matmul (#1482)
Add a separate HAVE_VNNI256 code path using _mm256_dpwssd_epi32 and
_mm256_dpbusd_epi32 for the Q6_K R4 kernel. The existing HAVE_FANCY_SIMD
(AVX-512 VNNI) path is preserved unchanged.

Co-authored-by: Adam Caldwell <accaldwell@users.noreply.github.com>
2026-03-23 08:10:13 +01:00
Adam Caldwell ac4d6b94fb
Enable AVX-VNNI 256-bit path for IQ3_XXS and IQ3_S R4 matmul (#1474)
Co-authored-by: Adam Caldwell <accaldwell@users.noreply.github.com>
2026-03-20 16:12:07 +01:00
Adam Caldwell a56a7863c7
Enable AVX-VNNI 256-bit path for IQ4_NL R4 matmul (#1467)
Co-authored-by: Adam Caldwell <accaldwell@users.noreply.github.com>
2026-03-20 09:40:39 +01:00
Max Homilius 77f8060ca6
fix: FA vec kernels for D=256 quantized KV cache (e.g., Qwen3-Coder-Next) (#1452)
* fix: FA vec kernels for D=256 quantized KV cache

Three bugs prevented Flash Attention from working with quantized
(q8_0) KV cache on models with head dimension 256, such as
Qwen3-Coder-Next:

1. need_f16_K/V used dimension-based logic (Dk != 128) that forced
   q8_0→f16 conversion at D=256. The kernel then read f16 data as
   q8_0 blocks. Changed to type-based logic (type_K == GGML_TYPE_F16)
   matching mainline.

2. quantize_q8_1_to_shared output pointers were not advanced between
   loop iterations, so the second iteration overwrote the first half
   of Q data in shared memory. Added i0 offset to output pointers.

3. Q_i32 register array in vec_f32 kernel was sized to 1 instead of 2
   for D=256 due to an errant comparison (Dk >= expr evaluates to
   boolean 1, not expr). Removed the comparison.

Also adds extern template declarations for (256, Q8_0, Q8_0) so the
kernel is compiled and linked.

Tested on Pascal (GTX 1080, CC 6.1) with Qwen3-Coder-Next (D=256,
n_head_kv=2) using --cache-type-k q8_0 --cache-type-v q8_0.

* fix: use dimension-based need_f16 for D=256 vec kernels
2026-03-20 09:39:39 +01:00
Kawrakow b56a3c2dc9
Better barrier (#1456) 2026-03-19 07:33:00 +01:00
Adam Caldwell b8fa7936bf
Enable AVX-VNNI 256-bit path for Q8_K R8 matmul (#1460)
Use the sign trick with dpbusd instead of maddubs+madd+add,
replacing 3 AVX2 instructions with 1 fused VNNI instruction.
Removes dead HAVE_FANCY_SIMD code left over from the R16 split.

Co-authored-by: Adam Caldwell <accaldwell@users.noreply.github.com>
2026-03-19 06:56:11 +01:00
Kawrakow 1a7aa3e7fa
Fix potential integer overflow in the flash attention kernels (#1458) 2026-03-18 19:44:46 +01:00
Adam Caldwell 9015b6c51d
Enable AVX-VNNI 256-bit path for Q8_0 R8 dot product (#1459)
Replace maddubs_epi16 + madd_epi16 with dpbusd_epi32 in the
mul_mat_q8_0_r8_q8_2 dot product lambda when HAVE_VNNI256 is
defined. Same sign trick operands (abs(x), sign(y,x)), just
fewer instructions per sub-block.

Co-authored-by: Adam Caldwell <accaldwell@users.noreply.github.com>
2026-03-18 11:14:23 +01:00
Adam Caldwell 8ccb4f856c
Enable AVX-VNNI 256-bit path for Q8_1 R8 dot product (#1455)
Ungate the VNNI path in mul_mat_q8_1_r8_q8_2 by changing the
guard from HAVE_FANCY_SIMD to HAVE_VNNI256. This block only uses
256-bit intrinsics so it is safe for AVX-VNNI (non-512) CPUs.

Co-authored-by: Adam Caldwell <accaldwell@users.noreply.github.com>
2026-03-18 09:18:02 +01:00
Kawrakow 56477c7a9e
Mistral 4 support (#1450)
* WIP: mistral4

* CPU FA

* CUDA FA 320, 256
2026-03-18 07:32:39 +01:00
Kawrakow f6ca2fa8c0
Qwen-3.5/Next tweaks (#1447)
* Allow using -rtr and -muge together

* Various Qwen-3.5 tweaks

* No need to make v, g, beta contiguous

* Adjust NEON delta-net to non-contiguous v, g, b

* Cleanup

---------

Co-authored-by: Iwan Kawrakow <iwan.kawrakow@gmail.com>
2026-03-18 07:32:17 +01:00
Adam Caldwell 008125b5c1
Enable AVX-VNNI 256-bit path for Q4_K and Q5_K R4 matmul (#1446)
Add new CPU macro HAVE_VNNI256 for CPUs with 256-bit VNNI
(AVX-VNNI) support or better (AVX512-VNNI+VL), separate from
HAVE_FANCY_SIMD which requires the full AVX-512 set. Relax four
#ifdef guards in mul_mat_q4_k_r4_q8_k and mul_mat_q5_k_r4_q8_k
to use HAVE_VNNI256 instead of HAVE_FANCY_SIMD, enabling vpdpbusd
and cvtepi8_epi32 on Alder Lake, Raptor Lake, and similar CPUs.

Co-authored-by: Adam Caldwell <accaldwell@users.noreply.github.com>
2026-03-17 10:44:55 +01:00
Kawrakow e3f5f3d823
Minor delta-net tweaks (#1429) 2026-03-16 13:59:55 +01:00
Kawrakow 29e6d6b4c1
Check for overlap before fusing ssm_conv and silu (#1443) 2026-03-16 12:14:20 +01:00
Kawrakow 8075acb6cd
Turn off CPU ssm_conv and silu fusion (#1440) 2026-03-16 10:44:53 +01:00
Kawrakow f8d95f1279
Fused SSM_CONV and SILU on ARM_NEON (#1425)
Co-authored-by: Iwan Kawrakow <iwan.kawrakow@gmail.com>
2026-03-14 18:14:56 +01:00
Kawrakow aa053205e8
Faster fused_rms_norm on the CPU (#1427) 2026-03-14 16:33:34 +01:00
Kawrakow 46018f89ed
Fuse SILU and SSM_CONV (CPU) (#1421) 2026-03-14 08:27:32 +01:00
Kawrakow 7fab617684
Enable split mode graph for on-the-fly merged up/gate experts (#1413)
* Split mode graph for on-the-fly merged ffn_up/gate_exps

* Cleanup

* Also handle merged bias
2026-03-13 08:11:46 +01:00
Kawrakow c85361fe2f
Split mode graph for models with pre-merged ffn_up/ffn_gate experts (#1412)
* WIP: support pre-merged up/gate experts

Haha, mainline has elected to arrange the merged tensors
the other way around compared to what I had done in the on-the-fly merge.

* Change the order of on-the-fly packed up/gate

* OpenAI

* CUDA TG

* CPU

* Split mode graph for models with pre-merged ffn_up/ffn_gate experts
2026-03-12 17:26:48 +01:00
Kawrakow 5713d3b38b
Support models with merged up/gate experts (#1408)
* WIP: support pre-merged up/gate experts

Haha, mainline has elected to arrange the merged tensors
the other way around compared to what I had done in the on-the-fly merge.

* Change the order of on-the-fly packed up/gate

* OpenAI

* CUDA TG

* CPU
2026-03-12 09:25:57 +01:00
Kawrakow afa6439ac3
Faster convolution on AVX2 (#1400)
* Faster ssm_conv on AVX2

* Move the optimized ssm_conv to iqk

* Minor
2026-03-11 19:28:38 +01:00
Kawrakow bb45cc3c74
Arghh (#1397) 2026-03-10 18:28:35 +01:00
Kawrakow f90b4c2f27
Full graph parallel for Qwen3.5 (dense and MoE) (#1388)
* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

Loads and starts running, crashes with illegal memory access in
quantize_mmq_q8_1. This almost always indicates NaNs in the input
to the MoE FFN part.

* WIP

* WIP

Loads and runs, wrong results (very high PPL)
Performance looks promising, around 25% better than previous sm graph.
Needs f32 or bf16 graph reduce type.

* WIP - still wrong

* Fix after rebase

* WIP

* WIP

* This seems to be working for dense Qwen3.5!!!

* WIP: Qwen3-Next is not quite working

* Some cleanup

* Disable Qwen3-Next for now

* Disable graph parallel when mmproj was specified

* Read/write split recurrent state

* That should not crash

* Re-enable vision - it works now

* Recurrent layers should now be counted for split cache
2026-03-10 09:08:24 +01:00
Kawrakow 14492bfdd2
Make split mode graph work with vision enabled (#1392) 2026-03-10 06:56:39 +01:00