Skip to content

Consume external weights one tensor at a time - #25

Draft
matthargett wants to merge 1 commit into
rustnn:mainfrom
rebeckerspecialties:feat/consuming-external-weights
Draft

matthargett wants to merge 1 commit into
rustnn:mainfrom
rebeckerspecialties:feat/consuming-external-weights

Conversation

@matthargett

@matthargett matthargett commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

This is to get peak memory usage down and performance up on memory-constrained devices like Apple Watch and iPhone SE 2 (A13 like iPhone 11, but less physical memory).

Local-device graph compilers currently resolve an entire external weight archive into owned AST payloads before they can write backend storage. Large bundles briefly retain both representations. This adds an optional consuming sink and reads one validated tensor/span at a time; the existing inline resolver keeps its API and behavior.

The sink receives ownership of a tensor's bytes and returns its replacement AST payload. Returning empty bytes requires equivalent caller-owned external storage and does not produce a standalone resolved graph. SafeTensors bounds, dtype/shape, packed four-bit metadata, BF16 conversion and sanitized-name checks remain in force. Manifest spans keep their existing validation contract. The touched file's mixed line endings are normalized to LF.

Validation: 17 external-weight tests pass, including four new consuming ownership/error, malformed archive and manifest-span tests. This is setup-time storage work, with no inference kernels or network dependency. Draft prerequisite for the native-only RustNN work tracked in rebeckerspecialties/rustnn#38 (comment).

Read validated SafeTensors headers and individual manifest spans, transferring each payload to an optional consuming sink. Preserve the inline resolver and packed/BF16 conversion contracts. Document that empty replacement payloads require caller-owned external storage.

Validation: 17 external-weight tests pass, including consuming ownership, sink errors, malformed archive extents, manifest bounds, legacy resolution and packed storage cases.

This branch has not been deployed

No deployments
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.

1 participant