feat: Add activation functions and Xavier/He weight init#5
Merged
Conversation
ThomasHartDev
commented
Jul 24, 2026
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.
Pulled the nonlinearities and the init schemes into their own module so the variance story is measurable on its own. Each activation carries a local backward for act'(z), and Xavier vs He are the usual closed forms (2 over fan_in+fan_out for symmetric acts, 2 over fan_in for ReLU). The interesting bit is forward_variance_profile: stack a few layers from unit noise and you can watch naive N(0,1) weights explode, He hold a ReLU stack near O(1), and Xavier quietly starve the same ReLU stack. That last case is the silent failure mode I wanted to pin down with a test rather than leave as folklore.
Derivatives are checked against finite differences, sample variances of the draws match the formulas, and the MLP path is left alone for now so this stays a focused slice.