Skip to content

Commit

Permalink
[TRT] Fix reshape op after it was changed to no longer have dynamic i…
Browse files Browse the repository at this point in the history
…nputs
  • Loading branch information
Trevor Morris authored and trevor-m committed Jul 14, 2020
1 parent 13996b5 commit 57ff9f9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
3 changes: 0 additions & 3 deletions python/tvm/relay/tensorrt.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,6 @@ def reshape_whitelist_fn(attrs, args): # pylint: disable=unused-variable
if args[0].checked_type.dtype != "float32":
print("Only float32 inputs are supported for TensorRT.")
return False
if not isinstance(args[1], Constant):
print("reshape: New shape must be a constant.")
return False
if any([x < -1 for x in map(int, attrs.newshape)]):
print("reshape: new shape dims must be explicit.")
return False
Expand Down
9 changes: 4 additions & 5 deletions src/runtime/contrib/tensorrt/tensorrt_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -1033,18 +1033,17 @@ class TransposeOpConverter : public TrtOpConverter {

class ReshapeOpConverter : public TrtOpConverter {
public:
ReshapeOpConverter() : TrtOpConverter({kTensor, kWeight}) {}
ReshapeOpConverter() : TrtOpConverter({kTensor}) {}

void Convert(AddTrtLayerParams* params) const {
auto input = params->inputs.at(0).tensor;
const auto* attrs = params->call->attrs.as<ReshapeAttrs>();
CHECK(attrs->newshape);
CHECK_EQ(attrs->reverse, false);
std::vector<int> new_shape;
const int start_index = TRT_HAS_IMPLICIT_BATCH(params) ? 1 : 0;
for (size_t i = start_index; i < attrs->newshape.value().size(); ++i) {
CHECK(attrs->newshape.value()[i].defined());
const int value = attrs->newshape.value()[i].as<IntImmNode>()->value;
for (size_t i = start_index; i < attrs->newshape.size(); ++i) {
CHECK(attrs->newshape[i].defined());
const int value = attrs->newshape[i]->value;
CHECK_GE(value, -1);
new_shape.push_back(value);
}
Expand Down

0 comments on commit 57ff9f9

Please sign in to comment.