Skip to content

Commit cf858be

Browse files
committed
finish21
1 parent f6a0cab commit cf858be

File tree

3 files changed

+8
-18
lines changed

3 files changed

+8
-18
lines changed

python/tvm/topi/vision/nms.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ def _nms_loop(
8888
def nms_inner_loop(ib, i, j, nkeep, num_valid_boxes_local):
8989
on_new_valid_box_func(ib, 0, num_valid_boxes_local[0], i, j)
9090
num_valid_boxes_local[0] += 1
91-
9291

9392
num_boxes_to_check = nkeep - (j + 1)
9493

@@ -112,7 +111,6 @@ def nms_inner_loop(ib, i, j, nkeep, num_valid_boxes_local):
112111
nkeep = if_then_else(tvm.tir.all(top_k > 0, top_k < valid_count[i]), top_k, valid_count[i])
113112
# Use max_output_size directly without if_then_else
114113
# max_output_size = if_then_else(max_output_size > te.const(0), max_output_size, nkeep)
115-
116114

117115
with ib.if_scope(tvm.tir.all(iou_threshold > te.const(0), valid_count[i] > te.const(0))):
118116
num_valid_boxes_local = ib.allocate(

python/tvm/topi/vision/nms_util.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,6 @@ def _all_class_nms_ir(
319319
max_output_size_per_class = max_output_size_per_class[0]
320320
else:
321321
max_output_size_per_class = tvm.tir.const(1000)
322-
323322

324323
def calc_overlap(i, j, k):
325324
offset_j = sorted_indices[i, j] * 4

tests/python/relax/test_frontend_onnx.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3199,54 +3199,47 @@ def test_nms():
31993199

32003200
model = helper.make_model(graph, producer_name="nms_test")
32013201
model.opset_import[0].version = 11
3202-
3202+
32033203
# Use deterministic random inputs for consistent testing
32043204
bg = np.random.MT19937(0)
32053205
rg = np.random.Generator(bg)
32063206
boxes = rg.standard_normal(size=boxes_shape).astype(np.float32)
32073207
scores = rg.standard_normal(size=scores_shape).astype(np.float32)
32083208
inputs = {"boxes": boxes, "scores": scores}
3209-
3209+
32103210
# Run ONNX Runtime
32113211
ort_session = onnxruntime.InferenceSession(
32123212
model.SerializeToString(), providers=["CPUExecutionProvider"]
32133213
)
32143214
ort_output = ort_session.run([], inputs)
3215-
3215+
32163216
# Run TVM
32173217
tvm_model = from_onnx(model, opset=11, keep_params_in_input=True)
32183218
tvm_model = relax.transform.DecomposeOpsForInference()(tvm_model)
32193219
tvm_model = relax.transform.LegalizeOps()(tvm_model)
32203220
tvm_model, params = relax.frontend.detach_params(tvm_model)
3221-
3221+
32223222
with tvm.transform.PassContext(opt_level=3):
32233223
ex = tvm.compile(tvm_model, target="llvm")
32243224
vm = relax.VirtualMachine(ex, tvm.cpu())
3225-
3225+
32263226
input_list = [
32273227
inputs[key.name_hint] for key in tvm_model["main"].params if key.name_hint in inputs
32283228
]
32293229
if params:
32303230
input_list += params["main"]
3231-
3231+
32323232
vm.set_input("main", *input_list)
32333233
vm.invoke_stateful("main")
32343234
tvm_output = vm.get_outputs("main")
3235-
3236-
# Custom NMS output comparison
3237-
# TVM outputs fixed shape (6,3), ONNX Runtime outputs dynamic shape (varies)
3238-
# We only compare the valid rows based on the actual output count
3235+
32393236
if isinstance(tvm_output, (list, tuple)):
32403237
tvm_selected = tvm_output[0].numpy()
32413238
else:
32423239
tvm_selected = tvm_output.numpy()
32433240
ort_selected = ort_output[0]
3244-
3245-
# For NMS, compare only the number of valid rows
3246-
# TVM may output more rows with garbage data, but the first N rows should match
3241+
32473242
min_rows = min(tvm_selected.shape[0], ort_selected.shape[0])
3248-
3249-
# Compare the first min_rows rows
32503243
if min_rows > 0:
32513244
tvm.testing.assert_allclose(
32523245
tvm_selected[:min_rows], ort_selected[:min_rows], rtol=1e-5, atol=1e-5

0 commit comments

Comments
 (0)