-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Tile supported #34388
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
Merged
Merged
Tile supported #34388
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a64ca4c
tile op
b3602sss c548804
more uts
b3602sss cc6fa5c
disable tile if trt6.0
b3602sss 1ea279e
typo
b3602sss fc105dc
fix timeout issue
b3602sss a26381e
opteller
b3602sss bc9be44
opteller remove duplicate code
b3602sss 9fcc16e
comments. test=document_fix
b3602sss a43d53d
modify PADDLE_ENFORCE.
b3602sss f495c0e
fix reduce_mean issue
b3602sss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| /* Copyright (c) 2018 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/inference/tensorrt/convert/op_converter.h" | ||
|
|
||
| namespace paddle { | ||
| namespace framework { | ||
| class Scope; | ||
| namespace proto { | ||
| class OpDesc; | ||
| } // namespace proto | ||
| } // namespace framework | ||
| } // namespace paddle | ||
|
|
||
| namespace paddle { | ||
| namespace inference { | ||
| namespace tensorrt { | ||
|
|
||
| /* | ||
| * ReshapeOp | ||
| */ | ||
| class TileOpConverter : public OpConverter { | ||
| public: | ||
| void operator()(const framework::proto::OpDesc& op, | ||
| const framework::Scope& scope, bool test_mode) override { | ||
| #if IS_TRT_VERSION_GE(7000) | ||
| VLOG(4) << "convert a fluid tile op to tensorrt tile layer"; | ||
|
|
||
| framework::OpDesc op_desc(op, nullptr); | ||
| // Declare inputs | ||
| auto* input = engine_->GetITensor(op_desc.Input("X")[0]); | ||
| nvinfer1::Dims input_shape = input->getDimensions(); | ||
| std::vector<int> repeat_times = | ||
| BOOST_GET_CONST(std::vector<int>, op_desc.GetAttr("repeat_times")); | ||
|
|
||
| nvinfer1::Dims output_dim = input_shape; | ||
| nvinfer1::Dims output_stride; | ||
| // If input_dims.nbDims + 1 < repeat_times.size() means we | ||
| // should add expand 1 on batchsize. trt doesn't support this behavior. | ||
| assert(input_shape.nbDims + 1 >= repeat_times.size()); | ||
| int diff = input_shape.nbDims + 1 - repeat_times.size(); | ||
| if (diff > 0) repeat_times.insert(repeat_times.begin(), diff, 1); | ||
|
|
||
| // Can't expand on batchsize | ||
| assert(repeat_times[0] == 1); | ||
b3602sss marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| output_stride.nbDims = input_shape.nbDims; | ||
| for (int i = 0; i < input_shape.nbDims; i++) { | ||
| output_dim.d[i] = output_dim.d[i] * repeat_times[i + 1]; | ||
| output_stride.d[i] = 1; | ||
| } | ||
|
|
||
| auto* layer = TRT_ENGINE_ADD_LAYER(engine_, Slice, *input, input_shape, | ||
| output_dim, output_stride); | ||
| layer->setMode(nvinfer1::SliceMode::kWRAP); | ||
| auto output_name = op_desc.Output("Out")[0]; | ||
| RreplenishLayerAndOutput(layer, "tile", {output_name}, test_mode); | ||
| #endif | ||
| } | ||
| }; | ||
|
|
||
| } // namespace tensorrt | ||
| } // namespace inference | ||
| } // namespace paddle | ||
|
|
||
| REGISTER_TRT_OP_CONVERTER(tile, TileOpConverter); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
python/paddle/fluid/tests/unittests/ir/inference/test_trt_tile_op.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| # Copyright (c) 2020 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. | ||
|
|
||
| from __future__ import print_function | ||
|
|
||
| import unittest | ||
| import numpy as np | ||
| from inference_pass_test import InferencePassTest | ||
| import paddle | ||
| import paddle.fluid as fluid | ||
| import paddle.fluid.core as core | ||
| from paddle.fluid.core import PassVersionChecker | ||
| from paddle.fluid.core import AnalysisConfig | ||
|
|
||
|
|
||
| class TRTTileTest(InferencePassTest): | ||
| def setUp(self): | ||
| with fluid.program_guard(self.main_program, self.startup_program): | ||
| data = fluid.data( | ||
| name="data", shape=[4, 3, 224, 256], dtype="float32") | ||
| tile_out = paddle.tile(x=data, repeat_times=[1, 1, 1, 1]) | ||
| out = fluid.layers.batch_norm(tile_out, is_test=True) | ||
|
|
||
| self.feeds = { | ||
| "data": np.random.random([4, 3, 224, 256]).astype("float32"), | ||
| } | ||
| self.enable_trt = True | ||
| self.trt_parameters = TRTTileTest.TensorRTParam( | ||
| 1 << 30, 16, 1, AnalysisConfig.Precision.Float32, False, False) | ||
| self.fetch_list = [out] | ||
|
|
||
| def test_check_output(self): | ||
| if core.is_compiled_with_cuda(): | ||
| use_gpu = True | ||
| self.check_output_with_option(use_gpu, flatten=True) | ||
| self.assertTrue( | ||
| PassVersionChecker.IsCompatible('tensorrt_subgraph_pass')) | ||
|
|
||
|
|
||
| class TRTTileExpandTest(InferencePassTest): | ||
| def setUp(self): | ||
| with fluid.program_guard(self.main_program, self.startup_program): | ||
| data = fluid.data(name="data", shape=[1, 1, 1, 1], dtype="float32") | ||
| tile_out = paddle.tile(x=data, repeat_times=[1, 4, 1080, 1920]) | ||
| out = fluid.layers.batch_norm(tile_out, is_test=True) | ||
|
|
||
| self.feeds = { | ||
| "data": np.random.random([1, 1, 1, 1]).astype("float32"), | ||
| } | ||
| self.enable_trt = True | ||
| self.trt_parameters = TRTTileExpandTest.TensorRTParam( | ||
| 1 << 30, 1, 1, AnalysisConfig.Precision.Float32, False, False) | ||
| self.fetch_list = [out] | ||
|
|
||
| def test_check_output(self): | ||
| if core.is_compiled_with_cuda(): | ||
| use_gpu = True | ||
| self.check_output_with_option(use_gpu, flatten=True) | ||
| self.assertTrue( | ||
| PassVersionChecker.IsCompatible('tensorrt_subgraph_pass')) | ||
|
|
||
|
|
||
| class TRTTileExpandStaticTest(InferencePassTest): | ||
| def setUp(self): | ||
| with fluid.program_guard(self.main_program, self.startup_program): | ||
| data = fluid.data(name="data", shape=[1, 1, 1, 1], dtype="float32") | ||
| tile_out = paddle.tile(x=data, repeat_times=[1, 4, 1080, 1920]) | ||
| out = fluid.layers.batch_norm(tile_out, is_test=True) | ||
|
|
||
| self.feeds = { | ||
| "data": np.random.random([1, 1, 1, 1]).astype("float32"), | ||
| } | ||
| self.enable_trt = True | ||
| self.trt_parameters = TRTTileExpandStaticTest.TensorRTParam( | ||
| 1 << 30, 1, 1, AnalysisConfig.Precision.Float32, True, False) | ||
| self.fetch_list = [out] | ||
|
|
||
| def test_check_output(self): | ||
| if core.is_compiled_with_cuda(): | ||
| use_gpu = True | ||
| self.check_output_with_option(use_gpu, flatten=True) | ||
| self.assertTrue( | ||
| PassVersionChecker.IsCompatible('tensorrt_subgraph_pass')) | ||
|
|
||
|
|
||
| class TRTTileExpandHalfTest(InferencePassTest): | ||
| def setUp(self): | ||
| with fluid.program_guard(self.main_program, self.startup_program): | ||
| data = fluid.data(name="data", shape=[1, 1, 1, 1], dtype="float32") | ||
| tile_out = paddle.tile(x=data, repeat_times=[1, 4, 1080, 1920]) | ||
| out = fluid.layers.batch_norm(tile_out, is_test=True) | ||
|
|
||
| self.feeds = { | ||
| "data": np.random.random([1, 1, 1, 1]).astype("float32"), | ||
| } | ||
| self.enable_trt = True | ||
| self.trt_parameters = TRTTileExpandHalfTest.TensorRTParam( | ||
| 1 << 30, 1, 1, AnalysisConfig.Precision.Half, False, False) | ||
| self.fetch_list = [out] | ||
|
|
||
| def test_check_output(self): | ||
| if core.is_compiled_with_cuda(): | ||
| use_gpu = True | ||
| self.check_output_with_option(use_gpu, flatten=True) | ||
| self.assertTrue( | ||
| PassVersionChecker.IsCompatible('tensorrt_subgraph_pass')) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.