Repository navigation
Conversation
Collaborator
|
Looks good, merging |
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.
Description
Fixes #1924 .
At
layer=0,stack_head_resultsandstack_neuron_resultsreturn an empty tensor shaped likehook_embed. It was created withtorch.zeros(..., device=self.model.cfg.device)and no dtype (1, 2, 3), so on a bf16 model, or a cache upcast to float64, layer 0 came back float32 while later layers followed the cache.The empty tensor now takes its dtype and device from the tensor it was already using for its shape (
pos_slice.apply(self["hook_embed"], dim=-2), projected whenproject_output_ontois set). In_stack_neuron_results_apply_ln_projected, the dtype is that tensor's dtype promoted with the cached LN scale and the projection, because thelayer >= 1result is computed from all three (float32 on a bf16 model, whose LN scales are float32).Type of change
Testing
I added
test_layer_zero_stacks_follow_the_cache_dtypetotests/unit/test_activation_cache.py.stack_head_results(0)andstack_neuron_results(0)are empty and matchhook_embed's dtype and devicestack_neuron_results(apply_ln=True, project_output_onto=d)has the same dtype at layers 0 and 1Before (
dev):After:
dev, layer 0 / layer 1stack_head_resultsstack_neuron_resultsstack_neuron_results(project_output_onto=d)stack_neuron_results(apply_ln=True, project_output_onto=d)make check-formatanduv run mypy .are clean.Checklist: