Skip to content

fix(scripts): recompute metadata.total_size after stripping vision weights - #117

Open
agourakis82 wants to merge 1 commit into
Edge0-AI:mainfrom
agourakis82:fix/strip-vision-total-size
Open

agourakis82 wants to merge 1 commit into
Edge0-AI:mainfrom
agourakis82:fix/strip-vision-total-size

Conversation

@agourakis82

Copy link
Copy Markdown
Contributor

Fixes #104.

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 reports 96 after stripping — consumers that trust total_size over-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_size once, after all shards are processed. Untouched shards' bytes are unaffected by definition, so old_total - dropped equals the true new total — equivalent to, but cheaper than, recomputing from every shard's retained tensor offsets from scratch.

Test plan

  • Added tests/test_strip_vision_weights.py with a hand-built minimal safetensors shard (no MLX, no real checkpoint needed): asserts total_size shrinks 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).

…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

scripts/strip_vision_weights.py leaves metadata.total_size at the pre-strip value

1 participant