-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
Fused elementwises kernels and ops #51427
Changes from 1 commit
bd117a0
eb1081b
2525681
3c8b7d3
462f006
b72bd52
90f9217
190e797
4f72943
1ad3f16
f93b1a7
e4be4cc
0dc0b06
079fb83
e52e35d
3651b8e
f4909e8
b587ed0
734f4fe
4322409
6d21d73
b0116a2
1705253
f0d836c
a3c7d2d
0f36edf
e1d5eb7
f119f6f
833c2f1
db0831f
93b0b48
2c20932
4e600b4
24decf5
8d60160
b977541
62ae00e
a9dadce
d93d827
8920095
47a4745
7d2fa1a
20c3c33
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,50 @@ | ||||||||||||||||||||||||||||||||||
type: "fused_elementwise_add" | ||||||||||||||||||||||||||||||||||
def { | ||||||||||||||||||||||||||||||||||
inputs { | ||||||||||||||||||||||||||||||||||
name: "X" | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
inputs { | ||||||||||||||||||||||||||||||||||
name: "Y" | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
outputs { | ||||||||||||||||||||||||||||||||||
name: "Out" | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
attrs { | ||||||||||||||||||||||||||||||||||
name: "axis" | ||||||||||||||||||||||||||||||||||
type: INT | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
extra { | ||||||||||||||||||||||||||||||||||
attrs { | ||||||||||||||||||||||||||||||||||
name: "x_data_format" | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||||||||||||||||||||||
type: STRING | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
attrs { | ||||||||||||||||||||||||||||||||||
name: "y_data_format" | ||||||||||||||||||||||||||||||||||
type: STRING | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
attrs { | ||||||||||||||||||||||||||||||||||
name: "alpha" | ||||||||||||||||||||||||||||||||||
type: FLOAT | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
attrs { | ||||||||||||||||||||||||||||||||||
name: "beta" | ||||||||||||||||||||||||||||||||||
type: FLOAT | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||
attrs { | ||||||||||||||||||||||||||||||||||
name: "Scale_x" | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
All attributes should be lowercase. We must unify it, as there are currently too many duplicates with quantization scales. |
||||||||||||||||||||||||||||||||||
type: FLOAT | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
attrs { | ||||||||||||||||||||||||||||||||||
name: "Scale_y" | ||||||||||||||||||||||||||||||||||
type: FLOAT | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
attrs { | ||||||||||||||||||||||||||||||||||
name: "Scale_out" | ||||||||||||||||||||||||||||||||||
type: FLOAT | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
attrs { | ||||||||||||||||||||||||||||||||||
name: "fuse_activation" | ||||||||||||||||||||||||||||||||||
type: STRING | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is also float There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All comments to |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
type: "fused_elementwise_div" | ||
def { | ||
inputs { | ||
name: "X" | ||
} | ||
inputs { | ||
name: "Y" | ||
} | ||
outputs { | ||
name: "Out" | ||
} | ||
attrs { | ||
name: "axis" | ||
type: INT | ||
} | ||
} | ||
extra { | ||
attrs { | ||
name: "x_data_format" | ||
type: STRING | ||
} | ||
attrs { | ||
name: "y_data_format" | ||
type: STRING | ||
} | ||
attrs { | ||
name: "alpha" | ||
type: FLOAT | ||
} | ||
attrs { | ||
name: "beta" | ||
type: FLOAT | ||
} | ||
attrs { | ||
name: "Scale_x" | ||
type: FLOAT | ||
} | ||
attrs { | ||
name: "Scale_y" | ||
type: FLOAT | ||
} | ||
attrs { | ||
name: "Scale_out" | ||
type: FLOAT | ||
} | ||
attrs { | ||
name: "fuse_activation" | ||
type: STRING | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
type: "fused_elementwise_mul" | ||
def { | ||
inputs { | ||
name: "X" | ||
} | ||
inputs { | ||
name: "Y" | ||
} | ||
outputs { | ||
name: "Out" | ||
} | ||
attrs { | ||
name: "axis" | ||
type: INT | ||
} | ||
} | ||
extra { | ||
attrs { | ||
name: "x_data_format" | ||
type: STRING | ||
} | ||
attrs { | ||
name: "y_data_format" | ||
type: STRING | ||
} | ||
attrs { | ||
name: "alpha" | ||
type: FLOAT | ||
} | ||
attrs { | ||
name: "beta" | ||
type: FLOAT | ||
} | ||
attrs { | ||
name: "Scale_x" | ||
type: FLOAT | ||
} | ||
attrs { | ||
name: "Scale_y" | ||
type: FLOAT | ||
} | ||
attrs { | ||
name: "Scale_out" | ||
type: FLOAT | ||
} | ||
attrs { | ||
name: "fuse_activation" | ||
type: STRING | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
type: "fused_elementwise_sub" | ||
def { | ||
inputs { | ||
name: "X" | ||
} | ||
inputs { | ||
name: "Y" | ||
} | ||
outputs { | ||
name: "Out" | ||
} | ||
attrs { | ||
name: "axis" | ||
type: INT | ||
} | ||
} | ||
extra { | ||
attrs { | ||
name: "x_data_format" | ||
type: STRING | ||
} | ||
attrs { | ||
name: "y_data_format" | ||
type: STRING | ||
} | ||
attrs { | ||
name: "alpha" | ||
type: FLOAT | ||
} | ||
attrs { | ||
name: "beta" | ||
type: FLOAT | ||
} | ||
attrs { | ||
name: "Scale_x" | ||
type: FLOAT | ||
} | ||
attrs { | ||
name: "Scale_y" | ||
type: FLOAT | ||
} | ||
attrs { | ||
name: "Scale_out" | ||
type: FLOAT | ||
} | ||
attrs { | ||
name: "fuse_activation" | ||
type: STRING | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "paddle/fluid/framework/op_registry.h" | ||
#include "paddle/fluid/operators/elementwise/elementwise_op.h" | ||
#include "paddle/fluid/operators/fused/fused_elementwise_op.h" | ||
|
||
namespace paddle { | ||
namespace operators { | ||
|
||
class FusedElementwiseAddOpMaker : public FusedElementwiseOpMaker { | ||
protected: | ||
std::string GetName() const override { return "Add"; } | ||
std::string GetEquation() const override { return "Out = X + Y"; } | ||
|
||
void AddInputX() override { | ||
AddInput( | ||
"X", | ||
"(Variable), Tensor or phi::DenseTensor of any dimensions. Its dtype " | ||
"should be int32, int64, float32, float64."); | ||
} | ||
|
||
void AddInputY() override { | ||
AddInput( | ||
"Y", | ||
"(Variable), Tensor or phi::DenseTensor of any dimensions. Its dtype " | ||
"should be int32, int64, float32, float64."); | ||
} | ||
|
||
std::string GetOpFuntionality() const override { | ||
return "Add two tensors element-wise"; | ||
} | ||
}; | ||
|
||
} // namespace operators | ||
} // namespace paddle | ||
namespace ops = paddle::operators; | ||
|
||
REGISTER_OPERATOR( | ||
fused_elementwise_add, | ||
ops::ElementwiseOp, | ||
ops::FusedElementwiseAddOpMaker, | ||
ops::ElementwiseOpInferVarType, | ||
paddle::framework::EmptyGradOpMaker<paddle::framework::OpDesc>, | ||
paddle::framework::EmptyGradOpMaker<paddle::imperative::OpBase>); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "paddle/fluid/framework/op_registry.h" | ||
#include "paddle/fluid/operators/elementwise/elementwise_op.h" | ||
#include "paddle/fluid/operators/fused/fused_elementwise_op.h" | ||
|
||
namespace paddle { | ||
namespace operators { | ||
|
||
class FusedElementwiseDivOpMaker : public FusedElementwiseOpMaker { | ||
protected: | ||
std::string GetName() const override { return "Div"; } | ||
std::string GetEquation() const override { return "Out = X / Y"; } | ||
|
||
void AddInputX() override { | ||
AddInput( | ||
"X", | ||
"(Variable), Tensor or phi::DenseTensor of any dimensions. Its dtype " | ||
"should be int32, int64, float32, float64."); | ||
} | ||
|
||
void AddInputY() override { | ||
AddInput( | ||
"Y", | ||
"(Variable), Tensor or phi::DenseTensor of any dimensions. Its dtype " | ||
"should be int32, int64, float32, float64."); | ||
} | ||
|
||
std::string GetOpFuntionality() const override { | ||
return "Divide two tensors element-wise"; | ||
} | ||
}; | ||
|
||
} // namespace operators | ||
} // namespace paddle | ||
namespace ops = paddle::operators; | ||
|
||
REGISTER_OPERATOR( | ||
fused_elementwise_div, | ||
ops::ElementwiseOp, | ||
ops::FusedElementwiseDivOpMaker, | ||
ops::ElementwiseOpInferVarType, | ||
paddle::framework::EmptyGradOpMaker<paddle::framework::OpDesc>, | ||
paddle::framework::EmptyGradOpMaker<paddle::imperative::OpBase>); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we change it already, please change
elt
to eithereltwise
orelementwise
as it's more common among other passes.