Skip to content
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

[Relay] Handle pad value coming from Tensor instead of scalar #14735

Merged
merged 2 commits into from
Apr 28, 2023
Merged
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: 1 addition & 1 deletion src/relay/op/nn/pad.cc
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ Array<te::Tensor> PadCompute(const Attrs& attrs, const Array<te::Tensor>& inputs
pad_after.push_back(pad_width[i][1]);
}
te::Tensor cast_pad_value = topi::cast(inputs[1], inputs[0]->dtype);
const PrimExpr& pad_value = cast_pad_value(Array<PrimExpr>());
const PrimExpr& pad_value = cast_pad_value(Array<PrimExpr>(inputs[1]->shape.size(), 0));
return Array<te::Tensor>{topi::pad(inputs[0], pad_before, pad_after, pad_value, "T_pad",
topi::kElementWise, param->pad_mode)};
}
Expand Down
19 changes: 19 additions & 0 deletions tests/python/relay/test_op_level2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1444,6 +1444,25 @@ def _test_run(dtype):
_test_run("int32")


def test_pad_value_in_array():
A = relay.var("A", shape=(32, 32), dtype="int8")

# Extract pad value from an array
p0 = relay.Constant(tvm.nd.array(np.array([2], dtype="int8")))
p1 = relay.nn.pad(A, pad_value=p0, pad_width=((1, 1), (1, 1)))

func = relay.Function(relay.analysis.free_vars(p1), p1)
mod = tvm.IRModule.from_expr(func)

target = "llvm"
lib = relay.build(
mod,
tvm.target.Target(target, host=target),
runtime=relay.backend.Runtime("cpp"),
executor=relay.backend.Executor("aot", {"unpacked-api": False, "interface-api": "packed"}),
)


@tvm.testing.uses_gpu
@pytest.mark.parametrize("dtype", ["float32", "float16"])
def test_lrn(executor_kind, dtype):
Expand Down