Commit 4870d45
Add int8 support to ConvInteger (#26585)
### Description
<!-- Describe your changes. -->
This change extends the `ConvInteger` implementation to match the [ONNX
operator spec](https://onnx.ai/onnx/operators/onnx__ConvInteger.html),
which allows both `int8` and `uint8` for the input tensors:
- The ONNX `ConvInteger` schema defines:
- `T1`: `tensor(int8)` or `tensor(uint8)`
- `T2`: `tensor(int8)` or `tensor(uint8)`
- `T3`: `tensor(int32)`
- Previously, only the `uint8` × `uint8` combination was supported.
- This PR adds support for all 8-bit combinations:
- `uint8` × `uint8` (existing behavior)
- `uint8` × `int8`
- `int8` × `uint8`
- `int8` × `int8`
### Motivation and Context
<!-- - Why is this change required? What problem does it solve?
- If it fixes an open issue, please link to the issue here. -->
Fixes #24183
Fixes #15888
Fixes #12558
Fixes #3130
Fixes #12362
The ONNX ConvInteger operator schema allows both int8 and uint8 element
types for its inputs, but the current implementation only supports uint8
× uint8. This leads to a gap where valid ONNX models using ConvInteger
with int8 tensors cannot be executed.
This PR closes that gap by:
Aligning the implementation with the official ConvInteger type
constraints.
Enabling models that use int8 (or mixed int8/uint8) for X and W to run
without needing operator rewrites or additional custom kernels.
Keeping existing uint8 behavior unchanged, so the change is backwards
compatible for current users.
### Implementation details
1. Templated core implementation (ComputeInner)
The core logic of ConvInteger::Compute is moved into a templated helper:
```text
class ConvInteger : public OpKernel {
public:
...
private:
template <typename XT, typename WT>
Status ComputeInner(OpKernelContext* context) const
};
```
XT is the element type of X (uint8_t or int8_t).
WT is the element type of W (uint8_t or int8_t).
2. Zero-point handling
Zero points are still treated as per-tensor scalar values, with the same
validation,
The values are read via `DataRaw()` and stored as 8-bit scalars,
preserving the previous behavior.
Interpretation of these raw bytes as signed or unsigned is delegated to
the GEMM implementation via explicit signedness flags (see below).
3. Im2col templated on XT
The Im2col call now uses the runtime input type XT.
4. Quantized GEMM with signedness flags:
```text
gemm_shape.AIsSigned = W->IsDataType<int8_t>();
gemm_shape.BIsSigned = X->IsDataType<int8_t>();
```
AIsSigned and BIsSigned are derived from the runtime types of W and X.
Data for A and B is passed as raw bytes, the GEMM implementation uses
the signedness flags to interpret them correctly (In a manner similar to
the implementation in `MatMulInteger`).
5. Runtime dispatch in Compute()
The public Compute method becomes a thin dispatcher that selects the
appropriate ComputeInner<XT, WT> instantiation based on the actual input
types.
In addition, a small set of unit tests is added on top of the existing
ConvInteger tests to cover the new type combinations, including cases
where the first input tensor contains negative values (for the int8 ×
int8 path).
---------
Co-authored-by: Copilot <[email protected]>1 parent 977efe4 commit 4870d45
File tree
4 files changed
+669
-38
lines changed- docs
- onnxruntime
- core
- providers/cpu/quantization
- util
- test/providers/cpu/nn
4 files changed
+669
-38
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
91 | | - | |
| 91 | + | |
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
| |||
Lines changed: 78 additions & 37 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
32 | | - | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
33 | 35 | | |
34 | 36 | | |
35 | 37 | | |
| |||
43 | 45 | | |
44 | 46 | | |
45 | 47 | | |
46 | | - | |
| 48 | + | |
47 | 49 | | |
48 | 50 | | |
49 | 51 | | |
50 | 52 | | |
51 | | - | |
| 53 | + | |
52 | 54 | | |
53 | 55 | | |
54 | 56 | | |
| |||
110 | 112 | | |
111 | 113 | | |
112 | 114 | | |
113 | | - | |
114 | | - | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
115 | 118 | | |
116 | 119 | | |
117 | 120 | | |
118 | 121 | | |
119 | 122 | | |
120 | 123 | | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
138 | 161 | | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
152 | 191 | | |
153 | 192 | | |
154 | 193 | | |
155 | 194 | | |
156 | 195 | | |
157 | 196 | | |
158 | 197 | | |
| 198 | + | |
| 199 | + | |
159 | 200 | | |
160 | 201 | | |
161 | 202 | | |
162 | 203 | | |
163 | 204 | | |
164 | | - | |
| 205 | + | |
165 | 206 | | |
166 | 207 | | |
167 | 208 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
527 | 527 | | |
528 | 528 | | |
529 | 529 | | |
| 530 | + | |
530 | 531 | | |
531 | 532 | | |
532 | 533 | | |
| |||
0 commit comments