Commit df44eab
authored
Introduce checks to prevent buffer overflow, add tests (#28713)
This pull request improves the correctness and robustness of the
`InPlaceAccumulator` and `InPlaceAccumulatorV2` gradient accumulation
kernels by adding new unit tests and enforcing stricter shape validation
in both CPU and CUDA implementations. The changes ensure that shape
mismatches are caught early, and that optional outputs are properly
handled in all execution providers.
**Test coverage improvements:**
* Added a test to verify that `InPlaceAccumulator` correctly passes
through the `old_sum` unchanged and does not consume the `value` input
when the optional `update_signal` is `false`.
* Added tests for `InPlaceAccumulatorV2` to check that shape mismatches
between `accumulation_buffer` and `value` are detected and handled as
errors, covering both overwrite and accumulate branches.
* Added tests to verify that `InPlaceAccumulatorV2` correctly handles
the case where the optional `accumulation_buffer_out` output is omitted,
for both CPU and CUDA providers.
[[1]](diffhunk://#diff-c62fec6d9ac7d24c7d6befe4e18317d2690385051c01a6412651f01e190de1beR2247-R2288)
[[2]](diffhunk://#diff-c62fec6d9ac7d24c7d6befe4e18317d2690385051c01a6412651f01e190de1beR2332-R2346)
**Kernel validation improvements:**
* Added explicit shape validation to the CPU implementation of
`InPlaceAccumulatorV2`, ensuring that the shapes of the accumulation
buffer and the value tensor match.
* Added the same shape validation to the CUDA implementation of
`InPlaceAccumulatorV2`, preventing out-of-bounds memory accesses.1 parent d165fba commit df44eab
3 files changed
Lines changed: 90 additions & 0 deletions
File tree
- orttraining/orttraining
- test/gradient
- training_ops
- cpu/optimizer
- cuda/optimizer
Lines changed: 82 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2175 | 2175 | | |
2176 | 2176 | | |
2177 | 2177 | | |
| 2178 | + | |
| 2179 | + | |
| 2180 | + | |
| 2181 | + | |
| 2182 | + | |
| 2183 | + | |
| 2184 | + | |
| 2185 | + | |
| 2186 | + | |
| 2187 | + | |
| 2188 | + | |
| 2189 | + | |
| 2190 | + | |
| 2191 | + | |
2178 | 2192 | | |
2179 | 2193 | | |
2180 | 2194 | | |
| |||
2230 | 2244 | | |
2231 | 2245 | | |
2232 | 2246 | | |
| 2247 | + | |
| 2248 | + | |
| 2249 | + | |
| 2250 | + | |
| 2251 | + | |
| 2252 | + | |
| 2253 | + | |
| 2254 | + | |
| 2255 | + | |
| 2256 | + | |
| 2257 | + | |
| 2258 | + | |
| 2259 | + | |
| 2260 | + | |
| 2261 | + | |
| 2262 | + | |
| 2263 | + | |
| 2264 | + | |
| 2265 | + | |
| 2266 | + | |
| 2267 | + | |
| 2268 | + | |
| 2269 | + | |
| 2270 | + | |
| 2271 | + | |
| 2272 | + | |
| 2273 | + | |
| 2274 | + | |
| 2275 | + | |
| 2276 | + | |
| 2277 | + | |
| 2278 | + | |
| 2279 | + | |
| 2280 | + | |
| 2281 | + | |
| 2282 | + | |
| 2283 | + | |
| 2284 | + | |
| 2285 | + | |
| 2286 | + | |
| 2287 | + | |
| 2288 | + | |
| 2289 | + | |
| 2290 | + | |
| 2291 | + | |
| 2292 | + | |
| 2293 | + | |
| 2294 | + | |
| 2295 | + | |
| 2296 | + | |
| 2297 | + | |
| 2298 | + | |
| 2299 | + | |
2233 | 2300 | | |
2234 | 2301 | | |
2235 | 2302 | | |
| |||
2273 | 2340 | | |
2274 | 2341 | | |
2275 | 2342 | | |
| 2343 | + | |
| 2344 | + | |
| 2345 | + | |
| 2346 | + | |
| 2347 | + | |
| 2348 | + | |
| 2349 | + | |
| 2350 | + | |
| 2351 | + | |
| 2352 | + | |
| 2353 | + | |
| 2354 | + | |
| 2355 | + | |
| 2356 | + | |
| 2357 | + | |
2276 | 2358 | | |
2277 | 2359 | | |
2278 | 2360 | | |
| |||
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
98 | 102 | | |
99 | 103 | | |
100 | 104 | | |
| |||
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
122 | 126 | | |
123 | 127 | | |
124 | 128 | | |
| |||
0 commit comments