Skip to content
Open
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
3 changes: 2 additions & 1 deletion python/tvm/relax/backend/dispatch_sort_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ def visit_call_(self, call: relax.Call) -> relax.Expr:
with tgt:
if self.is_gpu_target(tgt):
te_func = topi.gpu.searchsorted
out_dtype = "int32" if call.attrs.out_int32 else "int64"
return self.builder_.call_te(
te_func, boundaries, input_tensor, right, input_tensor.ty.dtype.dtype
te_func, boundaries, input_tensor, right, out_dtype
)
if call.op.name == "relax.sort":
tgt = self._get_target(call.ty)
Expand Down
3 changes: 2 additions & 1 deletion python/tvm/relax/transform/legalize_ops/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ def _bucketize(bb, call):
input_tensor = call.args[0]
boundaries = call.args[1]
right = call.attrs.right
return bb.call_te(topi.searchsorted, boundaries, input_tensor, right, input_tensor.ty.dtype)
out_dtype = "int32" if call.attrs.out_int32 else "int64"
return bb.call_te(topi.searchsorted, boundaries, input_tensor, right, out_dtype)
13 changes: 13 additions & 0 deletions tests/python/relax/test_frontend_from_exported_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -7829,6 +7829,19 @@ def main(
verify_model(Bucketize(), (input_tensor, boundaries), {}, Expected)


@pytest.mark.parametrize("right", [False, True])
@pytest.mark.parametrize("out_int32", [False, True])
def test_bucketize_numerically(right, out_int32):
class Bucketize(Module):
def forward(self, input_tensor, boundaries):
return torch.bucketize(input_tensor, boundaries, right=right, out_int32=out_int32)

input_tensor = torch.tensor([-0.5, 0.0, 0.5, 1.0, 2.0, 2.5], dtype=torch.float32)
boundaries = torch.tensor([0.0, 1.0, 2.0], dtype=torch.float32)

verify_model_numerically(Bucketize(), (input_tensor, boundaries))


def test_argsort():
class Argsort(Module):
def forward(self, x):
Expand Down