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

【BUPT】【Paddle TensorRT No.38】Add pd_op.gather converter #69714

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
9 changes: 9 additions & 0 deletions python/paddle/tensorrt/impls/manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ def reshape_converter(network, paddle_op, inputs):
return shuffle_layer.get_output(0)


@converter_registry.register("pd_op.gather", trt_version="8.x")
def gather_converter(network, paddle_op, inputs):
input_tensor, index_tensor, *_ = inputs
Copy link
Contributor

Choose a reason for hiding this comment

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

参考paddle/fluid/inference/tensorrt/convert/gather_op.cc

Copy link
Contributor

Choose a reason for hiding this comment

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

index和axis还有pir::value的情况,这里没有实现,另外,axis是输入,而不是属性

gather_layer = network.add_gather_v2(
input_tensor, index_tensor, trt.GatherMode.DEFAULT
)
return gather_layer.get_output(0)


@converter_registry.register("pd_op.gather_nd", trt_version="8.x")
def gather_nd_converter(network, paddle_op, inputs):
input_tensor, indices_tensor = inputs
Expand Down
20 changes: 20 additions & 0 deletions test/tensorrt/test_converter_manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,5 +567,25 @@ def test_trt_result(self):
self.check_trt_result()


class TestGatherTRTPattern(TensorRTBaseTest):
def setUp(self):
self.python_api = paddle.gather
self.api_args = {
"x": np.random.random([3, 4, 10]).astype("float32"),
"index": np.array([0, 2]).astype("int64"),
"axis": 1,
Copy link
Contributor

Choose a reason for hiding this comment

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

axis还有pir::value的情况,用np.array组网,放到feed_list中

}
self.program_config = {"feed_list": ["x", "index"]}
self.min_shape = {"x": [1, 4, 10], "index": [1]}
self.max_shape = {"x": [5, 4, 10], "index": [5]}
self.dynamic_shape = {
"x": {"min": [1, 4, 10], "max": [5, 4, 10], "opt": [3, 4, 10]},
"index": {"min": [1], "max": [5], "opt": [2]},
}

def test_trt_result(self):
self.check_trt_result()


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