Skip to content
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

【SCU】[Paddle TensorRT No.63] Add pd_op.mish converter #69705

Merged
merged 15 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions paddle/fluid/pir/transforms/tensorrt/trt_op_marker_pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ DEFINE_GENERAL_PATTERN(Swish, paddle::dialect::SwishOp)
DEFINE_GENERAL_PATTERN(Log, paddle::dialect::LogOp)
DEFINE_GENERAL_PATTERN(Floor, paddle::dialect::FloorOp)
DEFINE_GENERAL_PATTERN(Roll, paddle::dialect::RollOp)
DEFINE_GENERAL_PATTERN(Mish, paddle::dialect::MishOp)
DEFINE_GENERAL_PATTERN(ThresholdedRelu, paddle::dialect::ThresholdedReluOp)

#undef DEFINE_GENERAL_PATTERN
Expand Down Expand Up @@ -2136,6 +2137,7 @@ class TrtOpMarkerPass : public pir::PatternRewritePass {
ADD_PATTERN(Log)
ADD_PATTERN(Floor)
ADD_PATTERN(Roll)
ADD_PATTERN(Mish)
ADD_PATTERN(ThresholdedRelu)
#if IS_TRT_VERSION_GE(8600)
ADD_PATTERN(Layer_norm)
Expand Down
15 changes: 15 additions & 0 deletions python/paddle/tensorrt/impls/activation.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,21 @@ def swish_silu_converter(network, paddle_op, inputs):
return trt_prod(network, inputs[0], layer_output)


@converter_registry.register("pd_op.mish", trt_version="8.x")
def mish_converter(network, paddle_op, inputs):
x = inputs[0]

softplus_layer = network.add_activation(x, trt.ActivationType.SOFTPLUS)
softplus_output = softplus_layer.get_output(0)

tanh_layer = network.add_activation(
softplus_output, trt.ActivationType.TANH
)
tanh_output = tanh_layer.get_output(0)

return trt_prod(network, x, tanh_output)


@converter_registry.register("pd_op.thresholded_relu", trt_version="8.x")
def thresholded_relu_converter(network, paddle_op, inputs):
x = inputs[0]
Expand Down
14 changes: 14 additions & 0 deletions test/tensorrt/test_converter_activation.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,19 @@ def test_trt_result(self):
self.check_trt_result()


class TestMishFloatTRTPattern(TensorRTBaseTest):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

再加几个单测,测试下1维度,4维度和3维度能不能通过,这个是因为旧ir下是通过通用plugin的方式进入trt的,我们还未支持,如果你这个测对了,可以合入

def setUp(self):
self.python_api = paddle.nn.functional.mish
self.api_args = {
"x": np.random.randn(2, 3).astype("float32"),
}
self.program_config = {"feed_list": ["x"]}
self.min_shape = {"x": [1, 3]}
self.max_shape = {"x": [5, 3]}

def test_trt_result(self):
self.check_trt_result()


if __name__ == '__main__':
unittest.main()