Skip to content

Test Squeeze op converter in dynamic shape mode - #38146

Merged
tensorflow-copybara merged 5 commits into
tensorflow:masterfrom
tfeher:trt_squeeze_op_test
Apr 30, 2020
Merged

tensorflow-copybara merged 5 commits into
tensorflow:masterfrom
tfeher:trt_squeeze_op_test

Conversation

@tfeher

@tfeher tfeher commented Apr 1, 2020 •

Copy link
Copy Markdown
Contributor

This PR adds tests for dynamic shape mode for TF-TRT ConvertSqueeze.

  • The BuildAndRun method is extended with a profile generation step.
  • ConvertSqueeze is refactored: all test use TestParams
  • All previous test in ConvertSqueeze run both in implicit and explicit batch mode
  • Added new dynamic shapes tests (those run only in explicit batch mode)

PR #38118 is required for of this PR, please review that first. Tagging @bixia1 for review.

@google-ml-butler google-ml-butler Bot added the size:XL CL Change Size:Extra Large label Apr 1, 2020
@google-ml-butler
google-ml-butler Bot requested a review from joker-eph April 1, 2020 22:23
@tfeher tfeher changed the title Trt squeeze op tes Test Squeeze op converter in dynamic shape mode Apr 1, 2020
@gbaned gbaned self-assigned this Apr 2, 2020
@gbaned gbaned added comp:gpu:tensorrt Issues specific to TensorRT awaiting review Pull request awaiting review labels Apr 2, 2020
@gbaned
gbaned requested a review from bixia1 April 17, 2020 16:13
void AddTestTensor(
const string& name, const std::vector<int32>& dims, int batch_size = 1,
bool HasStaticShape(std::vector<int> dims) const {
return !absl::c_any_of(dims, [](int i) { return i == -1; });

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The existing code uses comparison i < 0, and there is a reason for this -- if the dimension values come from graph properties, the negative values actually represent the group of the symbolic dimension value.

bool HasStaticShape(const nvinfer1::Dims& dims) const {
if (dims.nbDims < 0) return false;
for (int i = 0; i < dims.nbDims; ++i) {
if (dims.d[i] < 0) return false;
}
return true;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The dimension values come from the test parameters that we define. I do not mind changing it to i < 0 to be on the safe side. Originally, I have assumed that the dimensions represent a PartialTensorShape. Is there any valid negative value apart from -1 for a PartialTensorShape?

@tensorflowbutler tensorflowbutler removed the awaiting review Pull request awaiting review label Apr 26, 2020
@gbaned

gbaned commented Apr 28, 2020

Copy link
Copy Markdown
Contributor

@tfeher Can you please check @bixia1 comments and keep us posted. Thanks!

@gbaned gbaned added the stat:awaiting response Status - Awaiting response from author label Apr 28, 2020
@tfeher

tfeher commented Apr 28, 2020

Copy link
Copy Markdown
Contributor Author

Thanks @bixia1 for the review. I am working on fixing the issues, I will update soon.

@tfeher tfeher left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have addressed the the issues. As part of making the test Value-Parameterized, I have done some additional changes:

  • Introduced TrtTestMode enum to enumerate test options: implicit/explicit batch & dynamic shape mode.
  • Added more test params (apart from TrtTestMode): Converter precision and input tensor dtype.

Using these the test coverage of ConvertSqueeze is improved:

  • Now all the test run in dynamic shape mode (earlier only those run in dynamic shape mode where we defined partial_input_dims manually).
  • The converter can be tested for multiple input types and conversion precision.

Additional changes:

  • Previously, precision mode was set through the precision_mode_to_test_ member variable of OpConverterTest. Removed the member variable and added precision_mode_to_test as an argument of OpConverterTest::Reset(). Reset calls the constructor of the Converter and sets the TensorRT precision mode there.

  • Noticed that precision_mode arg of OpConverterTest::BuildAndRun is not used. Removed it.

To facilitate reusing the same set of changes for other OpConverterTests, I have moved all the inptut tensor initializing result checking code into helper routines:

  • AddTestTensor (with trt_mode arg),
  • RunValidationAndConversion,
  • BuildAndRunConvertedNetwork

void AddTestTensor(
const string& name, const std::vector<int32>& dims, int batch_size = 1,
bool HasStaticShape(std::vector<int> dims) const {
return !absl::c_any_of(dims, [](int i) { return i == -1; });

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The dimension values come from the test parameters that we define. I do not mind changing it to i < 0 to be on the safe side. Originally, I have assumed that the dimensions represent a PartialTensorShape. Is there any valid negative value apart from -1 for a PartialTensorShape?

@gbaned gbaned removed the stat:awaiting response Status - Awaiting response from author label Apr 29, 2020

@bixia1 bixia1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Temporarily approving this for myself to further look at this within google.

@google-ml-butler google-ml-butler Bot added kokoro:force-run Tests on submitted change ready to pull PR ready for merge process labels Apr 30, 2020
@kokoro-team kokoro-team removed the kokoro:force-run Tests on submitted change label Apr 30, 2020
@tensorflow-copybara
tensorflow-copybara merged commit 609b1e8 into tensorflow:master Apr 30, 2020
@tfeher
tfeher deleted the trt_squeeze_op_test branch May 16, 2022 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes comp:gpu:tensorrt Issues specific to TensorRT ready to pull PR ready for merge process size:XL CL Change Size:Extra Large

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants