Commit e370fc7
authored
[Relax][ONNX] Normalize negative indices before the take call for
Hi Committers,
This PR is trying to fix issues
#19436. Any suggestions would be
appreciated if you are available.
### Root Cause
1. ONNX `Gather` allows negative indices (counting from the end of the
target axis).
2. In the Relax ONNX importer, `Gather` was lowered directly to
`relax.op.take` without normalizing negative indices first.
3. This created semantic mismatch / incorrect behavior in downstream
lowering paths that assume non-negative indices.
4. Test failures were also caused by pytest parametrization issues:
- using ONNX `TensorProto` enum values directly as NumPy dtypes,
- and tuple-style parametrization triggering fixture interpretation
errors.
### Solutions
1. Added conditional negative-index normalization in `Gather._impl_v13`:
- apply only for signed index dtypes,
- use: `idx < 0 ? idx + axis_extent : idx`,
- derive `axis_extent` from shape/runtime expression to support dynamic
shapes.
2. Skipped normalization for unsigned index dtypes to avoid redundant
graph ops/checks.
---------
Co-authored-by: cchung100m <cchung100m@users.noreply.github.com>Gather operator (#19525)1 parent 6b27d19 commit e370fc7
2 files changed
Lines changed: 81 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1106 | 1106 | | |
1107 | 1107 | | |
1108 | 1108 | | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
1109 | 1128 | | |
1110 | 1129 | | |
1111 | 1130 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
874 | 874 | | |
875 | 875 | | |
876 | 876 | | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
877 | 939 | | |
878 | 940 | | |
879 | 941 | | |
| |||
0 commit comments