100 Commits
Author SHA1 Message Date
KawrakowandGitHub fbcc743c70 Fix race in indexer topk on CUDA (#2148) 2026-07-17 18:08:18 +03:00
a5b130389b Fix build on macOS (#2137)
* Fix build on macOS

* Add forgotten check

---------

Co-authored-by: Iwan Kawrakow <iwan.kawrakow@gmail.com>
2026-07-17 14:05:55 +03:00
KawrakowandGitHub 1fddd12ba8 New op: ggml_sum_rows_ext (#2132)
* Add ggml_sum_rows_ext

* openPangu: use ggml_sum_rows_ext also in mhc_post

* openPangu: use ggml_sum_rows_ext also in mhc_tail

* Minor
2026-07-15 16:21:17 +03:00
Kawrakow 7937465ff1 Compiler warning 2026-07-13 10:34:26 +00:00
KawrakowandGitHub 593a196f78 DSA: Better way to build the attention mask (#2119)
* WIP: indexer_topk on CUDA

* Forgot these

* WIP

* WIP

* This seems to work

* Minor

* Fix bug. Fix suggested by @sayap using GLM-5.2

* GLM-DSA: much better PP long context performance (CUDA)

* DSA: Better way to build the attention mask
2026-07-13 13:28:05 +03:00
KawrakowandGitHub 0d5d1330e2 GLM-DSA: much better PP long context performance (CUDA) (#2109)
* WIP: indexer_topk on CUDA

* Forgot these

* WIP

* WIP

* This seems to work

* Minor

* Fix bug. Fix suggested by @sayap using GLM-5.2

* GLM-DSA: much better PP long context performance (CUDA)
2026-07-12 19:33:33 +03:00
KawrakowandGitHub e913807605 Fused indexer top_k (CUDA) (#2103)
* WIP: indexer_topk on CUDA

* Forgot these

* WIP

* WIP

* This seems to work

* Minor

* Fix bug. Fix suggested by @sayap using GLM-5.2
2026-07-12 08:08:04 +03:00
KawrakowandGitHub 6d30fa2fe6 Fused indexer top_k (CPU only) (#2098)
* Indexer topk op - CPU only

We do save memory, but it is somehow much slower than what we have on
main.

* Make it a command line option
2026-07-09 18:04:41 +03:00
Kawrakow c2b58f88dd Compiler warnings 2026-07-09 09:18:26 +03:00
KawrakowandGitHub 5c2552b6e8 Fix #2093 (#2095) 2026-07-07 18:27:00 +02:00
Kawrakow 6c5f047a7c Update AUTHORS 2026-07-07 08:04:07 +00:00
KawrakowandGitHub 05cba319e0 GLM DSA: reduce indexer cache size (#2093) 2026-07-07 09:35:42 +02:00
KawrakowandGitHub ba62eaffe7 GLM-DSA: do not compute indexer score if context < n_top_k (#2090) 2026-07-07 09:33:55 +02:00
Kawrakow b569706eae Fix compiler warning 2026-07-06 11:44:27 +00:00
KawrakowandGitHub a0859ce5ed GLM-DSA: add ability to use quantized indexer cache (#2075)
* GLM-DSA: improve TG performance even more

* Fix crash when using MTP

* GLM-DSA: much better PP performance (CPU-only)

* GLM-DSA: allow for quantized indexer cache
2026-07-06 12:04:15 +02:00
KawrakowandGitHub eacd450d2b GLM-DSA: much better PP performance (CPU-only) (#2074)
* GLM-DSA: much better PP performance (CPU-only)

* Cleanup
2026-07-06 11:57:40 +02:00
KawrakowandGitHub 4130ecc028 GLM-DSA: improve TG performance even more (#2068)
* GLM-DSA: improve TG performance even more

* Fix crash when using MTP

* Fix the fix
2026-07-06 11:15:54 +02:00
KawrakowandGitHub bbc7de4751 Fix Windows build after CUB addition (#2076) 2026-07-03 18:40:20 +02:00
KawrakowandGitHub dbe2ecbe47 GLM-DSA: improve TG performance (#2067) 2026-07-02 15:43:58 +02:00
KawrakowandGitHub 84f7631a9a GLM-DSA: minor optimization (#2066) 2026-07-02 11:12:20 +02:00
KawrakowandGitHub f74a6fb87b Bump GGML_MAX_SRC to 16 (#2055) 2026-06-29 15:38:02 +02:00
KawrakowandGitHub adefdb4b98 Adjust split context for layer (#2054) 2026-06-29 15:09:40 +02:00
843a939441 Restore original PR #2047 (#2053)
* Split mode graph for GLM4MoE MTP in split_mode_tensor_parallel

Analogous to what was done for Qwen35 dense MTP in PR 2027:

- ctx_for_layer_split(): return buft_matrix for GLM4_MOE MTP tail
  layers instead of buft, so split tensor preparation uses the
  correct split context.

- create_glm4_moe_tensors(): remove the ctx_split = ctx_layer
  override for MTP tail layers. ctx_for_layer_split(i) now
  returns buft_matrix for GLM4_MOE MTP tails, so regular layer
  tensors (attn, ffn) are created in the split context. NextN
  tensors (eh_proj, enorm, hnorm, shared_head_head,
  shared_head_norm) stay monolithic via ctx_for_layer().

- create_tensors(): add LLM_ARCH_GLM4_MOE to the MTP tail
  layer splitting exclusion so split processing visits them.

- build_glm4_moe_mtp(): pass inp_out_ids to build_std_attention
  instead of post-processing with ggml_get_rows. Use build_output
  for the output projection to properly handle split mode.

- build_output(): add LLM_ARCH_GLM4_MOE to the is_qwen_mtp
  check to ensure MTP output is properly materialized.

* Skip loading shared_head_head for GLM4MoE MTP

Add TENSOR_SKIP flag to shared_head_head so it is never loaded, even
when present in the GGUF file. The graph code already falls back to
model.output when shared_head_head is nullptr (line 375-376), which
frees ~306 MiB on CUDA0 for models that include this tensor (e.g.,
GLM-Steam-106B). The 355B GLM-4.6 model does not have this tensor and
already uses the same fallback path.

* cuda-graph: GLM4_MOE - Don't load layer.nextn.embed_tokens

---------

Co-authored-by: Nexesenex <124105151+Nexesenex@users.noreply.github.com>
2026-06-29 14:55:59 +02:00
KawrakowandGitHub f96eaddba8 Revert DFlash SWA optimization (#2039) 2026-06-26 11:00:09 +02:00
KawrakowandGitHub 1255b1e479 Minor DFlash tweaks (#2034) 2026-06-26 10:31:03 +02:00
KawrakowandGitHub b84902d2ad Split mode graph for dense Qwen35 MTP (#2027)
* WIP: Split mode graph for Gemma4 assistant

Something is not right - acceptance drops to nearly zero.

* Per model CUDA contexts

Still not working!?

* This works

The issue was that I was not correctly calculating the number
of KV heads for the split KV cache.

* Compiler warnings

* It is better to use llama_context pointers as keys

* Split mode graph for dense Qwen35 MTP
2026-06-25 11:12:22 +02:00
KawrakowandGitHub d5507e33ae Split mode graph for dense Gemma4 assistant (#2022)
* WIP: Split mode graph for Gemma4 assistant

Something is not right - acceptance drops to nearly zero.

* Per model CUDA contexts

Still not working!?

* This works

The issue was that I was not correctly calculating the number
of KV heads for the split KV cache.

* Compiler warnings

* It is better to use llama_context pointers as keys
2026-06-24 18:29:32 +02:00
KawrakowandGitHub bf23a7599c Avoid Gemma4 assistant strange tensor name warnings (#2023) 2026-06-24 11:23:22 +02:00
KawrakowandGitHub d47f484d29 Force Gemma4 assistant to be loaded on last GPU (#1999)
* Allow graph reuse for Gemma4 MTP

* Force Gemma4 assistant to be loaded on last GPU
2026-06-19 18:17:13 +02:00
KawrakowandGitHub 8369cf7412 Allow graph reuse for Gemma4 MTP (#1996) 2026-06-19 18:16:53 +02:00
KawrakowandGitHub b21653a56f Fully remove any BLAS remnants (#2001)
* Fully remove any BLAS remnants

* Also these
2026-06-19 17:26:09 +02:00
KawrakowandGitHub 4bcfe5b872 Add compatibility for llama.cpp Gemma4 assistant GGUFs (#1995) 2026-06-19 11:24:54 +02:00
KawrakowandGitHub 7321648844 Fix Gemma4 MTP compute graph (#1993)
* Fix MTP warmup for GLM models

* Fix Gemma4 MTP compute graph
2026-06-19 09:00:44 +02:00
KawrakowandGitHub 0d59973e4a Fix MTP warmup for GLM models (#1992) 2026-06-19 08:59:55 +02:00
Kawrakow 3b81f63acd Update AUTHORS 2026-06-18 08:11:41 +00:00
f5e5753c32 Fix Qwen35 mtp warmup (#1987)
* Use hidden state from prev token from qwen mtp

* Fix Qwen35 MTP warmup

* Cleanup + remove unnecessary crippling performance by not using accept to sample draft token

* Provide API to gtet the model arch string

---------

Co-authored-by: SamuelOliveirads <samueloliveira32df@gmail.com>
2026-06-18 09:03:40 +02:00
KawrakowandGitHub 71af16a6b7 Fix DFlash oerformance with split mode graph (#1980) 2026-06-17 18:40:02 +02:00
KawrakowandGitHub 8420f91ae3 Merge pull request #1977 from ikawrakow/ik/dflash_fix_cpu
Fix DFlash on the CPU
2026-06-16 15:26:23 +02:00
Kawrakow 6f45163a95 Fix DFlash on the CPU 2026-06-16 13:22:36 +00:00
KawrakowandGitHub f9078e169b Merge pull request #1970 from SamuelOliveirads/feat/dflash-implementation
Add DFlash support
2026-06-16 15:07:55 +02:00
KawrakowandGitHub 11c9935ce8 Merge pull request #1893 from ikawrakow/ik/gemma4_mtmd_blindness
Fix Gemma4 vision
2026-06-16 07:47:37 +02:00
KawrakowandGitHub 2f524850a1 Merge pull request #1973 from ikawrakow/ik/fattn_mma_gqa_16
CUDA FA: faster TG when GQA is 16 and head size is 128
2026-06-15 15:24:01 +02:00
KawrakowandGitHub 37ea89cabf Merge pull request #1974 from Nexesenex/fix_muge_crash_minimax_m3
Fix Minimax M3 crash when -muge merges up/gate experts
2026-06-15 15:07:49 +02:00
Kawrakow 6be3a488d3 CUDA FA: faster TG when GQA is 16 and head size is 128 2026-06-15 11:46:02 +00:00
KawrakowandGitHub f81673c7db Merge pull request #1972 from ikawrakow/ik/minimaxm3_smgraph
Split mode graph for MiniMax-M3
2026-06-15 13:44:19 +02:00
KawrakowandGitHub e927adc4ad Merge pull request #1969 from Farmadupe/resize_algo_fix
Correct image resize algorithm for all qwens after qwen2vl and gemma4
2026-06-15 13:39:11 +02:00
KawrakowandGitHub 00d96744de Merge pull request #1967 from Farmadupe/stb_image_resize2
Replace image resizers with avx2/neon simd impls from stb_img_resize2.h
2026-06-15 13:38:31 +02:00
KawrakowandGitHub 1dc4ea938a Merge pull request #1962 from ikawrakow/ik/fix_1961
Fix #1961
2026-06-15 13:00:27 +02:00
Kawrakow c24d50dd88 Split mode graph for MiniMax-M3 2026-06-15 08:41:34 +00:00
KawrakowandGitHub 567854aeab Merge pull request #1963 from jkyamog/minimax-m3-support
Add preliminary MiniMax-M3 support
2026-06-15 10:16:10 +02:00
KawrakowandGitHub 4f1ec69ae5 Merge pull request #1965 from Nexesenex/fix_q8_0_graph_reduce_type
CUDA: Fix Q8_0 graph reduce type
2026-06-14 16:32:48 +02:00
Kawrakow c73bfbe9ce Fix #1961 2026-06-14 07:42:39 +00:00
KawrakowandGitHub 670a3f6f5b Merge pull request #1960 from BeccaLabs/fix/rpc-device-init
fix: initialize rpc_device endpoint and device index before parsing
2026-06-14 08:14:07 +02:00
KawrakowandGitHub 5f917a64b3 Merge pull request #1958 from ikawrakow/ik/handle_think_no_space 2026-06-12 21:27:23 +02:00
Kawrakow 175819b4fb Style 2026-06-12 06:19:06 +00:00
Kawrakow 3dbc3241b9 Handle forced-open reasoning tag without trailing whitespace 2026-06-12 05:43:11 +00:00
KawrakowandGitHub 022bd00aab Optimize Cohere2-MoE graph parallel (#1948)
* Optimzie Cohere2-MoE graph parallel

* Minor
2026-06-11 07:26:42 +02:00
KawrakowandGitHub c0d25e8fa1 Gemma4 E2B/E4B tweaks (#1947)
* Gemma4 E2B/E4B tweaks

* A few more named nodes
2026-06-10 15:28:54 +02:00
KawrakowandGitHub e6f8112f3b Adjust CUDA FA kernel parameters for head size 512 on Turing (#1942) 2026-06-10 07:49:21 +02:00
KawrakowandGitHub 366e478cb6 Bug fixes (#1940)
* Bug fixes

* More
2026-06-10 07:45:49 +02:00
KawrakowandGitHub 2768b62515 Split mode graph for Laguna (#1939) 2026-06-09 10:13:30 +02:00
KawrakowandGitHub 11c3546235 Support for alternative Gemma4 assistant (#1937) 2026-06-09 09:30:12 +02:00
KawrakowandGitHub a38d29232d CPU FA: disable mask optimization (#1935) 2026-06-09 09:13:19 +02:00
KawrakowandGitHub eea6a82b25 Fix bf16 graph reduce type (#1938) 2026-06-08 16:51:05 +02:00
KawrakowandGitHub 1660459db5 CUDA FA: cover Gemma4-4B/2B assistant (#1934) 2026-06-08 08:18:26 +02:00
KawrakowandGitHub b50b0919d5 CPU FA: Check for empty attention mask (#1923) 2026-06-08 07:54:57 +02:00
KawrakowandGitHub 1b53a58bf9 Enable split mode graph for Gemma4-12B (#1922) 2026-06-05 10:59:22 +02:00
KawrakowandGitHub 4406e637b5 Split mode graph for Mellum (#1920) 2026-06-04 15:20:41 +02:00
KawrakowandGitHub 8960c5ba5e Add extra nodes when dealing with MLA and amb (#1899) 2026-05-29 15:17:24 +03:00
KawrakowandGitHub e75337fec3 quantize: add exception for Gemma4 (#1897) 2026-05-29 10:54:21 +03:00
6eff055a0c GLM-5 MTP (again) (#1890)
* wip: port MTP architecture

Ports the Multi-Token Prediction (MTP) architecture to the older `llama.cpp` codebase used by `ikllama`.

Changes include:
- Updating `llama_batch` to support `mtp_params`.
- Modifying `llama_decode_internal` (and `encode`) to handle MTP operations (Warmup, Update, Draft).
- Adding public APIs for MTP state management (`llama_set_draft_input_hidden_state`).
- Adapting the embedding extraction logic to skip MTP update passes.

* Refactors `server_slot` to support generic speculative decoding (MTP or Draft Model).

* core: enable hybrid outputs (logits + embeddings) for MTP support

* fix(mtp): correct KV-cache slot finding for updates

* fix(mtp): persist hidden states to prevent context corruption during drafting

* refactor(mtp): clean unused code

* fix(mtp): update server to new functions name

* fix(mtp): fix graph and save hidden state

* mtp: refactor integration, context params and kv cache search

* mtp: fix hidden state extraction and speculative acceptance flow

* server: fix MTP warmup for long prompts and reset token buffer

* llama: refactor MTP operation state to context parameters

* server: fix n_past calculation in MTP acceptance

* llama: fix mtp enable flags

* speculative: refactor MTP to use common_speculative interface

* context: remove unused signatures

* clip: fix deprecated enum-enum conversion warning

* common: fix format string crash in help message

* context: fix mtp activation logic

* llamat: always use the extracted embedding

* llama: get all embeddings to kv cache

* llama: revert logit to not run mtp for not supported arch

* llama: allocate all the n_outputs for MTP

* wip

* server-context: get only the last embedding for hidden state

* ggml-backend: fix array of bounds in debug build

* server-context: run mt kv update to each prompt batch

* revert segmentation fault fixes

* glm-mtp(feat): optimize graph embedding and recursive drafting

* glm5-mtp(feat): add glm 5 mtp logic

* glm-mtp: standardize the MTP graph

* glm 5 mtp: apply post-layer cvec

* glm 5 mtp: mark head as mandatory

* get normed embeddings for glm 5

* Fix GLM5 MTP

* GLM5 MTP: just reuse the layer attention implementation

* Make MTP work with split mode graph

---------

Co-authored-by: samuel <samueloliveira32df@gmail.com>
2026-05-28 18:14:12 +03:00
Kawrakow 6648aa2e6e Fix Gemma4 vision 2026-05-28 15:08:46 +00:00
KawrakowandGitHub 3bf7e836c2 Allow Hadamard transform for head sizes that are not power of 2 (#1883)
* Disable K Hadamard transform if K-head size is not a power of 2

* Allow Hadamard transform for head sizes that are not power of 2

* Give more details why Hadamard is not possible

* Arghh
2026-05-27 18:29:32 +03:00
KawrakowandGitHub d503b046f7 Fix GLM MTP with split mode graph (#1887)
* Fix crash with GLM and MTP

* Fix GLM MTP with split mode graph
2026-05-27 07:24:28 +03:00
KawrakowandGitHub 1f66f9912f Fix crash with GLM and MTP (#1885) 2026-05-27 07:24:05 +03:00
KawrakowandGitHub d2da6da05c Fix cache loading/saving for MLA models and split mode graph (#1884) 2026-05-26 17:07:40 +03:00
KawrakowandGitHub b4e1d916c5 Per GPU fit margin (#1872) 2026-05-25 08:16:45 +03:00
KawrakowandGitHub 0c45696db4 Minor logging cleanup (#1873) 2026-05-24 07:29:32 +03:00
KawrakowandGitHub 809a63bbb7 Fix MLA models with ngl < n_layer (#1870)
* Fix split mode graph with ngl < n_layer (MLA models)

* It is actually not related to split mode graph
2026-05-24 07:29:17 +03:00
KawrakowandGitHub a6bb509305 Fix split mode graph with ngl < n_layer (#1869) 2026-05-23 12:58:09 +03:00
KawrakowandGitHub 3f45ba9387 MTP tweaks 3 (#1862) 2026-05-23 07:23:20 +03:00
KawrakowandGitHub b3d39cff8b Fix split mode graph for Qwen35-MoE + MTP (#1861) 2026-05-22 09:23:53 +03:00
KawrakowandGitHub 48a55f74e4 Disable split mode graph for Qwen35-MoE when MTP is enabled (#1858) 2026-05-21 16:29:35 +03:00
KawrakowandGitHub 4b73de246b Fix crash with split mode graph and partial offload (#1857) 2026-05-21 13:36:01 +03:00
KawrakowandGitHub c5dc847d0a Fix Gemma4-E4B compute graph (#1855) 2026-05-21 12:46:28 +03:00
Kawrakow 3dd282358b Fix compiler warnings 2026-05-21 05:40:08 +00:00
KawrakowandGitHub 40254a51da Fix MTP when -no-gr is used (#1848) 2026-05-20 13:38:33 +03:00
Kawrakow eb597df91f Upate AUTHORS 2026-05-20 06:38:39 +00:00
KawrakowandGitHub 290935be79 Remove Makefile (#1847) 2026-05-20 09:14:28 +03:00
KawrakowandGitHub 6bb3ee3a32 Enable split mode graph for MLA models and partial offload (#1835) 2026-05-20 07:13:55 +03:00
KawrakowandGitHub 997c587a6c Fix #1837 (#1838) 2026-05-19 17:56:21 +03:00
Kawrakow 27d7a74389 Compiler warnings 2026-05-19 05:51:27 +00:00
KawrakowandGitHub 40aae0b6d8 Check for output_extra.weight when loading Gemma4 assistant models (#1817) 2026-05-18 08:17:05 +03:00
KawrakowandGitHub a407b9ca3d Fix Qwen3.6-MoE low MTP acceptance rate (#1815)
* Fix Qwen3.6-MoE low MTP acceptance rate

* Fix Gemma4 MTP
2026-05-18 07:26:17 +03:00
KawrakowandGitHub 0ab9bdf793 Fix Qwen3.5/3.6 MTP and -muge (#1816) 2026-05-17 17:14:47 +03:00
KawrakowandGitHub 1f8c603d9c Quantize: add extra output tensor for MTP (#1810)
* Quantize: add extra output tensor for MTP

* Consistently use --mtp-requantize-output-tensor
2026-05-17 13:59:56 +03:00
KawrakowandGitHub 3e573cfea6 MTP: option to use re-quantized output tensor for better TG performance (#1809)
* Option to use re-quantized output tensor for MTP

* Remove quantize extra output option

* Handle interleaved types
2026-05-16 14:40:18 +03:00
KawrakowandGitHub 5cc0d86c76 imatrix: use data for ffn_up when data for ffn_gate is missing (#1806) 2026-05-15 14:38:16 +03:00
KawrakowandGitHub 4e1851b01a imatrix: use data for ffn_up when data for ffn_gate is missing (#1805) 2026-05-15 07:28:34 +03:00
KawrakowandGitHub ba72890076 Faster imatrix (#1801)
* Faster imatrix on AVX2

* Slightly better
2026-05-15 07:15:16 +03:00