You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Follow-up to #4761 which lands burn-flex as an additive CPU backend through burn-dispatch, burn umbrella, burn-backend-tests, xtask, and the release workflow. That PR intentionally kept scope to the migration itself. This issue tracks the cleanup work of flipping the remaining type TestBackend = burn_ndarray::NdArray<f32> references over to flex.
None of this blocks #4761. All of these are test-only code, and flex already runs the full burn-backend-tests conformance suite via cargo test-flex through dispatch.
Categorized landscape
Crate-level pub type TestBackend aliases (5 crates)
Feature-gated with a test-<backend> cascade. Today the cascade is not(feature = "test-tch"), not(feature = "test-wgpu"), not(feature = "test-cuda"), not(feature = "test-rocm") → burn_ndarray::NdArray. Adding test-flex is a one-line cfg branch plus the Cargo.toml feature:
crates/burn-core/src/lib.rs:42
crates/burn-nn/src/lib.rs:38
crates/burn-optim/src/lib.rs:38
Hardcoded, no cfg escape at all (would need the cascade added first):
crates/burn-train/src/lib.rs:36
crates/burn-rl/src/lib.rs:18
Per-file test submodules (8 files)
These declare their own type TestBackend = burn_ndarray::NdArray<f32> inside #[cfg(test)] mod tests rather than importing from the crate-level alias. Cleanest fix is to import from the crate alias once that supports flex:
A nice cleanup opportunity here: rather than edit 30 files, add a single type TestBackend = ... alias at the crate level and have the test modules import it.
Easiest wins first: add test-flex cfg branches to burn-core, burn-nn, burn-optim. Three one-line edits plus Cargo.toml features. Reuses the existing test-<backend> pattern.
Unblock the hardcoded ones: add the same cfg cascade to burn-train and burn-rl, which are hardcoded to ndarray today with no feature escape.
burn-store sweep: either add a crate-level alias and consolidate, or do a mechanical replace across the ~30 sites.
burn-collective sweep: 4 sites, mechanical.
Per-file test submodules: import from crate-level aliases instead of re-declaring.
Examples and docs: separate follow-up once flex becomes the recommended CPU backend in burn's public docs.
Notes
Flex runs 1598 conformance tests cleanly through dispatch (424 autodiff + 1174 tensor) with zero regressions in the ndarray path (1791 ndarray tests still pass). Swapping the test backend over should be functionally safe.
Watch for tests that rely on ndarray-specific TestBackend signatures like NdArray<f32, i32> in burn-vision. Flex exposes the same phantom-generic shape (Flex<E = f32, I = i32>) so Flex<f32, i32> is valid, but only the default instantiation implements Backend (Add burn-flex CPU backend (intended to replace burn-ndarray) #4761 ships a compile_fail doctest locking this in).
Context
Follow-up to #4761 which lands
burn-flexas an additive CPU backend throughburn-dispatch,burnumbrella,burn-backend-tests,xtask, and the release workflow. That PR intentionally kept scope to the migration itself. This issue tracks the cleanup work of flipping the remainingtype TestBackend = burn_ndarray::NdArray<f32>references over to flex.None of this blocks #4761. All of these are test-only code, and flex already runs the full
burn-backend-testsconformance suite viacargo test-flexthrough dispatch.Categorized landscape
Crate-level
pub type TestBackendaliases (5 crates)Feature-gated with a
test-<backend>cascade. Today the cascade isnot(feature = "test-tch"), not(feature = "test-wgpu"), not(feature = "test-cuda"), not(feature = "test-rocm")→burn_ndarray::NdArray. Addingtest-flexis a one-line cfg branch plus the Cargo.toml feature:crates/burn-core/src/lib.rs:42crates/burn-nn/src/lib.rs:38crates/burn-optim/src/lib.rs:38Hardcoded, no cfg escape at all (would need the cascade added first):
crates/burn-train/src/lib.rs:36crates/burn-rl/src/lib.rs:18Per-file test submodules (8 files)
These declare their own
type TestBackend = burn_ndarray::NdArray<f32>inside#[cfg(test)] mod testsrather than importing from the crate-level alias. Cleanest fix is to import from the crate alias once that supports flex:crates/burn-train/src/metric/vision/dists/metric.rs:361crates/burn-train/src/metric/vision/fid/metric.rs:197crates/burn-train/src/metric/vision/lpips/metric.rs:499crates/burn-nn/src/loss/ctc.rs:513crates/burn-optim/src/optim/muon.rs:432crates/burn-core/tests/test_derive_module.rs:9crates/burn-core/tests/test_record_resilience.rs:15crates/burn-vision/tests/common/mod.rs:12(usesNdArray<f32, i32>)burn-store(~30 sites)burn-storeis the biggest concentration by far. All test-only and mechanical to migrate:src/applier.rs:332,src/collector.rs:238,src/tensor_snapshot.rs:308src/safetensors/tests/{adapter,direct_access,error_handling,file_io,filtering,integration,metadata,multi_layer_verify,pytorch_import,round_trip}.rssrc/safetensors/tests/mixed_datatypes.rs: 7 separate instances inside nested test modules in one filesrc/pytorch/tests/store/mod.rslines 122, 256, 317, 403, 985src/burnpack/tests/{store,zero_copy}.rspytorch-tests/tests/backend.rs,pytorch-tests/tests/complex_nested/mod.rs:127,safetensors-tests/tests/backend.rsbenches/zero_copy_loading.rs:125,benches/unified_loading.rs:80A nice cleanup opportunity here: rather than edit 30 files, add a single
type TestBackend = ...alias at the crate level and have the test modules import it.burn-collective(4 sites)crates/burn-collective/src/tests/broadcast.rs:17crates/burn-collective/src/tests/all_reduce.rs:17crates/burn-collective/src/tests/reduce.rs:17crates/burn-collective/multinode-tests/src/bin/node.rs:23Examples and docs (out of scope for this issue)
Separate concern, and probably the right moment to change them is when flex becomes the default recommended CPU backend in the
burnumbrella, not now:examples/{simple-regression,mnist-inference-web,import-model-weights,dqn-agent,notebook}burn-book/src/{onnx-import.md,basic-workflow/model.md,advanced/no-std.md,advanced/backend-extension/README.md},contributor-book/src/project-architecture/backend.mdProposed ordering
test-flexcfg branches toburn-core,burn-nn,burn-optim. Three one-line edits plus Cargo.toml features. Reuses the existingtest-<backend>pattern.burn-trainandburn-rl, which are hardcoded to ndarray today with no feature escape.burn-storesweep: either add a crate-level alias and consolidate, or do a mechanical replace across the ~30 sites.burn-collectivesweep: 4 sites, mechanical.Notes
TestBackendsignatures likeNdArray<f32, i32>inburn-vision. Flex exposes the same phantom-generic shape (Flex<E = f32, I = i32>) soFlex<f32, i32>is valid, but only the default instantiation implementsBackend(Add burn-flex CPU backend (intended to replace burn-ndarray) #4761 ships a compile_fail doctest locking this in).