Skip to content

perf(assets): stream prerouter safetensors payloads - #171

Merged
shuk777 merged 1 commit into
Edge0-AI:mainfrom
Afloat16:perf/20261111-stream-prerouter-payloads
Nov 16, 2026
Merged

shuk777 merged 1 commit into
Edge0-AI:mainfrom
Afloat16:perf/20261111-stream-prerouter-payloads

Conversation

@Afloat16

Copy link
Copy Markdown
Contributor

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

  • Model asset tools (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 -q

90 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

  • Added a bounded-memory regression with exact payload checks
  • Added malformed extent coverage
  • Full offline asset L1 suite passes

@shuk777 shuk777 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@shuk777
shuk777 merged commit b5695f1 into Edge0-AI:main Nov 16, 2026
1 check passed
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.

2 participants