Check the MLP layers against numpy goldens end to end - #355
Open
Thiago316316 wants to merge 1 commit into
Open
Thiago316316 wants to merge 1 commit into
Thiago316316 wants to merge 1 commit into
Conversation
The layer and cursor types landed with unit tests that check their own arithmetic. Nothing yet ran a whole policy and compared the answer with an independent implementation, so a shape or ordering mistake that is consistent across the crate would pass. Adds a numpy generator and two fixtures. `policy_22x64x64x4` is a quadrotor controller's shape — 22 observations in, two 64-wide rectified hidden layers, 4 rotor thrusts out — with its 5,892 parameters sampled from a fixed seed, its eight observations, and the goldens for both hidden layers as well as the action. Storing the hidden activations turns "the actions are wrong" into "layer 2 is wrong, layer 1 was fine". Eight observations rather than one so the batch drives several distinct activation patterns instead of a single path through the rectifiers. `activations` pins each nonlinearity at zero, at an ordinary value, and where `Tanh` saturates, which is where a hand-rolled approximation would drift. The test walks the flat export with `ParameterCursor` and asserts the buffer ends empty: each layer reads correctly on its own even when a width is mis-declared, so only the total catches it. It runs generic over the scalar, so the f32 pass walks the same source rather than a transcription that could drift, and narrows once on load the way an embedded caller would. The f32 band is 1e-5 rather than the crate's usual 1e-3: a forward pass is only multiplies and adds, so single precision sits within about 1e-6 of the f64 golden, and a looser bound would pass a regression a thousand times larger than anything the arithmetic can produce. @Thiago316316 (kmolan#83) Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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
Adds a numpy generator and two fixtures.
policy_22x64x64x4is a quadrotor controller's shape (22 observations in, two 64-wide rectified hidden layers, 4 rotor thrusts out ) with its 5,892 parameters sampled from a fixed seed, its eight observations, and the goldens for both hidden layers as well as the action. Storing the hidden activations turns "the actions are wrong" into "layer 2 is wrong, layer 1 was fine". Eight observations rather than one so the batch drives several distinct activation patterns instead of a single path through the rectifiers.issue #83
Checklist
cargo test+cargo clippy --all-targetsclean locallyunwrap/expect/panicon library paths (typed errors instead)