Skip to content

Fix inconsistent IR when printing R.nn.pad operator #17567

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

Closed
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
2 changes: 2 additions & 0 deletions include/tvm/relax/attrs/nn.h
Original file line number Diff line number Diff line change
Expand Up @@ -562,12 +562,14 @@ struct AttentionAttrs : public tvm::AttrsNode<AttentionAttrs> {
/*! \brief Attributes used for the padding operator */
struct PadAttrs : public tvm::AttrsNode<PadAttrs> {
Array<Integer> pad_width;
FloatImm pad_value;
tvm::String pad_mode;

TVM_DECLARE_ATTRS(PadAttrs, "relay.attrs.PadAttrs") {
TVM_ATTR_FIELD(pad_width).describe(
"Number of values padded to the edges of each axis, "
"in the format of (before_1, after_1, ..., before_N, after_N)");
TVM_ATTR_FIELD(pad_value).describe("The value to fill in padded area with");
TVM_ATTR_FIELD(pad_mode)
.set_default("constant")
.describe(
Expand Down
2 changes: 1 addition & 1 deletion python/tvm/relax/transform/legalize_ops/nn.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def _nn_pad(bb: BlockBuilder, call: Call) -> Expr:
call.args[0],
pad_before=pad_before,
pad_after=pad_after,
pad_value=float(call.args[1].data.numpy()),
pad_value=call.attrs.pad_value,
primfunc_name_hint="pad",
)

Expand Down
2 changes: 1 addition & 1 deletion python/tvm/relay/frontend/tensorflow_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -2359,7 +2359,7 @@ def _impl(inputs, attr, params, mod):
else:
paddings = tuple(tuple(l) for l in padlist)
attr["pad_width"] = paddings
attr["pad_value"] = 0
attr["pad_value"] = _expr.const(0)
new_inputs = [inputs[0]]
if name == "PadV2":
try:
Expand Down
8 changes: 4 additions & 4 deletions src/relax/op/nn/nn.cc
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,13 @@ TVM_REGISTER_OP("relax.nn.log_softmax")
/* relax.nn.pad */
TVM_REGISTER_NODE_TYPE(PadAttrs);

Expr pad(Expr data, Array<Integer> pad_width, Expr pad_value, String pad_mode) {
Expr pad(Expr data, Array<Integer> pad_width, FloatImm pad_value, String pad_mode) {
auto attrs = make_object<PadAttrs>();
attrs->pad_width = std::move(pad_width);
attrs->pad_value = pad_value;
attrs->pad_mode = std::move(pad_mode);
static const Op& op = Op::Get("relax.nn.pad");
return Call(op, {data, pad_value}, Attrs(attrs), {});
return Call(op, {data}, Attrs(attrs), {});
}

TVM_REGISTER_GLOBAL("relax.op.nn.pad").set_body_typed(pad);
Expand Down Expand Up @@ -171,9 +172,8 @@ StructInfo InferStructInfoPad(const Call& call, const BlockBuilder& ctx) {
}

TVM_REGISTER_OP("relax.nn.pad")
.set_num_inputs(2)
.set_num_inputs(1)
.add_argument("data", "Tensor", "The input tensor.")
.add_argument("pad_value", "Tensor", "The value to fill in padded area with.")
.set_attrs_type<PadAttrs>()
.set_attr<FInferStructInfo>("FInferStructInfo", InferStructInfoPad)
.set_attr<Bool>("FPurity", Bool(true));
Expand Down
Loading