fix(kvarn): avoid double-counting weights when a repo ships both consolidated and sharded safetensors#20
Merged
philippebich merged 1 commit intoJun 12, 2026
Conversation
…dated and sharded safetensors estimate_weight_bytes globbed and summed every *.safetensors in the snapshot. Repos that ship a single consolidated checkpoint alongside the sharded HF set (e.g. Mistral-7B-Instruct-v0.3, which carries consolidated.safetensors next to model-0000n-of-0000m.safetensors) were counted at ~2x their real weight size. The post-weight usable envelope then goes negative, the fp16 tail pool budget floors, and check_and_update_config caps max_num_seqs to 1, so KVarN serves such models at single-stream throughput only. Prefer the *.safetensors.index.json (or *.bin.index.json) manifest, which lists exactly the shards the loader reads, then fall back to a single canonical file, then to the previous glob. Unchanged for models with only the sharded set or a single checkpoint.
philippebich
added a commit
that referenced
this pull request
Jun 12, 2026
Follow-up to #20. If the index manifest names shards that are missing on disk (e.g. a hand-managed partial checkout), summing only the present ones under-estimates the weights, which over-grows the fp16 tail pool budget and risks an OOM at load. Fall through to the single-file / glob paths instead, which over-estimate at worst. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Summary
KVarNConfig.estimate_weight_bytesglobs and sums every*.safetensorsin the model snapshot. Repos that ship a single consolidated checkpoint alongside the sharded HF set get counted at roughly 2x their real weight size. The clearest case ismistralai/Mistral-7B-Instruct-v0.3, whose snapshot carriesconsolidated.safetensors(the original Mistral format) next tomodel-0000n-of-0000m.safetensors(the HF shards).The over-estimate propagates through the pool sizing: the post-weight usable envelope
gpu_memory_utilization * total - weight_bytesgoes negative,pool_budget_bytesfloors at 0, andcheck_and_update_configcapsmax_num_seqsto 1. KVarN then serves the model at single-stream throughput only (the log showscapping max_num_seqs 256 -> 1), while fp16 and other KV-quant backends serve it normally. vLLM itself loads the model correctly because it readsmodel.safetensors.index.json; only this estimate helper double-counts.Reproduction
Log on
main:Fix
Prefer the
*.safetensors.index.json(or*.bin.index.json) manifest and sum only the shards it names, which is exactly the set the loader reads. Fall back to a single canonical checkpoint (model.safetensors, thenconsolidated.safetensors), then to the previous glob. No behavior change for models that ship only the sharded set or a single checkpoint.Before / after (measured, 24 GB GPU, gmu 0.80)
Controls (only sharded set, no consolidated file), estimate unchanged before and after:
Validation
mistralai/Mistral-7B-Instruct-v0.3withkvarn_k4v2_g128now serves and generates correctly (cap 71,nvidia-smishows normal concurrent decode). Validated on WSL2 (vLLM editable install), single 24 GB GPU,gpu_memory_utilization 0.80.