()
| 2188 | |
| 2189 | |
| 2190 | def test_split_infer_struct_info(): |
| 2191 | bb = relax.BlockBuilder() |
| 2192 | n = tirx.Var("n", "int64") |
| 2193 | x = relax.Var("x", R.Tensor((16, 4))) |
| 2194 | y = relax.Var("y", R.Tensor((16, 4), "float32")) |
| 2195 | z = relax.Var("z", R.Tensor((n, 16))) |
| 2196 | w = relax.Var("w", R.Tensor((n + 5, 16))) |
| 2197 | |
| 2198 | # All relax shape variables are non-negative. When a scope |
| 2199 | # begins, any TIR variables that are used as shape variables are |
| 2200 | # declared to be non-negative `tvm.arith.Analyzer`. Because |
| 2201 | # `relax.op.split` clamps the indices to be within the bounds of |
| 2202 | # the axis being split, simplifying with non-negative shape |
| 2203 | # variables can result in much simpler shapes. |
| 2204 | # |
| 2205 | # For example, an axis of size `n`, split on the range from 2 to 5 |
| 2206 | # has size `T.max(T.min(5, n + 5) - T.min(2, n + 5), 0)`. If it |
| 2207 | # is known that `n >= 0`, then this simplifies down to `3`. |
| 2208 | bb.begin_scope([x, y, z, w]) |
| 2209 | |
| 2210 | _check_inference( |
| 2211 | bb, |
| 2212 | relax.op.split(x, 1), |
| 2213 | R.Tensor([16, 4]), |
| 2214 | ) |
| 2215 | _check_inference( |
| 2216 | bb, |
| 2217 | relax.op.split(x, 2), |
| 2218 | R.Tuple( |
| 2219 | R.Tensor([8, 4]), |
| 2220 | R.Tensor([8, 4]), |
| 2221 | ), |
| 2222 | ) |
| 2223 | # Uneven splits are allowed, with the last split being smaller than the others. |
| 2224 | _check_inference( |
| 2225 | bb, |
| 2226 | relax.op.split(x, 3), |
| 2227 | R.Tuple( |
| 2228 | R.Tensor([6, 4]), |
| 2229 | R.Tensor([6, 4]), |
| 2230 | R.Tensor([4, 4]), |
| 2231 | ), |
| 2232 | ) |
| 2233 | |
| 2234 | # Dtype of result is inherited from the tensor |
| 2235 | _check_inference( |
| 2236 | bb, |
| 2237 | relax.op.split(y, 2), |
| 2238 | R.Tuple( |
| 2239 | R.Tensor([8, 4], "float32"), |
| 2240 | R.Tensor([8, 4], "float32"), |
| 2241 | ), |
| 2242 | ) |
| 2243 | |
| 2244 | # Axis can be explicitly specified. Otherwise, defaults to axis=0. |
| 2245 | _check_inference( |
| 2246 | bb, relax.op.split(x, [2], axis=1), R.Tuple(R.Tensor([16, 2]), R.Tensor([16, 2])) |
| 2247 | ) |
nothing calls this directly
no test coverage detected
searching dependent graphs…