performance: post-compilation CLI to get/set kvcache_num_blocks - #638
Open
rebel-jongho wants to merge 5 commits into
Open
performance: post-compilation CLI to get/set kvcache_num_blocks#638rebel-jongho wants to merge 5 commits into
rebel-jongho wants to merge 5 commits into
Conversation
1 task
rebel-jongho
marked this pull request as ready for review
July 21, 2026 04:03
rebel-jongho
force-pushed
the
jongho/kvcache-num-blocks-cli
branch
2 times, most recently
from
July 22, 2026 04:06
7b69f4e to
df4c3f6
Compare
rebel-jongho
marked this pull request as draft
July 22, 2026 04:06
rebel-jongho
marked this pull request as ready for review
July 22, 2026 04:09
memory_budget is a compile-time estimation input, not a persisted property (the resolved kvcache_num_blocks is what the artifact keeps), so register it in subclass_non_save_attributes. qwen3_vl configs override that list, so add it there too to avoid re-exposing it. It stays readable at runtime; it is just not written to rbln_config.json. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
rebel-jongho
force-pushed
the
jongho/kvcache-num-blocks-cli
branch
from
July 22, 2026 06:08
df4c3f6 to
f0f6dfc
Compare
rebel-jongho
marked this pull request as draft
July 22, 2026 06:08
memory_budget only guides automatic block estimation (kvcache_num_blocks unset). If an explicit kvcache_num_blocks is also given, estimation is skipped and memory_budget would be silently ignored, so raise a ValueError instead. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add optimum-rbln-cli --get-kvcache-num-blocks / --set-kvcache-num-blocks N (--model-id DIR) to inspect/resize the kv-cache of an already-compiled artifact without recompiling, plus RBLNDecoderOnlyFlashAttentionMixin.rescale_kvcache_num_blocks. --set edits in place or writes a resized copy with --output-dir. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add optimum-rbln-cli --set-memory-budget BUDGET, which resizes the kv-cache to the largest block count that fits BUDGET (float fraction / "80%" / bytes), mutually exclusive with --set-kvcache-num-blocks. Thread current_blocks through estimate_num_kvcache_blocks / _search_num_kvcache_blocks (default 1) so the fit search is correct on an already-resized artifact; the transient budget is not persisted to rbln_config.json. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
rebel-jongho
force-pushed
the
jongho/kvcache-num-blocks-cli
branch
from
July 22, 2026 06:17
f0f6dfc to
03948ff
Compare
rebel-jongho
marked this pull request as ready for review
July 22, 2026 08:52
Contributor
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Type of Change
Changes Overview
Post-compilation subcommands on
optimum-rbln-clioperating on an already-compiled artifact directory (--model-id DIR), without recompilation:--get-kvcache-num-blocks— printskvcache_num_blocksfromrbln_config.json.--set-kvcache-num-blocks N— resizes the kv-cache of every*.rblntoNblocks.--set-memory-budget BUDGET— resizes to the largest block count that fits BUDGET (a float fraction of the NPU available DRAM like0.8, a"80%"string, or bytes like"10GB"). Mutually exclusive with--set-kvcache-num-blocks.setedits in place, or with--output-dirwrites a full resized copy there (copying the non-.rblnfiles too) and leaves the source untouched.Internals:
RBLNDecoderOnlyFlashAttentionMixin.rescale_kvcache_num_blocks(compiled_models, rbln_config, target): saved buffers holdper_block * currentbytes (current = rbln_config.kvcache_num_blocks); rescaling by the rational ratiotarget / current(rebel-compilerexp_rescale_buffer_size) yields exactlyper_block * target. Stateless;rbln_config.jsonis the source of truth.--set-memory-budgetcomputes the target viaestimate_num_kvcache_blocks(..., current_blocks=current).current_blocks(added toestimate_num_kvcache_blocks/_search_num_kvcache_blocks, default 1) makes the fit search correct on an already-resized artifact (buffers atcurrent, not 1). The transient budget is not persisted torbln_config.json(model: memory_budget config semantics (non-save, mutually exclusive with kvcache_num_blocks) #639 marksmemory_budgetnon-save).target < num_min_blocks→ValueError;targetabove the compile-time count ornum_full_blocks→ warning; older rebel-compiler withoutexp_rescale_buffer_size→ clearRuntimeError.Dependency
Requires rebel-compiler's new
exp_rescale_buffer_size(rebellions-sw/rebel_compiler#12067).Motivation and Context
Lets users tune
kvcache_num_blockson a compiled artifact without recompiling — either to an explicit count or to fit a memory budget. Split out from #629 per review; thememory_budgetestimation change (#637) is already merged intodev.How to test
On a compiled decoder-only artifact:
--getprints the count;--set-kvcache-num-blocks N(N ≥ num_min_blocks) rewrites buffers toper_block * Nand updates the config (verified by reloading the.rbln);--set-memory-budget BUDGETcomputes and sets the fitting count (smaller budget → fewer blocks); infeasible targets (< num_min_blocks) raiseValueError;--output-dirleaves the source untouched.