未验证 提交 fa10524d 编写于 作者: S Sławomir Siwek 提交者: GitHub

eltwise_div + scale [PHI] (#48484)

上级 9e9b705a
...@@ -95,6 +95,7 @@ const std::unordered_map<std::string, ExtraAttrPropertySet> ...@@ -95,6 +95,7 @@ const std::unordered_map<std::string, ExtraAttrPropertySet>
{"fuse_activation_alpha", ExtraAttrProperty::ONEDNN}, {"fuse_activation_alpha", ExtraAttrProperty::ONEDNN},
{"fuse_activation_beta", ExtraAttrProperty::ONEDNN}, {"fuse_activation_beta", ExtraAttrProperty::ONEDNN},
{"fuse_activation_scale", ExtraAttrProperty::ONEDNN}, {"fuse_activation_scale", ExtraAttrProperty::ONEDNN},
{"fused_output_scale", ExtraAttrProperty::ONEDNN},
{"fuse_alpha", ExtraAttrProperty::ONEDNN}, {"fuse_alpha", ExtraAttrProperty::ONEDNN},
{"fuse_beta", ExtraAttrProperty::ONEDNN}, {"fuse_beta", ExtraAttrProperty::ONEDNN},
{"fuse_relu", ExtraAttrProperty::ONEDNN}, {"fuse_relu", ExtraAttrProperty::ONEDNN},
......
...@@ -43,6 +43,12 @@ void ElementwiseKernel(const OneDNNContext& dev_ctx, ...@@ -43,6 +43,12 @@ void ElementwiseKernel(const OneDNNContext& dev_ctx,
dnnl::post_ops post_operations; dnnl::post_ops post_operations;
funcs::AppendActivation(dev_ctx, post_operations); funcs::AppendActivation(dev_ctx, post_operations);
if (dev_ctx.HasDnnAttr("fused_output_scale")) {
float scale_alpha =
PADDLE_GET_CONST(float, dev_ctx.GetDnnAttr("fused_output_scale"));
post_operations.append_eltwise(
1.0, dnnl::algorithm::eltwise_linear, scale_alpha, 0.0f);
}
auto* non_const_x = &x; auto* non_const_x = &x;
auto* non_const_y = &y; auto* non_const_y = &y;
......
...@@ -356,6 +356,42 @@ class ElementwiseActivationMkldnnFusePassTest_Mul_Sigmoid( ...@@ -356,6 +356,42 @@ class ElementwiseActivationMkldnnFusePassTest_Mul_Sigmoid(
self.act = paddle.nn.functional.sigmoid self.act = paddle.nn.functional.sigmoid
class ElementwiseScaleOneDNNFusePassTest_Add(
ElementwiseActivationMkldnnFusePassTest
):
def set_params(self):
self.operand = fluid.layers.elementwise_add
self.act_alpha = 0.6
self.act = paddle.scale
class ElementwiseScaleOneDNNFusePassTest_Sub(
ElementwiseActivationMkldnnFusePassTest
):
def set_params(self):
self.operand = fluid.layers.elementwise_sub
self.act_alpha = 0.6
self.act = paddle.scale
class ElementwiseScaleOneDNNFusePassTest_Mul(
ElementwiseActivationMkldnnFusePassTest
):
def set_params(self):
self.operand = fluid.layers.elementwise_mul
self.act_alpha = 0.6
self.act = paddle.scale
class ElementwiseScaleOneDNNFusePassTest_Div(
ElementwiseActivationMkldnnFusePassTest
):
def set_params(self):
self.operand = fluid.layers.elementwise_div
self.act_alpha = 0.6
self.act = paddle.scale
if __name__ == "__main__": if __name__ == "__main__":
paddle.enable_static() paddle.enable_static()
unittest.main() unittest.main()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册