diff --git a/ppcls/engine/train/train.py b/ppcls/engine/train/train.py index 639e2d478be52241a3b6798973875db177f0bd19..cf7f6573407d2597ca4db39ee96ed55769f81587 100644 --- a/ppcls/engine/train/train.py +++ b/ppcls/engine/train/train.py @@ -61,7 +61,8 @@ def train_epoch(engine, epoch_id, print_batch_step): if (iter_id + 1) % engine.update_freq == 0: for i in range(len(engine.optimizer)): # optimizer.step() with auto amp - engine.scaler.minimize(engine.optimizer[i], scaled) + engine.scaler.step(engine.optimizer[i]) + engine.scaler.update() if (iter_id + 1) % engine.update_freq == 0: # clear grad diff --git a/ppcls/engine/train/train_fixmatch.py b/ppcls/engine/train/train_fixmatch.py index 6404af16fb6d508a246ff05dd3ebc581dc1b69ad..26a3daa7494a77590e92e7dfabf29c43e1f649dc 100644 --- a/ppcls/engine/train/train_fixmatch.py +++ b/ppcls/engine/train/train_fixmatch.py @@ -75,7 +75,9 @@ def train_epoch_fixmatch(engine, epoch_id, print_batch_step): scaled.backward() for i in range(len(engine.optimizer)): - engine.scaler.minimize(engine.optimizer[i], scaled) + # optimizer.step() with auto amp + engine.scaler.step(engine.optimizer[i]) + engine.scaler.update() # step lr(by step) for i in range(len(engine.lr_sch)): diff --git a/ppcls/engine/train/train_metabin.py b/ppcls/engine/train/train_metabin.py index f0413fb47b96f604bbf0a09f4ea52fe6e58bcc96..d1d50f1d462c60a4c96fa8cd7385c58392b8bc48 100644 --- a/ppcls/engine/train/train_metabin.py +++ b/ppcls/engine/train/train_metabin.py @@ -201,7 +201,11 @@ def backward(engine, loss, optimizer): optimizer.clear_grad() scaled = engine.scaler.scale(loss) scaled.backward() - engine.scaler.minimize(optimizer, scaled) + + # optimizer.step() with auto amp + engine.scaler.step(optimizer) + engine.scaler.update() + for name, layer in engine.model.backbone.named_sublayers(): if "gate" == name.split('.')[-1]: layer.clip_gate()