feat(capture): wire mlp_in/mlp_out hooks for transcoder training - #206
Merged
Conversation
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
Wires the
mlp_inandmlp_outcapture hooks into the decoder layers of gemma3, gemma4, qwen3, qwen3_moe, and qwen3_next. These were already first-class hook names in the capture type system (HookName,_HOOK_NAME_TO_ID,_VALID_HOOK_NAMES) but had no tap insertion points in any model, so requesting them produced nothing.mlp_in— the normalized activation fed into the MLP/MoE sublayer (output of the pre-MLP norm).mlp_out— the MLP/MoE branch the sublayer writes back to the residual stream (after any post-MLP norm / layer-scale), so the residual-stream decompositionpost_block == post_attn + mlp_outholds wherepost_attnis captured after the deferred add (qwen family, gemma4).Why
These are the paired activations required to train transcoders (a transcoder learns
mlp_in → mlp_outfor a layer; cross-layer transcoders consume them across layers, aligned per token). Until now the capture machinery exposed only residual-stream points (pre_attn/post_attn/post_block), from which MLP input/output could only be indirectly reconstructed.Notes
mlp_in/mlp_outare intentionally excluded from the:allfan-out so:allstays model-agnostic and never reserves buffers on models that don't wire them. Request them explicitly, e.g.{"mlp_in": [12], "mlp_out": [12]}.mlp_incovers only the dense path (the parallel MoE branch is normed separately);mlp_outalways captures the combined branch.Scope / follow-up
qwen3_next.pyis wired but its unit test skips:qwen3_next.pyandqwen3_5.pycurrently fail to import onfeat/integrationbecause the upstream mamba refactor (vllm-project#41126) movedmamba.gdn_linear_attninto themamba.gdnpackage and the integration merge (#186) left these two files pointing at the dead path. That import breakage is pre-existing and unrelated to this change; it will be fixed separately (it needs GPU validation on the linear-attn path). Once fixed, Qwen3-Next/Qwen3.5 inherit the wiring here and the skipped test runs.