Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix ema and edgenext yaml bugs #703

Merged
merged 3 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions configs/edgenext/edgenext_base_ascend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mode: 0
distribute: True
num_parallel_workers: 8
val_while_train: True
seed: 1

# dataset
dataset: 'imagenet'
Expand Down Expand Up @@ -60,4 +61,5 @@ filter_bias_and_bn: True
momentum: 0.9
weight_decay: 0.05
loss_scale: 1024
drop_overflow_update: True
use_nesterov: False
2 changes: 2 additions & 0 deletions configs/edgenext/edgenext_small_ascend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mode: 0
distribute: True
num_parallel_workers: 8
val_while_train: True
seed: 1

# dataset
dataset: 'imagenet'
Expand Down Expand Up @@ -59,4 +60,5 @@ filter_bias_and_bn: True
momentum: 0.9
weight_decay: 0.05
loss_scale: 1024
drop_overflow_update: True
use_nesterov: False
2 changes: 2 additions & 0 deletions configs/edgenext/edgenext_x_small_ascend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mode: 0
distribute: True
num_parallel_workers: 8
val_while_train: True
seed: 1

# dataset
dataset: 'imagenet'
Expand Down Expand Up @@ -59,4 +60,5 @@ filter_bias_and_bn: True
momentum: 0.9
weight_decay: 0.05
loss_scale: 1024
drop_overflow_update: True
use_nesterov: False
2 changes: 2 additions & 0 deletions configs/edgenext/edgenext_xx_small_ascend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mode: 0
distribute: True
num_parallel_workers: 8
val_while_train: True
seed: 1

# dataset
dataset: 'imagenet'
Expand Down Expand Up @@ -58,4 +59,5 @@ filter_bias_and_bn: True
momentum: 0.9
weight_decay: 0.05
loss_scale: 1024
drop_overflow_update: True
use_nesterov: False
8 changes: 6 additions & 2 deletions mindcv/utils/train_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ def construct(self, *inputs):
# if there is no overflow, do optimize
if not overflow:
loss = self.gradient_accumulation(loss, grads)
if self.ema:
loss = F.depend(loss, self.ema_update())
else:
# apply grad reducer on grads
grads = self.grad_reducer(grads)
Expand All @@ -161,14 +163,16 @@ def construct(self, *inputs):
# if there is no overflow, do optimize
if not overflow:
loss = F.depend(loss, self.optimizer(grads))
if self.ema:
loss = F.depend(loss, self.ema_update())
else: # scale_sense = loss_scale: Tensor --> TrainOneStepCell.construct
if self.accumulate_grad:
loss = self.gradient_accumulation(loss, grads)
else:
grads = self.grad_reducer(grads)
loss = F.depend(loss, self.optimizer(grads))

if self.ema:
loss = F.depend(loss, self.ema_update())
if self.ema:
loss = F.depend(loss, self.ema_update())

return loss