Repository navigation
perf(assets): stream prerouter safetensors payloads - #171
Merged
shuk777 merged 1 commit intoNov 16, 2026
Merged
Conversation
3 of 9 tasks
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.
What & why
The prerouter safetensors reader holds the complete source file, a copied payload section, and individual tensor payloads at the same time. Large prerouter assets therefore require roughly three times their payload size during reading.
Read the bounded header and each validated tensor payload directly from one file handle. The returned tensors retain one copy of each payload. Validate declared extents against the opened file size before reading so malformed lengths cannot request oversized allocations. Header order, metadata, shapes and exact payload bytes are preserved.
Area
edge0-infer/tools/assets/)How was it tested?
uv run --project edge0-infer/tools/assets --no-sync python -m pytest edge0-infer/tools/assets/tests -m l1 -q90 passed; 6 tests outside L1 deselected. The added memory regression uses eight synthetic 2 MiB tensors with reverse header order, checks every returned byte, and requires peak traced allocation below twice the total payload. It fails on the base reader (50,335,446 bytes) and passes with the streamed reader. Added malformed extent cases cover a huge declared allocation, a gap, a truncated tensor and a trailing byte.
A separate three-run comparison of that same 16 MiB fixture measured median traced peak allocation of 50,339,718 bytes before / 16,790,306 bytes after (about 48.01 / 16.01 MiB). This measures Python allocations during reading, not total process RSS or inference memory. Existing conversion and rollback tests also pass; no model download is required.
Checklist