feat(server meta): expose SWA geometry in /v1/models meta#132
Merged
Conversation
Add three new fields to the /v1/models meta object so clients can
compute exact KV bytes/token for SWA-hybrid models (gemma-4 etc.):
n_swa — sliding window size (already in API, now in meta)
n_swa_layers — count of SWA layers in the model
swa_type — "none" | "standard" | "chunked" | "symmetric"
New public API:
llama_model_n_swa_layers(model) — loops hparams.is_swa(il)
llama_model_swa_type_name(model) — enum-to-string for swa_type
With these, clients compute the exact formula:
kv/tok = (k_gqa + v_gqa) * kv_bytes * (
n_full_layers
+ n_swa_layers * min(ctx, n_swa) / ctx )
where n_full_layers = n_layer - n_swa_layers.
Previously the best a client could do was assume all layers scale
with ctx (correct for dense, 2-8x over-estimate for SWA-hybrid).
Purely additive — no behavior change until consumers read the fields.
Closes #123.
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.
Closes #123.
What
Adds 3 new fields to the
/v1/modelsmeta object so clients (heierchat VRAM panel) can compute exact KV bytes/token for SWA-hybrid models (gemma-4 12B/31B, gemma-4-12b-256k@gem) instead of the current safe-upper-bound estimate.New meta fields (per loaded model)
n_swallama_model_n_swa(model)1024n_swa_layersllama_model_n_swa_layers(model)40swa_typellama_model_swa_type_name(model)"standard"New public API
Exact KV formula the FE will compute
where
n_full_layers = n_layer - n_swa_layers.Verification
-DGGML_CUDA=OFF): compiles clean, zero warningsFiles changed (4, +36 lines)
include/llama.h— 2 new API declarationssrc/llama-model.cpp— implementations (layer-count loop + enum→string)tools/server/server-context.h— 3 new fields inserver_context_metatools/server/server-context.cpp— populate + emit in/v1/modelsJSON