Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

revised loading to recycle state dict #706

Merged
merged 2 commits into from
Sep 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions transformer_lens/HookedTransformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
alteration of activations in individual components like attention heads and MLP layers, facilitating
a deeper understanding of the internal workings of transformers like GPT-2.
"""

import logging
import os
from typing import Dict, List, NamedTuple, Optional, Tuple, Union, cast, overload
Expand Down Expand Up @@ -1570,7 +1569,10 @@ def load_and_process_state_dict(
# so that quantization settings are not lost
self.load_state_dict(state_dict, assign=True, strict=False)
else:
self.load_state_dict(state_dict, strict=False)
state_dict_keys = list(state_dict.keys())
for key in state_dict_keys:
self.load_state_dict({key: state_dict[key]}, strict=False)
del state_dict[key]

def fill_missing_keys(self, state_dict):
return loading.fill_missing_keys(self, state_dict)
Expand Down
Loading