Skip to content

Commit

Permalink
Fix unused_parameters in pt18 (#290)
Browse files Browse the repository at this point in the history
  • Loading branch information
ckkelvinchan authored May 24, 2021
1 parent f9abfb1 commit b5c745d
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions configs/restorers/basicvsr/basicvsr_reds4.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,4 @@
load_from = None
resume_from = None
workflow = [('train', 1)]
find_unused_parameters = True
1 change: 1 addition & 0 deletions configs/restorers/basicvsr/basicvsr_vimeo90k_bd.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,4 @@
load_from = None
resume_from = None
workflow = [('train', 1)]
find_unused_parameters = True
1 change: 1 addition & 0 deletions configs/restorers/basicvsr/basicvsr_vimeo90k_bi.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,4 @@
load_from = None
resume_from = None
workflow = [('train', 1)]
find_unused_parameters = True
1 change: 1 addition & 0 deletions configs/restorers/iconvsr/iconvsr_reds4.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,4 @@
load_from = None
resume_from = None
workflow = [('train', 1)]
find_unused_parameters = True
1 change: 1 addition & 0 deletions configs/restorers/iconvsr/iconvsr_vimeo90k_bd.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,4 @@
load_from = None
resume_from = None
workflow = [('train', 1)]
find_unused_parameters = True
1 change: 1 addition & 0 deletions configs/restorers/iconvsr/iconvsr_vimeo90k_bi.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,4 @@
load_from = None
resume_from = None
workflow = [('train', 1)]
find_unused_parameters = True
7 changes: 3 additions & 4 deletions mmedit/models/restorers/basicvsr.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __init__(self,

# fix pre-trained networks
self.fix_iter = train_cfg.get('fix_iter', 0) if train_cfg else 0
self.generator.find_unused_parameters = False
self.is_weight_fixed = False

# count training steps
self.register_buffer('step_counter', torch.zeros(1))
Expand Down Expand Up @@ -74,14 +74,13 @@ def train_step(self, data_batch, optimizer):
"""
# fix SPyNet and EDVR at the beginning
if self.step_counter < self.fix_iter:
if not self.generator.find_unused_parameters:
self.generator.find_unused_parameters = True
if not self.is_weight_fixed:
self.is_weight_fixed = True
for k, v in self.generator.named_parameters():
if 'spynet' in k or 'edvr' in k:
v.requires_grad_(False)
elif self.step_counter == self.fix_iter:
# train all the parameters
self.generator.find_unused_parameters = False
self.generator.requires_grad_(True)

outputs = self(**data_batch, test_mode=False)
Expand Down

0 comments on commit b5c745d

Please sign in to comment.