未验证 提交 83ed5195 编写于 作者: G gaotingquan

fix: set use_fp16_test to True when AMP O2 is enabled

上级 efde56ff
......@@ -24,8 +24,6 @@ AMP:
use_dynamic_loss_scaling: True
# O2: pure fp16
level: O2
# only FP16 evaluation is supported when AMP O2 is enabled
use_fp16_test: True
# model architecture
Arch:
......
......@@ -34,12 +34,10 @@ Loss:
# mixed precision training
AMP:
scale_loss: 128.0
use_dynamic_loss_scaling: True
# O2: pure fp16
level: O2
# only FP16 evaluation is supported when AMP O2 is enabled
use_fp16_test: True
scale_loss: 128.0
use_dynamic_loss_scaling: True
# O2: pure fp16
level: O2
Optimizer:
name: Momentum
......
......@@ -58,8 +58,15 @@ def classification_eval(engine, epoch_id=0):
batch[1] = batch[1].reshape([-1, 1]).astype("int64")
# image input
if engine.amp and engine.config["AMP"].get("use_fp16_test", False):
if engine.amp and (
engine.config['AMP'].get("level", "O1").upper() == "O2" or
engine.config["AMP"].get("use_fp16_test", False)):
amp_level = engine.config['AMP'].get("level", "O1").upper()
if amp_level == "O2":
msg = "Only support FP16 evaluation when AMP O2 is enabled."
logger.warning(msg)
with paddle.amp.auto_cast(
custom_black_list={
"flatten_contiguous_range", "greater_than"
......
......@@ -162,12 +162,21 @@ def main(args):
init_model(global_config, train_prog, exe)
if 'AMP' in config:
if config["AMP"].get("level", "O1").upper() == "O2":
use_fp16_test = True
msg = "Only support FP16 evaluation when AMP O2 is enabled."
logger.warning(msg)
elif "use_fp16_test" in config["AMP"]:
use_fp16_test = config["AMP"].get["use_fp16_test"]
else:
use_fp16_test = False
optimizer.amp_init(
device,
scope=paddle.static.global_scope(),
test_program=eval_prog
if global_config["eval_during_train"] else None,
use_fp16_test=config["AMP"].get("use_fp16_test", False))
use_fp16_test=use_fp16_test)
if not global_config.get("is_distributed", True):
compiled_train_prog = program.compile(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册