Commit fcd917c
Add step support to tensor
* Add step support to tensor slice operations
Extends tensor slicing to support custom step values, including negative steps for reversed slices, via a new SliceInfo struct. Updates all relevant backend, API, and macro code to use SliceInfo for slicing, and adapts documentation and trait signatures to reflect the new functionality. Backends that do not support steps panic if step != 1. This enables advanced slicing patterns such as strided and reversed selection.
* Add support for slicing tensors with step in tch backend
Refactored tensor slicing logic to handle arbitrary step values, including negative steps, in the tch backend. Updated bool, int, and float tensor ops to use the new slice_with_steps method, removing previous step=1 restriction and panic.
* Add support for slicing tensors with steps
Introduces the `slice_with_steps` function to enable slicing tensors with arbitrary step sizes, including negative steps, in `base.rs`. Updates `bool_tensor.rs`, `int_tensor.rs`, and `tensor.rs` to use the new slicing logic via `SliceInfo`, allowing more flexible and efficient tensor slicing operations.
* Fix formatting
* Add step slicing support in burn-cubecl
* Fix format
* Refactor tensor slicing to use SliceInfo
Replaces usage of std::ops::Range with burn_tensor::SliceInfo for tensor slicing operations in qtensor and ring modules. This change improves consistency and prepares for more flexible slicing semantics across backends.
* Fix format
* Fix formatting
* Refactor tensor slice ops to use SliceInfo
Updated bool, float, int, and quantized tensor slice operations to accept and process SliceInfo instead of Range<usize>. This change enables support for slicing with steps and improves consistency across tensor types.
* Refactor slice kernels to use LinearView
Updated slice and slice_with_steps kernels to operate on LinearView types instead of raw Tensor references. This change improves memory access safety and consistency, and updates kernel launch calls to pass linear views for both input and output tensors.
* Refactor tensor slice output shape calculation
Centralizes and simplifies output shape calculation for tensor slicing with steps by introducing `calculate_slice_output_shape` in burn-tensor. Updates all relevant tensor ops to use this utility, improving code maintainability and consistency. Adds comprehensive unit tests for the new function.
* Fix no-std
* Add support for non-unit steps in ONNX Slice op
This commit adds support for arbitrary step values (including negative steps) in the ONNX Slice operator, updating the parser, code generation, and tests. It introduces new test cases and models for slicing with steps, removes previous restrictions on steps, and ensures correct handling of steps in both tensor and shape slicing scenarios.
* Fix lint warning
* Refactor cubecl slice kernel
* Fix no-std
* Refactor tensor slice validation to use SliceInfo
* Refactor slice_dim to use SliceInfo parameter
Updated the slice_dim function to accept a SliceInfo parameter instead of a Range, allowing for more flexible slicing with custom step values. Adjusted documentation and internal usage to reflect this change.
* Enforce unit step in slice_assign and slice_fill ops
Updated tensor slicing APIs to require step=1 for slice_assign and slice_fill, panicking if non-unit steps are provided. Refactored internal usage to pass SliceInfo instead of Range, updated related ops (cat, repeat_dim), and added tests to verify panics on unsupported stepped slicing.
* Add ignored test for matmul with stepped slice
Introduces a new test 'should_diff_matmul_with_slice_stepped' to verify autodiff behavior when using stepped slices in matmul operations. The test is currently ignored due to lack of support for slice assignment with steps.
* Refactor tensor slicing to use Slice instead of SliceInfo
Replaces usage of SliceInfo with the new Slice type across all tensor slicing APIs, implementations, and internal logic. Updates function signatures, backend implementations, and related code to support the new Slice structure, improving consistency and flexibility for tensor slicing operations.
* Add panic for unsupported slice step in Autodiff
Added a check in float_slice to panic if any slice step is not 1, as Autodiff does not support slicing with step != 1. Also added a test to verify that slicing with a step triggers the expected panic.
* Refactor slice range checks and update tests
Improved slice range validation in TensorCheck by checking the raw end index before conversion, providing clearer error messages. Updated related tests to use the Slice API directly and replaced Slice::new with Slice::from_range_stepped for consistency.
* Rename slice_infos to slices in tensor APIs
Updated documentation and variable names from 'slice_infos' to 'slices' across tensor API traits and convolution module implementations for consistency and clarity. No functional changes were made.
* Update tensor slicing docs to use 'slices' terminology
* Refactor tensor slicing to use Slice::from with ranges
Replaces multiple usages of Slice::new with Slice::from and Rust range syntax for tensor slicing in convolution weight gradient functions. This improves code readability and leverages more idiomatic Rust constructs.
---------
Co-authored-by: Genna Wingert <[email protected]>slice operations (tracel-ai#3748)1 parent 8e0474c commit fcd917c
File tree
59 files changed
+1929
-446
lines changed- burn-book/src/building-blocks
- crates
- burn-autodiff/src
- ops
- tests
- burn-candle/src/ops
- burn-collective/src
- global/node
- local/all_reduce
- burn-cubecl/src
- kernel/index
- ops
- burn-fusion/src
- ops
- stream
- burn-import
- onnx-tests
- tests/slice
- src
- burn/node
- onnx
- burn-ir/src
- burn-ndarray/src/ops
- burn-router/src/ops
- burn-tch/src/ops
- burn-tensor/src
- tensor
- api
- ops
- modules
- tests/ops
- onnx-ir/src/node
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
59 files changed
+1929
-446
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
166 | 166 | | |
167 | 167 | | |
168 | 168 | | |
169 | | - | |
| 169 | + | |
170 | 170 | | |
171 | 171 | | |
172 | 172 | | |
| |||
181 | 181 | | |
182 | 182 | | |
183 | 183 | | |
184 | | - | |
185 | 184 | | |
186 | 185 | | |
187 | 186 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
36 | | - | |
| 35 | + | |
| 36 | + | |
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
32 | | - | |
| 31 | + | |
| 32 | + | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | 1 | | |
4 | 2 | | |
5 | 3 | | |
| |||
84 | 82 | | |
85 | 83 | | |
86 | 84 | | |
87 | | - | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
88 | 89 | | |
89 | 90 | | |
90 | 91 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1130 | 1130 | | |
1131 | 1131 | | |
1132 | 1132 | | |
1133 | | - | |
1134 | | - | |
1135 | | - | |
1136 | | - | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
1137 | 1144 | | |
1138 | 1145 | | |
1139 | 1146 | | |
1140 | 1147 | | |
1141 | 1148 | | |
1142 | 1149 | | |
1143 | | - | |
| 1150 | + | |
1144 | 1151 | | |
1145 | 1152 | | |
1146 | 1153 | | |
1147 | 1154 | | |
1148 | 1155 | | |
1149 | 1156 | | |
1150 | | - | |
| 1157 | + | |
1151 | 1158 | | |
1152 | 1159 | | |
1153 | 1160 | | |
| |||
1170 | 1177 | | |
1171 | 1178 | | |
1172 | 1179 | | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
1173 | 1188 | | |
1174 | 1189 | | |
1175 | 1190 | | |
1176 | | - | |
| 1191 | + | |
1177 | 1192 | | |
1178 | 1193 | | |
1179 | 1194 | | |
1180 | 1195 | | |
1181 | 1196 | | |
1182 | | - | |
| 1197 | + | |
1183 | 1198 | | |
1184 | 1199 | | |
1185 | 1200 | | |
1186 | | - | |
| 1201 | + | |
1187 | 1202 | | |
1188 | | - | |
| 1203 | + | |
1189 | 1204 | | |
1190 | 1205 | | |
1191 | 1206 | | |
| |||
1234 | 1249 | | |
1235 | 1250 | | |
1236 | 1251 | | |
1237 | | - | |
| 1252 | + | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
| 1258 | + | |
| 1259 | + | |
| 1260 | + | |
| 1261 | + | |
1238 | 1262 | | |
1239 | 1263 | | |
1240 | 1264 | | |
| |||
2122 | 2146 | | |
2123 | 2147 | | |
2124 | 2148 | | |
2125 | | - | |
| 2149 | + | |
| 2150 | + | |
| 2151 | + | |
| 2152 | + | |
| 2153 | + | |
| 2154 | + | |
| 2155 | + | |
2126 | 2156 | | |
2127 | 2157 | | |
2128 | 2158 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
130 | 130 | | |
131 | 131 | | |
132 | 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 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
133 | 175 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 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 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
108 | 168 | | |
109 | 169 | | |
110 | 170 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
60 | | - | |
61 | | - | |
| 60 | + | |
| 61 | + | |
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
45 | | - | |
| 44 | + | |
| 45 | + | |
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | 1 | | |
4 | 2 | | |
5 | 3 | | |
| |||
80 | 78 | | |
81 | 79 | | |
82 | 80 | | |
83 | | - | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
84 | 85 | | |
85 | 86 | | |
86 | 87 | | |
| |||
0 commit comments