Repository navigation
fix(clt): scale single-layer encoding by the layer's concatenated decoder norm - #223
Open
flyingdoubleG wants to merge 1 commit into
Open
flyingdoubleG wants to merge 1 commit into
flyingdoubleG wants to merge 1 commit into
Conversation
…oder norm With sparsity_include_decoder_norm (the default), encode_single_layer multiplied the (..., d_sae) pre-activations by decoder_norm_per_feature(layer), an (n_layers, d_sae) table of per-target norms. That raised a shape error unless a leading dimension happened to equal n_layers, in which case it silently broadcast, and the activations were never divided back by the norm as encode does. Use the layer's decoder norm concatenated over its target layers, the row encode uses, and divide the activations by it.
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
CrossLayerTranscoder.encode_single_layeris used byFeatureAnalyzerfor CLT feature analysis, afterkeep_only_decoders_for_layer_from. Withsparsity_include_decoder_norm=True(the default, also used byexamples/train_pythia_clt_topk.py), it disagrees withencodein two ways.(..., d_sae)pre-activations bydecoder_norm_per_feature(layer=layer). That is an(n_layers, d_sae)table of per-target norms, with zero rows beforelayer.(batch, d_model)input this raisesRuntimeError: The size of tensor a (5) must match the size of tensor b (3).n_layers(e.g.seq_len == n_layers), it broadcasts silently and gives wrong activations.encodedoes.Reproduction
encode_single_layer(x[:, l], l)compared withencode(x)[:, l]on a 3-layer CLT:Change
layerofdecoder_norm_per_feature(), whichencodeuses, computed as the root sum of squares of the per-target norms, so it also works with the decoders kept bykeep_only_decoders_for_layer_from.Tests
tests/unit/test_clt.pychecks thatencode_single_layerequals the corresponding slice ofencode, with and withoutsparsity_include_decoder_normand with and withoutkeep_only_decoders_for_layer_from.sparsity_include_decoder_norm=Truecases fail before this change and pass after.ruff checkandruff format --checkare clean.