Commit d3a02fb
authored
[ONNX] Fix initializer prefix stripping (#20323)
The Relax ONNX importer used `str.strip("onnx::")` when
`keep_params_in_input=True`. Since `strip` treats its argument as a set
of characters, initializer names that do not have the prefix can still
lose leading or trailing `o`, `n`, `x`, or `:` characters. For example,
`neck...` became `eck...`.
This change uses `str.removeprefix("onnx::")` so only the exact
PyTorch-generated prefix is removed. The regression test covers both a
prefixed initializer and an ordinary initializer beginning with `n`.
Fixes #20290
Tests:
- `python -m pytest tests/python/relax/test_frontend_onnx.py -k
'params_names_start_with_onnx or
initializer_name_only_removes_onnx_prefix or concat_with_param or
multi_ops_with_same_params' -q`
- `python -m ruff check python/tvm/relax/frontend/onnx/onnx_frontend.py
tests/python/relax/test_frontend_onnx.py`
- `python -m ruff format --check
python/tvm/relax/frontend/onnx/onnx_frontend.py
tests/python/relax/test_frontend_onnx.py`
Local full-file note: the complete ONNX test file reached 28 passing
tests before hitting the unrelated Windows JIT export assertion `Target
triple should not be empty`.1 parent d01d441 commit d3a02fb
2 files changed
Lines changed: 31 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6354 | 6354 | | |
6355 | 6355 | | |
6356 | 6356 | | |
6357 | | - | |
| 6357 | + | |
6358 | 6358 | | |
6359 | 6359 | | |
6360 | 6360 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11797 | 11797 | | |
11798 | 11798 | | |
11799 | 11799 | | |
| 11800 | + | |
| 11801 | + | |
| 11802 | + | |
| 11803 | + | |
| 11804 | + | |
| 11805 | + | |
| 11806 | + | |
| 11807 | + | |
| 11808 | + | |
| 11809 | + | |
| 11810 | + | |
| 11811 | + | |
| 11812 | + | |
| 11813 | + | |
| 11814 | + | |
| 11815 | + | |
| 11816 | + | |
| 11817 | + | |
| 11818 | + | |
| 11819 | + | |
| 11820 | + | |
| 11821 | + | |
| 11822 | + | |
| 11823 | + | |
| 11824 | + | |
| 11825 | + | |
| 11826 | + | |
| 11827 | + | |
| 11828 | + | |
| 11829 | + | |
11800 | 11830 | | |
11801 | 11831 | | |
11802 | 11832 | | |
| |||
0 commit comments