Commit Graph

28 Commits

Author SHA1 Message Date
Kawrakow 397150caa2
MTP: faster recurrent state restore (#1791)
* MTP: store ready per step convolution states

* Cleanup
2026-05-13 11:00:24 +03:00
Kawrakow cec1a6c1f5
MTP: Reuse graphs (again) (#1780) 2026-05-12 07:36:12 +03:00
Samuel Oliveira Alves be8435793e
Pre-allocate buffers for hybrid model checkpoints (#1774)
* hybrid-spec: improve recurrent checkpoint handling in speculative decoding

* change per-step save to support scheduling and asynchronous tensor operations

* remove redudant backend tensor fallback

* improve recurrent tensor handling for split graph
2026-05-12 07:21:25 +03:00
Kawrakow eb570eb966
MTP: Avoid per step SSM copy (#1778)
* Avoid copying the per-step SSM state (CUDA)

* Avoid copying the per-step SSM state (CPU)

* Allocate only what is necessary for per-step SSM state

* Cleanup
2026-05-11 18:15:55 +03:00
Kawrakow 3557b446f8
Avoid recurrent state copy (#1777) 2026-05-11 13:13:59 +03:00
Kawrakow 94940cd882
MTP: ebable per step recurrent state for split mode graph (#1773) 2026-05-11 12:40:04 +03:00
Kawrakow e722f0bb73
MTP tweaks (#1741) 2026-05-06 08:35:11 +03:00
Kawrakow 453a027c17
Revert "server: defer recurrent-state reset to graph build (addresses #1696 r…" (#1704)
This reverts commit fb05c2e9a2.
2026-04-28 12:33:34 +02:00
markaalonzo fb05c2e9a2
server: defer recurrent-state reset to graph build (addresses #1696 review) (#1696)
ikawrakow asked the seq_rm zeroing be hoisted out of the per-cell loop and
preferably done as part of the compute graph. This rewrites the fix:

  - llama_kv_cache gets a pending_recurrent_reset bitmap, sized to
    qnext_state_slots and indexed by slot index.
  - llama_kv_cache_seq_rm only marks the bitmap; no CPU-side tensor
    writes, no work inside the per-cell loop.
  - delta_net::build_layer_attn_linear ORs the bitmap into the existing
    reset_state flag, so the in-graph ggml_scale(state, 0.0f) path that
    already handled batch.pos[0] == 0 now also handles slot reset.
  - build_qwen3next and build_qwen35 clear the bitmap after
    ggml_build_forward_expand, once per graph build.
  - llama_kv_cache_clear also drops the bitmap, since the full-buffer
    clear it already does makes any pending in-graph reset redundant.

Previous behavior is preserved (every recurrent layer column for the
released slot is zeroed before the next request reuses it), but the work
moves from the CPU into the compute graph, runs once per graph instead
of once per cell, and reuses the existing reset path referenced in the
review.
2026-04-28 08:00:01 +02:00
Samuel Oliveira Alves ea94afe777
Speculative checkpoints for recurrent models (#1669)
* server: spec checkpoints for recurrent models

* fix: save/restore sampler state during speculative checkpoint

When speculative decoding rejects draft tokens and restores the
recurrent state checkpoint, the sampler (RNG, grammar, prev tokens)
must also be restored to maintain consistency. Without this, the
sampler state reflects the rejected draft tokens, leading to
potential divergence.

Uses common_sampler_clone() to snapshot the sampler before the
speculative batch decode, and restores it on rejection.

* server: snapshot recurrent state in tensor

* reset ngram mod state for rejected tokens

* server: refactor checkpoint state logic

* speculative: fix sampler for checkpoints

* recurrent model: implement recurrent kernel checkpoint

* recurrent model: refactor api

* spec: free rbudget before overwriting
2026-04-24 09:59:30 +02: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
Kawrakow e3f5f3d823
Minor delta-net tweaks (#1429) 2026-03-16 13:59:55 +01:00
Kawrakow 46018f89ed
Fuse SILU and SSM_CONV (CPU) (#1421) 2026-03-14 08:27:32 +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 277fc1d26f
Do not repeat yourself (#1373)
* DRY - part 1

* DRY - part 2

* DRY - part 3

* Fix NEON

---------

Co-authored-by: Iwan Kawrakow <iwan.kawrakow@gmail.com>
2026-03-06 16:06:51 +01:00
Kawrakow 082addead2
Minor: do not do SILU on the whole convolution output (#1374) 2026-03-06 16:06:34 +01:00
Kawrakow 8fb002207a
Fused delta-net (AVX512) (#1362) 2026-03-05 07:55:05 +01:00
Kawrakow 3735e88925
Remove unused tensors from delta-net (#1350) 2026-03-02 16:02:40 +01:00
Kawrakow a568e12c8f
Minor delta-net tweak (#1337) 2026-03-01 17:45:02 +01:00
Kawrakow 0ff3a43289
Bring back #1333 and #1335 (#1340)
* Bring back fused delta net 3

* Remove autoregressive and chunking
2026-02-28 14:31:42 +01:00
Kawrakow 1922449b2c
Revert delta net 3 (#1339)
* Revert "Simplify delta-net (#1335)"

This reverts commit e5fc30244c.

* Revert "Fused delta net 3 (#1333)"

This reverts commit 7b68353e09.
2026-02-28 13:12:08 +01:00
Kawrakow e5fc30244c
Simplify delta-net (#1335)
* Simplify delta-net

* Minor

* Minor
2026-02-28 11:12:19 +01:00
Kawrakow 7b68353e09
Fused delta net 3 (#1333)
* This is better than chunked

* Keep the state in registers

* Cleanup

* Remove unused stuff

* Minor

* Make fused delta-net the default

* Fix race
2026-02-27 15:02:56 +01:00
Kawrakow c77ec4b8b8
Fused delta-net (#1315)
* Revive fused delta-net

* Add command line argument for fused delta net

* Simplify/improve CUDA delta-net

* Add -fdn to llama-bench

* More CUDA fused delta net optimizations

* CPU optimizations

* Much faster fused delta-net on the CPU

It seems it is faster than the chunked implementation!

* Change meaning of fdn from bool flag to threshold value

* Use eps = 1e-6

* Give some nodes a name
2026-02-25 14:12:48 +01:00
Kawrakow 38ca19d828
Minor delta-net tweak (#1308)
* Make sure we pick the reduced tensor from the right GPU

* Minor

* Minor delta-net tweak
2026-02-24 15:22:57 +01:00
Kawrakow 5dacb5355a
Graph parallel for Qwen3-Next (#1292)
* WIP

* This works, but is slower than split mode layer
2026-02-23 07:58:00 +01:00
Kawrakow 13c3d83ce7
Qwen3.5-MoE support (#1288)
* WIP: loads and runs, but not correct

Very high PPL, empty TG.

* This appears to work
2026-02-21 08:33:06 +01:00
Kawrakow 04cf685e82
Factor out delta net (#1286)
* WIP: factor out delta net implementation

* WIP

* Use the standard FFN functions

* More standard attn for Qwen3-Next
2026-02-18 17:16:17 +01:00