Skip to content

Commit

Permalink
Merge pull request #124 from stanfordnlp/zen/unseenmodel
Browse files Browse the repository at this point in the history
[Minor] Support zero_grad as a module
frankaging authored Mar 4, 2024
2 parents 9798caf + 7ab3cf7 commit fcf4870
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pyvene/models/intervenable_base.py
Original file line number Diff line number Diff line change
@@ -310,7 +310,7 @@ def named_parameters(self, recurse=True):
if isinstance(v[0], TrainableIntervention):
ret_params += [(k + '.' + n, p) for n, p in v[0].named_parameters()]
return ret_params

def get_cached_activations(self):
"""
Return the cached activations with keys
@@ -399,6 +399,14 @@ def set_zero_grad(self):
if isinstance(v[0], TrainableIntervention):
v[0].zero_grad()

def zero_grad(self):
"""
The above, but for HuggingFace.
"""
for k, v in self.interventions.items():
if isinstance(v[0], TrainableIntervention):
v[0].zero_grad()

def save(
self, save_directory, save_to_hf_hub=False, hf_repo_name="my-awesome-model"
):

0 comments on commit fcf4870

Please sign in to comment.