Fix more cases for 0 sized tensors.#4878
Conversation
Codecov Report❌ Patch coverage is
❌ Your patch check has failed because the patch coverage (0.00%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #4878 +/- ##
==========================================
- Coverage 65.62% 65.62% -0.01%
==========================================
Files 1161 1161
Lines 170422 170432 +10
==========================================
Hits 111839 111839
- Misses 58583 58593 +10 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Instead of being backend-specific logic in cubecl, we could add the early return check in the high-level API? The contract should be the same for all.
We should probably add more tests to cover 0 sized tensor operations.
/edit: going over pending PRs, I just realized this shouldn't trigger for slice_assign in any case as it currently stands. If the value tensor is empty, the slice range should be empty, and it's a no-op:
burn/crates/burn-tensor/src/tensor/api/base.rs
Lines 1447 to 1456 in bf2e8b7
If the slice range is not empty but the value tensor is, it would panic with a tensor operation error due to the mismatch.
But other kernels like select and select_assign don't have this check for 0 sized tensors which should be handled.
|
This PR has been marked as stale because it has not been updated for over a month |
shape == 0, the subtraction underflows and panics under overflow checks (e.g. debug builds, wasm tests).
On native this is hidden because ChannelDeviceHandle swallows worker-thread panics with catch_unwind. on wasm ReentrantMutexDeviceHandle propagates the panic and additionally poisons the device handle (the service cell stays None after the panic skips its replace), turning every later test into "State ... is already borrowed by the current thread". Fix: an empty tensor has no elements that can overlap, so return true early when any dim is zero.
For slice assign, the kernel does no useful work when
valuehas 0 elements anyway, so just early-return. After tracel-ai/cubecl#1297 this wouldn't panic anymore anyway, but, might as well skip the work here entirely.