Repository navigation
fix(sae): compare the JumpReLU Lp loss with the gated pre-activation - #222
Open
flyingdoubleG wants to merge 1 commit into
Open
flyingdoubleG wants to merge 1 commit into
flyingdoubleG wants to merge 1 commit into
Conversation
With sparsity_include_decoder_norm (the default), encode gates hidden_pre * ||W_d|| with the JumpReLU threshold but returns hidden_pre unscaled, and the Lp loss computed ReLU(threshold - hidden_pre) * ||W_d||, comparing the threshold with a quantity on a different scale. The loss then changed under the reparametrization encoder * s, decoder / s, which leaves the model unchanged, so training could lower it by inflating the encoder. Compare the threshold with hidden_pre * ||W_d|| in that mode; without the decoder norm in the gate the loss is unchanged.
This branch has not been deployed
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.
Summary
With
sparsity_include_decoder_norm=True(the default), the SAE, Lorsa, MoLT and Crosscoderencodemethods apply the JumpReLU threshold tohidden_pre * ||W_d||, but returnhidden_preunscaled. The JumpReLU Lp (pre-act) loss inSparseDictionary.compute_lossthen computesThis compares the threshold with a pre-activation on a different scale from the one it actually gates. The inconsistency shows up under the reparametrization
W_E, b_E *= s,W_D /= s. That reparametrization leaves the model's function,l_recand the tanh sparsity loss unchanged, butl_pchanges. Training can therefore lowerl_psimply by inflating the encoder and shrinking the decoder, which is exactly the dynamic thatsparsity_include_decoder_normis meant to suppress.Reproduction
A JumpReLU SAE with every latent rescaled by
s, run on the same batch:Change
In the
sparsity_include_decoder_normcase, compare the threshold with the gated quantity:This is the decoder-norm-scaled counterpart of
ReLU(exp(t) - f_i(x)) ||W_{d,i}||. TheFalsecase is unchanged, since there the threshold already gateshidden_preand the||W_d||factor gives the invariance. CLT overridescompute_lossand is not affected.Tests
test_jumprelu_lp_loss_is_invariant_to_latent_rescaling[True]fails before this change and passes after. The[False]case is a control and passes both before and after.tests/unit/test_sae.py,test_crosscoder.pyandtest_evaluator.pypass.ruff checkandruff format --checkare clean.