Run a learned MLP policy forward without copying its parameters - #340
Open
Thiago316316 wants to merge 2 commits into
Open
Run a learned MLP policy forward without copying its parameters#340Thiago316316 wants to merge 2 commits into
Thiago316316 wants to merge 2 commits into
Conversation
A trained policy reaches a robot as one flat block of numbers. Two hidden layers 64 units wide over a 22-component observation come to about 5,900 of them, some 23 KB as `f32`, against the 64 KB of RAM a small Cortex-M has in total. Owning those weights would copy the block onto the stack every control cycle. `Layer` holds a `MatrixView` of its weights and a `VectorView` of its biases instead, so the coefficients are read where they were stored. `forward` writes only the activations, `OUTPUT` of them rather than `OUTPUT`x`INPUT`. `Activation` carries the scalar nonlinearity as an enum rather than a `fn` pointer, so the choice is inlinable and a layer stays inspectable; it is `#[non_exhaustive]`, leaving room for more. Widths are const parameters, so chaining a layer that produces three values into one that expects four fails to build rather than at runtime. Nothing allocates and nothing panics, so it runs under `no_std`. Inference only. Training belongs on a machine with room for it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The overview ran three long paragraphs before the example, restating in prose what the example shows. Cut to what a reader cannot get from the code: what the layers do, why the parameters are borrowed, and what the const widths buy. The links go with it. `cargo doc` denies warnings in CI, and rustdoc counts a link whose label already names a path in scope as a redundant explicit target. Both view types are imported here, so the bare labels resolve to the same pages the spelled-out paths did. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Thiago316316
force-pushed
the
fix/83-mlp-inference-core
branch
from
August 28, 2026 23:20
a38ddda to
6a32e97
Compare
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
A trained policy reaches a robot as one flat block of numbers. Two hidden layers 64 units wide over a 22-component observation come to about 5,900 of them, some 23 KB as
f32, against the 64 KB of RAM a small Cortex-M has in total.Layerholds aMatrixViewof its weights and aVectorViewof its biases instead, so the coefficients are read where they were stored.forwardwrites only the activations,OUTPUTof them rather thanOUTPUTxINPUT.Activationcarries the scalar nonlinearity as an enum rather than afnpointer, so the choice is inlinable and a layer stays inspectable; it is#[non_exhaustive], leaving room for more.Widths are const parameters, so chaining a layer that produces three values into one that expects four fails to build rather than at runtime. Nothing allocates and nothing panics, so it runs under
no_std.issue #83
Checklist
cargo test+cargo clippy --all-targetsclean locallyunwrap/expect/panicon library paths (typed errors instead)