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

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
11 changes: 11 additions & 0 deletions python/paddle/tensorrt/impls/manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ 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, axis = inputs
Copy link
Contributor

Choose a reason for hiding this comment

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

if xxx.get_defining_op():
拿到value
else:
axis=inputs[2]

reshape_layer = network.add_shuffle(index_tensor)
reshape_layer.reshape_dims = (-1,)
gather_layer = network.add_gather(
input_tensor, reshape_layer.get_output(0), axis
)
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
32 changes: 32 additions & 0 deletions test/tensorrt/test_converter_manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,5 +567,37 @@ 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": np.array([1]).astype("int32"),
}
self.program_config = {"feed_list": ["x", "index", "axis"]}
Copy link
Contributor

Choose a reason for hiding this comment

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

加一个axis为int输入的情况

self.min_shape = {"x": [1, 4, 10], "index": [1], "axis": [1]}
self.max_shape = {"x": [5, 4, 10], "index": [5], "axis": [1]}

def test_trt_result(self):
self.check_trt_result()


class TestGatherCase1TRTPattern(TensorRTBaseTest):
def setUp(self):
self.python_api = paddle.gather
self.api_args = {
"x": np.random.random([3, 4, 10]).astype("int64"),
"index": np.array([0, 2]).astype("int64"),
"axis": np.array([1]).astype("int32"),
}
self.program_config = {"feed_list": ["x", "index", "axis"]}
self.min_shape = {"x": [1, 4, 10], "index": [1], "axis": [1]}
self.max_shape = {"x": [5, 4, 10], "index": [5], "axis": [1]}

def test_trt_result(self):
self.check_trt_result()


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