Skip to content

Commit

Permalink
subtler fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Mickus Timothee committed Sep 25, 2023
1 parent 30ba781 commit a98a274
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion onmt/model_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,9 @@ def build_task_specific_model(
def has_grad_hook(module, input, output) -> None:
for param in module.parameters(recurse=False):
if param.requires_grad:
param.has_grad = True
# NB: we're looking at whether gradient will/has been computed, which is only the
# case when the module is training.
param.has_grad = module.training

for module in nmt_model.modules():
module.register_forward_hook(has_grad_hook)
Expand Down

0 comments on commit a98a274

Please sign in to comment.