Skip to content

Conversation

@akmaru
Copy link
Contributor

@akmaru akmaru commented May 25, 2021

Fixed the omission modify pad_value from Attr to Args of `relay.nn.pad ' by the following commit.

78657e1

@akmaru
Copy link
Contributor Author

akmaru commented May 25, 2021

By the way, are there suitable codeplaces of dynamic_cast util functions to relay ops from python?
If any, it should modularize the sequence of check and take constant from Relay.Constant as a function, for example, as_const_scalar.

Copy link
Contributor

@comaniac comaniac left a comment

Choose a reason for hiding this comment

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

Can you add a test case?
Also cc @trevor-m

@trevor-m
Copy link
Contributor

Thanks @akmaru
Were you able to test the runtime with this change in place? I think we also need to edit the input signature for the pad converter otherwise there will be a runtime error.

https://github.com/apache/tvm/blob/main/src/runtime/contrib/tensorrt/tensorrt_ops.cc#L1060
Should now be {kTensor, kWeight} instead of {kTensor}

run_and_verify_func(get_graph((1, 8, 16, 16), [[0, 0], [0, 0], [0, 1], [2, 0]], pad_value=-1.0e30))
run_and_verify_func(get_graph((1, 8, 3, 16, 16), [[0, 0], [0, 0], [0, 0], [0, 0], [0, 0]]))

run_and_verify_func(get_graph((1, 8, 3, 16, 16), [[0, 0], [0, 0], [0, 0], [0, 0], [0, 0]], pad_value=-1.0e30))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the test cases.

@akmaru
Copy link
Contributor Author

akmaru commented May 25, 2021

@trevor-m

Were you able to test the runtime with this change in place? I think we also need to edit the input signature for the pad converter otherwise there will be a runtime error.

Umm, I haven't encountered runtime error in my running.
(I have encountered this error compiling Tiny-YOLOv3 DarkNet and I have confirmed it is passed by this change.)

Though, it should be fix, so I'll do it!

class PadOpConverter : public TensorRTOpConverter {
public:
PadOpConverter() : TensorRTOpConverter({kTensor}) {}
PadOpConverter() : TensorRTOpConverter({kTensor, kWeight}) {}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added pad_value input into PadOpConverter.

Comment on lines 726 to 727
assert isinstance(args[1], relay.Constant)
if len(args[1].checked_type.shape) == 0 and args[1].data.numpy().item() != 0.0:

Choose a reason for hiding this comment

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

I think it's better to check type of pad_value with if instead of assert because it may be Expr.

I suggest the following code, including the fix of checking the shape of pad_value,

Suggested change
assert isinstance(args[1], relay.Constant)
if len(args[1].checked_type.shape) == 0 and args[1].data.numpy().item() != 0.0:
if (not isinstance(args[1], relay.Constant) or
len(args[1].checked_type.shape) != 0 or
args[1].data.numpy().item() != 0.0):

Copy link
Contributor

Choose a reason for hiding this comment

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

It shouldn't be Expr anyways if the pad mode is constant.

Choose a reason for hiding this comment

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

I think pad_mode="constant" just means padding by pad_value, not type of pad_value is relay.Constant.

nn.pad allows Expr for pad_value.

pad_value: float, or tvm.relay.Expr, optional, default=0
The value used for padding

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm you're right. I didn't notice that constant mode doesn't enforce constant node. @akmaru please change accordingly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed by e50bc43, please review again.

@tqchen
Copy link
Member

tqchen commented Jun 4, 2021

gentle ping @akmaru to resolve the lint error

@comaniac
Copy link
Contributor

comaniac commented Jul 6, 2021

@akmaru not sure if the CI failure is related to this PR. Please fix it or retrigger the CI otherwise.

@comaniac
Copy link
Contributor

Gentle ping @akmaru

@trevor-m
Copy link
Contributor

@akmaru Could you resolve the conflict?

ylc added a commit to ylc/tvm that referenced this pull request Sep 28, 2021
trevor-m pushed a commit to neo-ai/tvm that referenced this pull request Sep 28, 2021
@comaniac
Copy link
Contributor

Gentle ping @akmaru please resolve the conflict and pass the CI.

@masahi
Copy link
Member

masahi commented Jan 9, 2022

This was partially addressed in #9858. @akmaru can you update?

@jroesch jroesch added the needs-triage PRs or issues that need to be investigated by maintainers to find the right assignees to address it label Jan 19, 2022
@areusch
Copy link
Contributor

areusch commented Apr 11, 2022

closing due to inactivity, but feel free to reopen!

@areusch areusch closed this Apr 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-triage PRs or issues that need to be investigated by maintainers to find the right assignees to address it status: accepted

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants