name | about | labels |
---|---|---|
Bug Report | Use this template for reporting a bug | kind/bug |
Ascend
/GPU
/CPU
):Uncomment only one
/device <>
line, hit enter to put that in a new line, and remove leading whitespaces from that line:
/device gpu
test_ir_fusion_combine_momentum_weight
test_ir_fusion_fused_scale_momentum_decay
def test_ir_fusion_fused_scale_momentum_decay():
clear_files()
context.set_context(save_graphs=True)
epoch_size = 1
batch_size = 1
num_classes = 3
input_np = np.random.uniform(0.0, 1.0,
size=[batch_size, 3, 2, 2]).astype(np.float16)
label_np = np.ones([batch_size, num_classes]).astype(np.float32)
net = Net(3, num_classes)
loss = SoftmaxCrossEntropyWithLogits(sparse=False)
opt = Momentum(learning_rate=0.01, momentum=0.9,
params=filter(lambda x: x.requires_grad, net.get_parameters()),
weight_decay=1.5, loss_scale=1.5)
lsm = FixedLossScaleManager(loss_scale=1.5, drop_overflow_update=False)
net = amp.build_train_network(net, opt, loss,
level="O3", loss_scale_manager=lsm)
net.set_train()
for epoch in range(0, epoch_size):
net(Tensor(input_np), Tensor(label_np))
result = find_files('hwopt*momentum_scale_fusion*ir',
'FusedWeightScaleApplyMomentum')
> assert result == '2'
E AssertionError: assert '0' == '2'
E - 0
E + 2
def test_ir_fusion_combine_momentum_weight():
clear_files()
context.set_context(save_graphs=True)
epoch_size = 1
batch_size = 1
num_classes = 3
input_np = np.random.uniform(0.0, 1.0,
size=[batch_size, 3, 2, 2]).astype(np.float16)
label_np = np.ones([batch_size, num_classes]).astype(np.float32)
net = Net2(3, num_classes)
loss = SoftmaxCrossEntropyWithLogits(sparse=False)
conv_params = list(filter(lambda x: 'conv' in x.name,
net.trainable_params()))
no_conv_params = list(filter(lambda x: 'conv' not in x.name,
net.trainable_params()))
group_params = [{'params': conv_params, 'weight_decay': 0.3},
{'params': no_conv_params, 'lr': 0.04},
{'order_params': net.trainable_params()}]
opt = Momentum(group_params, learning_rate=0.03, momentum=0.9,
loss_scale=1.3, weight_decay=0.7)
lsm = FixedLossScaleManager(loss_scale=1.3, drop_overflow_update=False)
net = amp.build_train_network(net, opt, loss, level="O3",
loss_scale_manager=lsm)
net.set_train()
for epoch in range(0, epoch_size):
net(Tensor(input_np), Tensor(label_np))
result = find_files('hwopt*combine_momentum*ir',
'CombineMomentumWeight')
> assert result == '2'
E AssertionError: assert '0' == '2'
pass
Appearance & Root Cause
问题:IR图中未出现预期融合算子
原因:由于ME前端的修改,进入到后端的IR图与原设定的apply_momentum_weight_scale_fusion pass不匹配,Cast(input)-->Depend(Cast(input)),不能正常融合。
Fix Solution
解决方法:修改适配apply_momentum_weight_scale_fusion pass,使其能够处理Depend(Cast(input))的情况。
关联PR:!16210:update apply_momentum_weight_scale_fusion pass
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
pytest -s
test_ir_fusion_combine_momentum_weight
test_ir_fusion_fused_scale_momentum_decay
result pass
登录 后才可以发表评论