Skip to content

Commit

Permalink
Reduce memory use when loading model (#327)
Browse files Browse the repository at this point in the history
* No grad when extracting weights

* Remove circular reference
  • Loading branch information
slavachalnev authored Jun 21, 2023
1 parent 4f3e143 commit 3cd9436
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions transformer_lens/hook_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ def setup(self):
self.mod_dict = {}
self.hook_dict: Dict[str, HookPoint] = {}
for name, module in self.named_modules():
if name == "":
continue
module.name = name
self.mod_dict[name] = module
if "HookPoint" in str(type(module)):
Expand Down
4 changes: 4 additions & 0 deletions transformer_lens/loading_from_pretrained.py
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,10 @@ def get_pretrained_state_dict(
)

# Load model weights, and fold in layer norm weights

for param in hf_model.parameters():
param.requires_grad = False

if cfg.original_architecture == "GPT2LMHeadModel":
state_dict = convert_gpt2_weights(hf_model, cfg)
elif cfg.original_architecture == "GPTNeoForCausalLM":
Expand Down

0 comments on commit 3cd9436

Please sign in to comment.