[BUG] out_idx accepts out-of-range indices in scalar and profiler list forms
- Dominant language
- Python
- Stars
- 7.4k
- Forks
- 745
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 104
Description
### Required prerequisites
- [x] I have searched the issue tracker for an existing report.
### TileLang version
`0.1.13+cuda`, reproduced on `1d155f4b80865edfe0009ad952135b7afbd4f05a`.
### System information
- Installed from source
- Python 3.12.13
- Linux x86-64
### Problem description
Output parameter indices should follow Python indexing bounds:
```text
-len(params) <= index < len(params)
```
The adapter and profiler currently enforce this inconsistently. With three parameters:
- Both scalar paths accept `3`, although it is past the final parameter.
- The adapter rejects list `[3]`, but the profiler accepts it.
- The profiler accepts list `[-4]`.
- The profiler leaves valid negative list indices such as `[-1]` unnormalized.
- The adapter error advertises `-4` as valid even though it rejects it.
- Non-integer list elements can pass through or raise an incidental `TypeError`.
An invalid scalar index can therefore fail later during adapter wrapping, while invalid or unnormalized profiler indices can cause parameters to be classified incorrectly.
### Reproducible example code
```python
from tilelang.jit.adapter import BaseKernelAdapter
from tilelang.profiler import Profiler
from tilelang.utils.tensor import TensorSupplyType
class TestAdapter(BaseKernelAdapter):
def _convert_torch_func(self):
return lambda: None
params = [object(), object(), object()]
cases = [
("adapter scalar upper", lambda: TestAdapter(None, params, 3).result_idx),
("adapter list upper", lambda: TestAdapter(None, params, [3]).result_idx),
("profiler scalar upper", lambda: Profiler(params, 3, TensorSupplyType.Integer).result_idx),
("profiler list upper", lambda: Profiler(params, [3], TensorSupplyType.Integer).result_idx),
("profiler list lower", lambda: Profiler(params, [-4], TensorSupplyType.Integer).result_idx),
("profiler valid negative", lambda: Profiler(params, [-1], TensorSupplyType.Integer).result_idx),
]
for name, case in cases:
try:
print(name, "->", case())
except Exception as exc:
print(name, "->", type(exc).__name__, exc)
```
Observed behavior includes:
```text
adapter scalar upper -> [3]
adapter list upper -> ValueError ...
profiler scalar upper -> [3]
profiler list upper -> [3]
profiler list lower -> [-4]
profiler valid negative -> [-1]
```
### Expected behavior
For three parameters:
- `-3`, `-1`, `0`, and `2` are accepted.
- Negative values are normalized to positive parameter indices.
- `-4` and `3` raise `ValueError` for scalar and list forms.
- Every list element is required to be an integer.
- Adapter and profiler behavior and error bounds are consistent.
Contributor guide
Research direction
Start in tilelang/jit/adapter.py at BaseKernelAdapter and tilelang/profiler.py at Profiler, then trace how scalar and list result_idx values are validated and normalized. Reproduce the six cases in the issue; done means both paths consistently accept valid Python indices, normalize negatives, reject out-of-range values, and require integer list elements.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 72/100