Skip to content

[staging CI] unslothai/unsloth#13628 - #389

Closed
danielhanchen wants to merge 2 commits into
upstream-mainfrom
pr-13628-ci
Closed

danielhanchen wants to merge 2 commits into
upstream-mainfrom
pr-13628-ci

Conversation

@danielhanchen

Copy link
Copy Markdown
Collaborator

Disposable CI run for unslothai#13628. Do not merge; closed after CI.

@danielhanchen
danielhanchen deleted the pr-13628-ci branch October 13, 2026 17:06
danielhanchen pushed a commit that referenced this pull request Nov 20, 2026
…llama.cpp prebuild (unslothai#18692)

> **Note:** this targets the next llama.cpp prebuild, not the one
shipped today (`b12572-mix-8eebad4`). It assumes the pin set on
`unslothai/llama.cpp` master, which adds unslothai/llama.cpp#385
(chunked dense bias) and unslothai/llama.cpp#386 (banded flash
attention), plus unslothai/llama.cpp#389 at `3b34f4f`. On today's build
the dense rate from unslothai#18689 is the right one.

## Problem

unslothai#18689 sized the Inkling 2 compute buffer for the dense
relative-position bias (`512 * (8 * n_head + 4 + 2)` bytes per context
token at ub=512). The next llama.cpp prebuild replaces that path in the
common case:

- #386 runs the relative bias through banded flash attention when flash
attention is on, the cache is f16/bf16/f32, the head size is 64 or 128,
there is one stream and the ubatch is above 32 tokens. Studio's default
launch (flash attention, f16 cache, `--kv-unified`, ub=512) takes this
path.
- #385 chunks the dense bias over query rows once it passes 2^29
elements, for the configurations that still take the dense path.

With the dense rate, Studio would overestimate the banded buffer by
about 11x (77531 vs 7236 MiB at 800K) and pick a much shorter context
than fits.

## Fix

In `_compute_buffer_ctx_bytes`, the `inkling2` branch now:

- takes the banded path when it applies: 18 bytes per cell and
micro-batch token, plus a flat f32 `[ub, ub, n_head]` block;
- keeps the dense rate for the rest (quantized cache, flash attention
off, ubatch of 32 or less). With #385's chunking that rate is exact up
to the first split (32K at ub=512 for 24 heads) and an upper bound after
it.

## Verification

CUDA0 compute buffer of llama-server from the shipped mix source plus
#385, #386 and #389 at `3b34f4f`, on an RTX 6000 Ada, Inkling-2-Mini
UD-Q4_K_XL, `--kv-unified`, compared with Studio's estimate:

| n_ctx | ubatch | slots | cache | flash attn | measured (MiB) |
estimate (MiB) |
|---|---|---|---|---|---|---|
| 65536 | 512 | 4 | f16 | on | 781 | 786 |
| 262144 | 512 | 4 | f16 | on | 2509 | 2514 |
| 800000 | 512 | 4 | f16 | on | 7236 | 7241 |
| 65536 | 256 | 4 | f16 | on | 387 | 389 |
| 65536 | 2048 | 4 | f16 | on | 3350 | 3428 |
| 262144 | 2048 | 4 | f16 | on | 10236 | 10340 |
| 65536 | 512 | 1 | f16 | on | 672 | 781 |
| 65536 | 512 | 4 | q8_0 | on | 4574 | 6522 |
| 131072 | 512 | 4 | q8_0 | on | 6175 | 12858 |
| 262144 | 512 | 4 | q8_0 | on | 12191 | 25530 |
| 32768 | 512 | 4 | f16 | off | 4936 | 4922 |
| 65536 | 512 | 4 | f16 | off | 5159 | 9658 |
| 131072 | 512 | 4 | f16 | off | 5543 | 19130 |

On the banded path the estimate is 0.1% to 2.3% above the measurement
with 4 slots, and 16% above with 1. The dense fallback stays at or above
the measurement, except at 32K without flash attention, where it is 14
MiB (0.3%) below. Above that it is 1.4x to 3.5x high. It only applies to
non-default configurations.

Tests: `test_compute_buffer.py` checks the banded table (at or up to 20%
above the measurement), the dense fallback staying above the chunked
buffer, the two rates, which configurations take the dense path, and the
layer-split delta on both paths. `test_compute_buffer.py` and
`test_kv_cache_estimation.py` pass locally.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant