ITADN

cpu backend: 18 backend tests fail, all backward passes with wrong gradient values

#5296Open4ktLuffy 创建于 14 天前
bug
4
4ktLuffycommented
### Describe the bug The `cpu` backend fails 18 of the shared backend tests, and every failure is a backward pass producing wrong gradient values — not a missing implementation. ``` cargo test -p burn-backend-tests --no-default-features --features cpu --features std ``` ``` test result: FAILED. 504 passed; 18 failed; 6 ignored ``` The 18 are 9 distinct tests, each failing in both the `base` and `checkpointing` variants: ``` avgpool1d::test_avg_pool1d_complex avgpool1d::test_avg_pool1d_complex_dont_count_pad gather_scatter::test_gather_grad gather_scatter::test_scatter_grad gradients::should_update_tensor_when_grad_replace mask_select::test_mask_select_grad_empty_mask select::test_select_add_grad select::test_select_grad unfold::unfold_backward_accumulates_overlaps ``` The values are wrong rather than absent, e.g. `test_gather_grad`: ``` Tensors are not eq: => Position 0: 88 != 94 => Position 1: 156 != 150 => Position 2: 181 != 187 => Position 3: 223 != 242 => Position 4: 324 != 305 ``` ### An observation about the set Every failing test is a backward pass whose gradient is formed by **accumulating into overlapping positions** — gather/scatter, `select` and `select_add`, `unfold` (the test is literally named `unfold_backward_accumulates_overlaps`), and average-pooling backward, which spreads a gradient across overlapping windows. Note the numbers above are close to correct but redistributed, which is what a mis-accumulation looks like rather than a wrong formula. I have not confirmed a single root cause, so I am reporting the pattern rather than asserting one. Two of the nine are known separately and are not part of it: - `should_update_tensor_when_grad_replace` is the assertion in #5294. - `mask_select::test_mask_select_grad_empty_mask` is the empty-tensor case in #5293. That leaves seven that look like the same family. ### This backend is not in the CI matrix `xtask`'s backend list covers Ndarray, Flex, Metal, Cuda, Vulkan and Wgpu; `cpu` does not appear, and `burn-cpu` is in `EXCLUDE_CRATES` for unit tests. So these failures are not visible to CI, which is presumably why they have accumulated. ### Question before anyone spends time on it `burn-cpu` is published, but the README says "Example coming soon" and the crate has been quiet since May. **Is the `cpu` backend expected to pass the shared backend tests at this point?** If it is, I am happy to dig into the scatter-accumulation family and open a PR. If it is a work in progress and the failures are known, this issue is at least a record of exactly which tests are affected, and it costs nothing to close. ### Environment - burn `main` at `318b8f9a`, `rustc 1.97.1` - Apple M-series, debug profile. I have not yet checked whether the same failures appear under `--release`.
6 条评论