Skip to content

Studio: size Inkling 2's banded relative-bias attention for the next llama.cpp prebuild - #18692

Merged
oobabooga merged 1 commit into
unslothai:mainfrom
oobabooga:inkling2-banded-estimate
Nov 20, 2026
Merged

oobabooga merged 1 commit into
unslothai:mainfrom
oobabooga:inkling2-banded-estimate

Conversation

@oobabooga

Copy link
Copy Markdown
Member

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 #18689 is the right one.

Problem

#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:

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 Request for phi 3 support #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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-20T22:40:26.285749Z
We couldn’t complete this review. Comment @codex review to try again.
e474b6f PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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