Repository navigation
model : banded flash attention for the Inkling 2 relative bias - #386
danielhanchen wants to merge 100 commits into
Conversation
Hybrid attention model: 55 sliding-window plus 11 global layers, banded content-dependent relative position bias instead of RoPE, per-layer short convolution state, fine-grained MoE (256 experts top-6 plus 2 shared), attention log-scaling past 128K, 1M context. Includes the GGML_OP_FLASH_ATTN_EXT_BANDED operator (CPU and CUDA, fused into the MMA flash attention kernel with an fp16 accumulator overflow guard), HF to GGUF conversion, chat template with typed content block parsing (interleaved thinking, narration and tool calls), mmproj vision and audio support, and backend op tests at production shapes.
# Conflicts: # ggml/src/ggml-cuda/mmq.cuh # src/llama-model-saver.cpp # src/llama-vocab.h
Upstream 910196f renamed common_chat_params::thinking_end_tag to thinking_end_tags and changed it from std::string to a vector, so data.thinking_end_tag = END_MESSAGE no longer compiles.
# Conflicts: # src/llama-arch.cpp
# Conflicts: # ggml/include/ggml-rpc.h # ggml/src/ggml-backend-meta.cpp # ggml/src/ggml-cuda/ggml-cuda.cu # src/llama-model-saver.cpp # tests/test-llama-archs.cpp
# Conflicts: # src/llama-model.cpp
# Conflicts: # ggml/src/ggml-rpc/ggml-rpc.cpp
Resolves the two conflicts left by upstream ggml-org#27764 (chat parsers split into common/parsers) and ggml-org#26675 (ggml_prec rework): - common_chat_params_init_inkling moves to common/parsers/inkling.cpp, registered in parsers.h and sources.cmake; chat.cpp keeps only the template detection branch. - GGML_PREC_F32_PEDANTIC joins the new ranked ggml_prec scale at 5, below GGML_PREC_F32, since it is the stricter contract; ggml_flash_attn_ext_banded keeps its declaration next to the flash attention API.
…C_F32_PEDANTIC Every caller of the deprecated ggml_mul_mat_set_prec / ggml_flash_attn_ext_set_prec now uses ggml_prec_set_acc (the macOS prebuilt leg builds with LLAMA_FATAL_WARNINGS, so the deprecation would be fatal there), and ggml_prec_set_acc accepts GGML_OP_FLASH_ATTN_EXT_BANDED. With the enum ranked, the CUDA cuBLAS compute-type gate and the CPU, spacemit and Vulkan flash-attention accumulator checks compare by rank instead of equality with GGML_PREC_F32, so a pedantic request never falls through to a lower-precision path. The CUDA mul_mat_id slice carries the acc and src precision slots, and ggml_cuda_mul_mat_id_needs_sync applies the same pedantic gate as ggml_cuda_mul_mat_id so a pedantic F32 expert matmul cannot trip its assertion.
…own lines Inkling shared its n_embd_r() check, the FALCON_H1 hybrid-memory branch and the kv-cache context declaration with the line any new hybrid architecture also edits, so every such PR (Inkling 2 in ggml-org#32217 among them) conflicts with this one. Move each into its own block; behaviour is unchanged (RWKV never sets n_embd_r_impl, and the Inkling branch is the FALCON_H1 body).
#386 repin: ded02bd -> 8ee7920 (Inkling 2 banded attention for small ubatches and several sequences)8ee7920 is a fast-forward of ded02bd (the current #386 merge probe on b12668 / b12670). It adds ten commits, eight from two branches and two that keep #378 intact, and changes 13 files (+1332 / -58):
With #386 at 8ee7920 and the rest of unslothai master's pr-set, What it fixesBefore this, every ubatch of 2 to 32 tokens (DSpark verify batches, prompt tails), every ubatch of several sequences, and every SWA ubatch after the ring wrapped took the dense relative bias: n_kv x n_tokens x n_head in F32 plus F16 copies. The reserve sized the compute buffer for that at load (the 32-row dense reserve of 6510f1f, and a dense multi-sequence reserve). With quantized K/V, dense flash attention with 3 or more queries also converts the whole K/V view to F16, which is why q8_0 / q4_0 used more memory than f16 (1282 vs 770 MiB at 128K). Now all of those take the banded kernels. One sequence spans the padded n_kv with a shifted bias table, so graphs are still reused. Several sequences and wrapped caches pass the position of each cell and query. A new decode kernel reads F16, BF16, q8_0, q4_0, q4_1, q5_0, q5_1 and mixed q8_0-K / q4_0-V and q8_0-K / f16-V caches in place. Decode steps over f16 / bf16 / q8_0 / q4_0 caches stay on the dense flash attention path, so their output is unchanged. Decode steps over q4_1 / q5_0 / q5_1 / mixed caches, which dense CUDA flash attention converts to F16 every step, take the banded kernel in the full-attention layers. Memory (compute buffer, MiB, Inkling-2-Mini UD-IQ1_S, FA on)Before is the current pin set (b12651 mix). After is the same mix with this change (pins + both branches). Exit equals load in every cell. 1 slot:
4 slots, unified KV (
Quantized K/V gate: every quantized type is at or below f16 and below the pin set in every cell above. The one cell above f16 is mixed q8_0-K / f16-V, by 24 MiB at ub 512 and 96 MiB at ub 2048 (1 and 4 slots). A reserve-graph diff at 1M shows that the only extra nodes are the KV rotation that quantized K enables (48 Q-rotation and 48 K-rotation matmuls); the pin set carries the same term. Process GPU peak with DSpark (2 drafts, q4_0 draft K/V), UD-IQ2_XXS, 1 slot, -ub 512, prompt filling the cache, 128 generated tokens:
The memory outside the accounted buffers is the same before and after (about 2085 MiB at 128K, 7574 MiB at 1M), so decode and drafts make no F16 copy of a quantized cache. Kernel traces confirm it: with q4_1 / q5_0 / q5_1 K/V, 3- and 16-token ubatches launch 29184 and 5472 dequantize-to-F16 kernels before and none after. Prompt ubatches of more than 32 tokens with q4_1 / q5_x K/V still convert the cache to F16 in the banded MMA kernel, as before (about 4 GiB of pool at 1M); the process peak still stays below f16. Accuracy
DSparkDraft
SpeedExclusive B200, UD-IQ2_XXS, depth 131072, -ub 2048, run as pin set | this change | pin set. Ratio of this change to the mean of both pin-set runs; the pin set against itself shows the noise.
Decode with f16 / q8_0 / q4_0 caches is unchanged. Decode with q4_1 / q5_1 caches is 27 to 30% faster because the step no longer converts the cache to F16. Small cardsColab T4 (16 GB) and L4 (24 GB). Both trees were built on the VM from upstream b12651 plus the pin-set diff (before), then plus this change (after). UD-IQ3_XXS, q8_0 K/V,
On the T4 the pin set has to leave part of three layers' weights in host memory (about 860 MiB) to fit 128K; with this change the whole model fits on the card. L4, 4 slots,
The first T4 round of the pin set ran on a cold card and is faster than every later run on the same card; the second round shows depth 0 unchanged. At depth 32K, prompt processing is 18% (T4) to 31% (L4) faster: after the SWA ring wraps, its layers took the dense bias before and now take the banded kernel with cell positions. Generation is unchanged. Not covered
|
… bytes (builds on unslothai#19148) (unslothai#19249) Builds on unslothai#19148 (includes its commits); merging this merges unslothai#19148. ## Problem unslothai#19148 prices the large compute reserve that unslothai/llama.cpp#386 added in `b12649-mix`. The next llama.cpp prebuild may ship the fix to that reserve. In the fixed build, several slots run the banded kernel over cell positions, and short ubatches run banded over the padded cache. The reserve then drops to almost nothing: | Inkling-2-Mini, 1 slot, 1M context, ub 512 | `b12649-mix` | fixed build | |---|---|---| | f16 K/V | 5866 MiB | 1248 MiB | | q8_0 K/V | 9962 MiB | 1248 MiB | With unslothai#19148 alone, Studio would keep pricing the fixed build with the `b12649-mix` reserve. On the measured points that overestimates the compute buffer by 0.2 to 55 GB, so Studio would place fewer layers on the GPU than fit. This PR prices the fixed build separately, which makes unslothai#19148 safe to merge. ## Fix - Detect the fixed build by two graph input names it adds to `libllama`: `attn_inp_k_pos_swa` (several slots, banded over cell positions) and `attn_inp_rel_shift_swa` (short ubatches over the padded cache). No earlier build has either name. Both survive `strip`. Both must be present. - Price its reserve as the f16 KQ mask over the padded cache (2 bytes per cell per ubatch token, twice with `--swa-full`) plus 160 KiB per ubatch token, for any slot count and K/V type. A layer split adds its mask copies as before. - Keep only the CUDA pool margin (256 KiB per ubatch token) in `--fit-target`, as unslothai#19148 does for `b12649-mix`. The markers identify the build even when its build number cannot be read. - `b12649-mix` and the merge-only rebuild of #386 keep unslothai#19148's pricing. Older builds keep the pricing on `main`. - Split a `--fit off` multi-GPU load by bytes when llama.cpp's split by layer count would overflow a card. Unsloth Dynamic quants keep some layers at higher precision: the last four layers of Inkling-2-Mini UD-Q8_K_XL are about 2 GB each, against 0.6 GB for the rest, so a split by count can put several GB more on the smaller card than it holds. Studio now emits a `--tensor-split` whose layer runs fit each card. When no split fits, it lets `--fit on` place the model with the slots the user asked for, not a count cut only to fit every layer on the GPUs. A load whose count split already fits keeps llama.cpp's own split. Which pricing each build gets (`grep -c` of each string in the built `libllama`): | Build | `inkling2_loop: %zu cache slots exceed` | `attn_inp_k_pos_swa` | `attn_inp_rel_shift_swa` | Pricing | |---|---|---|---|---| | `b12631-mix` | 1 | 0 | 0 | as on `main` (build below 12649) | | `b12649-mix` | 1 | 0 | 0 | unslothai#19148 | | #386 merge-only rebuild | 1 | 0 | 0 | unslothai#19148 | | fixed build (#386 plus the banded-position fix) | 1 | 1 | 1 | this PR | ## Accuracy Compute buffer at load from `llama-server`, Inkling-2-Mini, flash attention, B200, on the fixed build. The table is a sample of 116 points: 1 to 64 slots, ub 256 to 2048, f16 / bf16 / q8_0 / q4_0 / q4_1 / q5_0 / q5_1 / mixed K/V, 4K to 1M context, with and without `--swa-full`, and with a DSpark drafter. | Setup | Measured (MiB) | This PR (MiB) | unslothai#19148 (MiB) | |---|---|---|---| | 4 slots, 32K, ub 512 | 256 | 298 | 3050 | | 4 slots, 256K, ub 512, q5_1 | 480 | 522 | 6506 | | 4 slots, 1M, ub 2048, q8_0 | 4999 | 5156 | 60388 | | 1 slot, 512K, ub 512 | 734 | 773 | 3429 | | 1 slot, 1M, ub 512, q4_0, DSpark | 1248 | 1285 | 10597 | | 1 slot, 415,488, ub 2048, q4_0, `--swa-full` | 4124 | 4292 | 10932 | | 4 slots, 274,688, ub 512, q4_0, `--swa-full` | 758 | 803 | 18577 | | 64 slots, 64K, ub 512 | 352 | 440 | 9496 | Across all 116 points the estimate is 1.01x to 1.25x the measurement (+14 to +184 MiB) and never under it. The highest ratio is 64 slots at 64K, where the flat estimate's output rows lead. After two concurrent 13.5K-token prompts at ub 2048 with 4 slots, the compute buffer grew by 120 MiB past the load reserve. The 512 MiB pool margin in `--fit-target` covers that. ## unslothai#19137 on the fixed build The unslothai#19137 setup with Inkling-2-Mini UD-Q8_K_XL: 2 GPUs, 32K context, 4 slots requested, the Windows reserve floor. Studio's planner ran for each free VRAM pair. The command it produced then ran on two B200s, with `cudaMemGetInfo` capped to that pair. The cap only changes what llama.cpp sees as free memory; it does not stop an allocation. So for every load, the table checks llama.cpp's own per-card memory (weights, cache, compute, unaccounted) against the card. Every load answered two concurrent 13.5K-token prompts. | Free VRAM | `main` | unslothai#19148 | This PR | |---|---|---|---| | 14848 + 11264 MiB | `--fit on`, target 3714: 12.3 GiB of weights on GPU | `--fit on`, target 1536: 16.6 GiB on GPU | same command as unslothai#19148 | | 15360 + 11264 MiB | `--fit on`, target 3714: 12.8 GiB on GPU | `--fit on`, target 1536: 16.6 GiB on GPU | same command as unslothai#19148 (4 slots, `--fit on`, target 1536) | | 16384 + 12288 MiB | all layers on GPU, 4 slots, split by count: 13.5 GB on the 12 GB card, so it fails at load | all layers on GPU, 1 slot, split by count: 13.9 GB on the 12 GB card, so it fails at load | all layers on GPU, 4 slots, `--tensor-split 19.5,5.5`: 15.0 GB and 11.1 GB, under 16 and 12 GB | Decode speed, median of 5 runs of 256 tokens after a warmup, in tok/s. These numbers are noise-dominated: the host CPU was shared with other jobs, and loads with every layer on the GPUs measured anywhere from 91 to 698 tok/s across rounds of the same setup. They do not rank the versions; the placement above is the result. | Free VRAM | `main` | unslothai#19148 | This PR | |---|---|---|---| | 14848 + 11264 MiB | 134 | 155 | same command as unslothai#19148 | | 15360 + 11264 MiB | 155 | 208 | same command as unslothai#19148 | | 16384 + 12288 MiB | 110 (would not load on the real cards) | 184 (would not load on the real cards) | 91 | `main` on the fixed build reproduces the report: 11.6 and 7.9 GB used of the two cards with expert weights on the CPU, as in the Task Manager readings in unslothai#19137. With 16 + 12 GB free, this PR keeps the whole model on the GPUs and loads. `main` and unslothai#19148 plan the same placement but split by layer count, so the 12 GB card cannot hold its share. The 1024 MiB per-device overhead matches what llama.cpp reports as unaccounted per device (0.8 to 1.3 GB), so this PR leaves the multi-GPU margins as they are. ## Boundaries - The byte split shares the cards by the lowest fill they can all hold, in device order. With three or more cards it can leave a middle card lightly used. - `llama-completion` reserves a logit row per ubatch token, so its single-slot buffers are larger than `llama-server`'s at the same settings (819 vs about 252 MiB at 32K, ub 512). Studio launches `llama-server`, which is what this PR prices. - The DSpark drafter's own compute buffer (203 MiB with f16 draft K/V and 663 MiB with q4_0 at 128K) is unchanged by the fix and priced as before. ## Tests - `test_inkling2_banded_quant_kv.py` adds: - the marker detection, including each marker alone, a longer name, an unknown build number and an older build number; - 48 measured points, plus mixed K/V types; - context monotonicity, with no slot or K/V type dependence; - the layer-split mask copies; - the `--fit-target` margin; - the dense fallback with flash attention off or ubatches of 32 or fewer. - `test_byte_balanced_layer_split.py` covers: - an even model keeping llama.cpp's split; - the unslothai#19137 rows split by bytes at 16 + 12 GB, and handed to the fitter at 15 + 11 GB; - each run fitting its card, the positional order over three cards; - the planner path from the layout, and the launch falling back to `--fit on`. - a slot cut whose pin has no layer split that fits: the launch keeps the 4 slots asked with `--fit on`. - The 31 Studio planner suites give the same failing test IDs on `main`, unslothai#19148 and this PR. All 321 come from this host's CUDA probe guard (a CPU test reaching `torch.cuda` on a GPU host without a queried device), not from these changes. --------- Co-authored-by: oobabooga <[email protected]>
|
Moved one step further to 01f7959 (fast-forward of 8ee7920): the two checks that the cell and query positions are mirrored (src[7] / src[8]) now sit just before the op switch in At 01f7959, with the rest of unslothai master's pr-set: |
|
@codex review |
|
Codex Review: Didn't find any major issues. Delightful! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Upstream b12635 added an op and moved the RPC check to GGML_OP_COUNT == 101 with RPC_PROTO_PATCH_VERSION 2. This branch adds GGML_OP_FLASH_ATTN_EXT_BANDED on top, so the count is 102 and GGML_RPC=ON builds stop at the static_assert. Bump the check to 102 and the patch version to 3.
ggml_prec_set_acc() stores the accumulator precision of GGML_OP_FLASH_ATTN_EXT_BANDED in op param 3 and ggml_flash_attn_ext_get_prec() reads it, but the generic getter returned GGML_PREC_UNDEFINED for the banded op. test-flash-attn-bias checks the round trip.
…h with the main label Both were plain add_test() entries without a label, so ctest -L main skipped them.
…_bias The banded op reuses the FA MMA kernel and tagged it with max_bias < 0, but ggml_flash_attn_ext() accepts a negative max_bias (no ALiBi), so an ordinary call with max_bias < 0 read the sinks as a relative-bias table. m0 of an ordinary call is a power of 2 and never negative. Add FLASH_ATTN_EXT cases with max_bias = -2.
…A path The switch only gated the standalone banded MMA kernel; a no-sink op still delegated to the FA MMA kernel.
A row without a visible cell has a zero rowsum, the MMA kernel and the stream-k fixups divided 0 by 0. The CPU and the other banded CUDA kernels return 0. Add banded cases with a fully masked query (mask_kind 4), which the op delegates to the FA MMA kernel without sinks.
The local index rejects a tensor in a shard the index does not assign it to and a name that two tensors map to after filtering. --remote overwrote both silently: check the shard in SafetensorRemote and the filtered name in index_tensors().
… early return A pure NVFP4 checkpoint returned from dequant_model() before the check, keeping the packed experts.
…probe every cache type The reserve context reports the full span as contiguous, so the reserved graph of a unified multi-sequence context was banded while such ubatches run dense. Take the banded op for one-sequence ubatches only, as inkling2 does, and ask the layer's device for F32 / F16 / BF16 caches too, not only for quantized ones.
With LLAMA_INKLING_BANDED_POS=0 a cache whose cells are not the positions is dense, so reserve the full-attention layers dense too, not only a wrapping SWA cache. A unified multi-sequence context decodes one token dense, while its tg reserve of n_seq_max tokens is banded: reserve that graph as well.
The FA kernels read F16 K/V in place with 16-byte loads, so a K/V view whose rows are padded off that boundary (a 129-wide backing tensor) was mis-addressed. Keep such ops on the banded kernels, which read any row stride. Add the kv_layout cases: padded K/V rows, a mask wider than K and K/V head counts that differ.
|
@codex review |
|
Codex Review: Didn't find any major issues. Breezy! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…leaving the banded op check as it was
…d-only MMA checks
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…st (-Werror=cast-qual)
|
@codex review |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Banded flash attention for the relative bias, on top of #378 (
GGML_OP_FLASH_ATTN_EXT_BANDED) and #385 (chunked relative-bias attention). The base is the upstream commit #378 uses, so the diff also shows #378 and #385 at their pinned commits. In the pin set this goes after both of them.Change
src/models/inkling2.cpp: when flash attention is on and the cache is position-contiguous (get_n_kv_pos_contiguous), the relative logits inside the extent go toggml_flash_attn_ext_bandedand the sink logit goes in as per-query sinks. No dense per-head mask is built. Everything else uses the chunked dense path: other cache layouts, quantized or scaled K/V, head sizes other than 64/128, devices that do not support the op, and ubatches of up to 32 tokens. Small ubatches stay dense so the graph can be reused while decoding.src/llama-graph.cpp/.h: the rel-pos input refuses graph reuse when the banded cell count changes.ggml_flash_attn_ext_add_sinksaccepts FLASH_ATTN_EXT_BANDED, with sinks[n_head]or per query[n_head, n_q, 1 or n_seq];test-backend-ops: banded cases with per-head and per-query sinks, plus Inkling-2-Small shapes (48/8 heads, extent 1024, decode, speculative and prefill rows).Tests
test-llama-archs(CPU): 155/155.test-backend-ops -o FLASH_ATTN_EXT_BANDED -b CPU: 53/53.test-backend-opsCUDA0 vs CPU (B200, sm_100): FLASH_ATTN_EXT_BANDED 53/53, FLASH_ATTN_EXT 4430/4430, MUL_MAT_ID 1060/1060, GET_ROWS 228/228, CONCAT 221/221, CPY 285/285, SET_ROWS 179/179.ggml-hip+llama, gfx90a and gfx1151): passes.-c 512 --chunks 8, experts on CPU,-fa on, compared with plain b12549:-b 512(one sequence, banded path): PPL 3.6358 vs 3.6310, mean KLD 0.006934, same top token 96.96%. For comparison, b12549 itself at-b 2048against-b 512gives mean KLD 0.006184 and 97.40% same top token, so the change is within the batch-layout noise of the existing kernels.-b 2048(four sequences, dense fallback): PPL 3.622135, the same as b12549; mean KLD 0.000000, same top token 100%.llama-perplexity -c 51200 -b 2048 -ub 2048 --chunks 1 -fa onon an Inkling-2-Small-shaped test model (48 heads, random weights): completes. b12549 aborts there withGGML_ASSERT(s2 <= UINT32_MAX).Quantized K/V and a shared banded mask (15b7c1a)
7db4a7064: the CUDA banded kernel dequantizes q8_0 / q4_0 K/V in-tile. Before, a quantized cache fell back to the dense relative-bias path and reserved an extra F16 copy of K/V, so q8_0 used more memory than F16. Inkling-2-Mini q8_0 peak at 256K: 14876 -> 13528 MiB after both changes; q8_0 prefill at 128K is 2.3x faster.493fc82c2: one banded mask per graph shared by every layer. Compute buffer at 256K: 2400 -> 560 MiB; at 1M: 9312 -> 2096 MiB.291a63e3d,2f96ddbbb,15b7c1ae4:--no-ffmerges of the three model : Inkling 1 (ggml-org#25731) on b12533 for the prebuilt #378 commits this branch carries.-c 512and-c 32768; q8_0 / q4_0 KLD unchanged. Cross-platform base vs head: HIP gfx1151 Linux and Windows, CPU, Vulkan lavapipe and Metal (macos-15), no regression.Graph dedupe (0edf1d6)
It removes repeated work in the Inkling 2 graph; results are bit-identical:
It edits the lines this PR and #385 added to src/models/inkling2.cpp and src/models/models.h, so it belongs here and not in a separate pin.
Evidence (B200, one exclusive card, ABBA): on its own, +5 to +7% pp512/pp4096 and +8 to +10% tg128 on Inkling-2-Mini; decode 7328 -> 6653 kernels per token. test-llama-archs inkling2.* 6/6. llama-perplexity KLD against the pin set (UD-IQ1_S, UD-Q4_K_XL, Mainline_Support UD-IQ1_S, -ub 1 / -ub 4, -sm layer -ts 1,1): PPL string equal, mean KLD 0, top-1 100%.
Update: two more commits (fast-forward 6348de2 to 4fff29a)
Both are graph-only. With these two commits and every CUDA decode pin switched off by its kill switch, the stack is bit-identical to #399 (which has the previous #386 head) on B200, T4, L4, A100 and RTX PRO 6000: KLD at -c 512, -c 4096, -ub 4 and -ub 1, PPL string equal, mean KLD 0.
Update: the compute buffer now covers the dense relative-bias path
While testing #407 we found that Inkling 2 could grow its CUDA compute buffer far past the size reserved at load, which ends in an OOM in the middle of a generation. Two causes combined:
-kvu), a single-sequence ubatch whose cells are not one run, ubatches of 32 tokens or less, and the SWA layers once the positions pass the SWA cache and it wraps.ggml_cpyinto a tensor fromggml_new_tensor_4d. That tensor is a graph leaf, and the allocator keeps leaves for the whole graph, so the bias of every chunk and every dense layer stayed allocated at once and the chunking bounded nothing. The chunk outputs, kept until a final concatenation, also split the region the next chunk's bias reused.On this branch (#385):
On #386 (same code merged, plus the banded reserve):
ggml_castnode instead of a copy into a leaf.Results on a B200, Inkling-2-Mini UD-IQ1_S, CUDA0 compute buffer in MiB, reserved at load and largest at runtime. Each case prefills one sequence to 4352 tokens short of the context, then runs a ubatch split over two sequences (two-slot cases), a 32-token batch, a full ubatch and one token per sequence:
-kvu-kvu-kvu-kvuA single slot at Studio settings (f16 KV,
-np 1) reserves a little more at load:-ub 512-ub 2048The ggml-org#32804 case (
-c 172032 -kvu -npl 2 -npp 80000 -ub 2048) still completes. It reserved 3834 MiB and grew to 17285 MiB at runtime; it now reserves 10673 MiB and stays there.Output is unchanged: wikitext-2 PPL strings are identical to the base at
-c 512and-c 4096, with one sequence per batch and with several in a unified cache, mean KLD 0.000000 and the same top-1 agreement as the base against itself. The logits of a ubatch split over two sequences are bit-identical to the base at 131072 (one chunk) and 524288 (two chunks).test-backend-ops -o FLASH_ATTN_EXT_BANDEDpasses 71/71 on CUDA0, andtest-llama-archspasses for inkling2 and inkling2_loop.The extra reserve nodes are added only to the graph built at load. Every runtime graph has the same node count as before (11035 per decode token at
-ub 1, 10870 for a 512-token ubatch), and a counter on the reserve condition read 0 on every real ubatch: decode, 33 to 2048-token prefill, a ubatch over two sequences that share a position, and llama-server with two slots. llama-bench pp512 and tg128 are within noise of the base. Context shift and--cache-reuseare not available for this model (llama_memory_can_shiftis false), so they cannot reach the dense path.