Files
Strata/engine/include
Niko1221 1e800fd204 fix(inkling2/cuda): grow the global K/V when the net growth fits, not only when the whole new K/V fits (#6770 #6755)
ensure_global_kv_cap() compared the free memory with the WHOLE new K/V (global visits x slots x new capacity), as if
the old K/V were not already in the card. When the plan leaves room for the full context, that check refuses at about
half of it; the request then fails (and on a fatal path the engine ends) with gigabytes still free.

The 8 global visits grow one at a time (allocate the new buffer, copy, free the old one), so the card needs the net
growth of every visit plus the one old visit that is still held: strata/core/ink_kv_grow.hpp
(ink_kv_next_cap / ink_kv_grow_peak_bytes / ink_kv_grow_fits / ink_kv_grow_target), used by the runner.

Test ink_kv_grow_test (no GPU) models the growth loop with room planned for 131072 tokens: the old rule stops at
73728, the new one reaches 131072; also a card with room for 3/4 of the context, and the full / tight / none targets.

Checked on an RTX 4090 with 9.8 GB held back (SQ-10, --kv fp16 --kv-offload off --max-context 131072, planned context
51584, prompts of 20000, 30000, 45000 tokens):
- origin/main: the K/V stops growing at 32768 tokens (63% of the plan): "VRAM exhausted growing elastic global KV cache
  to 33071 tokens", the engine ends, the 45000-token request is lost.
- this change: the K/V grows 8192 > 16384 > ... > 49152, the 45000-token request is answered; prompts above the planned
  51584 get "prompt length out of range" and the engine stays up.
2026-11-23 12:20:55 +01:00
..