Skip to content

Commit

Permalink
🐛Should consider ddp
Browse files Browse the repository at this point in the history
  • Loading branch information
carefree0910 committed Jan 4, 2025
1 parent 1f75321 commit 5803bc2
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions core/learn/callbacks/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from ..schedulers import WarmupScheduler
from ..modules.common import EMA
from ...toolkit import console
from ...toolkit.misc import is_ddp
from ...toolkit.misc import shallow_copy_dict
from ...toolkit.types import tensor_dict_type

Expand Down Expand Up @@ -101,9 +102,12 @@ def before_summary(self, trainer: ITrainer) -> None:
)
msg_fmt = f"{'{}'} parameter(s) will be {'{}'} under '{'{}'}':"
param_names = []
is_ddp_mode = is_ddp()
if freeze:
num_frozen = 0
for name, param in model.named_parameters():
if is_ddp_mode:
name = name[len("module.") :]
if re.match(freeze, name):
num_frozen += 1
param.requires_grad_(False)
Expand All @@ -112,6 +116,8 @@ def before_summary(self, trainer: ITrainer) -> None:
elif freeze_except:
num_trainable = 0
for name, param in model.named_parameters():
if is_ddp_mode:
name = name[len("module.") :]
if not re.match(freeze_except, name):
param.requires_grad_(False)
else:
Expand Down

0 comments on commit 5803bc2

Please sign in to comment.