fix(scripts): recompute metadata.total_size after stripping vision weights - #117
Open
agourakis82 wants to merge 1 commit into
Open
agourakis82 wants to merge 1 commit into
agourakis82 wants to merge 1 commit into
Conversation
…ights strip_vision_weights.py removed vision keys from weight_map but left metadata.total_size at its pre-strip value. Given an index with total_size=96 and 32 bytes of vision tensors, the index still reported 96 after stripping, so consumers trusting total_size over-report disk usage by the stripped volume (~0.9 GB on the real 35B checkpoint). Tracks the bytes actually dropped from each rewritten shard (already computed for the per-shard log line) and subtracts the running total from metadata.total_size once, after all shards are processed. This is equivalent to recomputing from the retained tensor offsets — untouched shards' bytes are unaffected by definition, so old_total - dropped equals the true new total. Fixes Edge0-AI#104. Co-Authored-By: Claude Sonnet 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.
Fixes #104.
strip_vision_weights.pyremoved vision keys fromweight_mapbut leftmetadata.total_sizeat its pre-strip value. Given an index withtotal_size=96and 32 bytes of vision tensors, the index still reports96after stripping — consumers that trusttotal_sizeover-report disk usage by the stripped volume (~0.9 GB on the real 35B checkpoint).Fix
Tracks bytes actually dropped from each rewritten shard (already computed for the per-shard log line) and subtracts the running total from
metadata.total_sizeonce, after all shards are processed. Untouched shards' bytes are unaffected by definition, soold_total - droppedequals the true new total — equivalent to, but cheaper than, recomputing from every shard's retained tensor offsets from scratch.Test plan
tests/test_strip_vision_weights.pywith a hand-built minimal safetensors shard (no MLX, no real checkpoint needed): assertstotal_sizeshrinks by exactly the dropped vision bytes, and that a checkpoint with no vision weights leaves the index untouched.pytest -m 'not slow': 81 passed, 1 skipped (no regressions).