Files
apache--tvm/python
Javier De Jesus 1720d305ae [Relax][ONNX] Fix TopK scalar K extraction in from_onnx (#19573)
### Root Cause

`TopK._impl_v11` extracted `k` with `int(k.data.numpy())`. ONNX emits
`K` as a single-element 1-D tensor constant, so `numpy()` returns a 1-D
array and `int()` raises `TypeError: only 0-dimensional arrays can be
converted to Python scalars`, failing conversion of any model with a
`TopK` node.

### Solution

Resolve `k` with `get_constant(inputs[1], params)` and extract the
scalar with `.item()`, matching the `Trilu` and `Reshape` converters in
the same file. `get_constant` also handles `k` arriving as a parameter
when `keep_params_in_input=True`.

### Test Plan

`test_topk` in `tests/python/relax/test_frontend_onnx.py` already builds
`K` as a single-element 1-D INT64 constant, so it exercises this path.
`.item()` returns the scalar for both single-element 1-D and 0-d
constants.

### Issue

Fixes #19571
2026-05-19 09:02:59 -07:00
..