crates/burn-backend-tests/README.md
This crate provides a comprehensive suite of tests for Burn backends, covering:
The TestBackend is selected via feature flags. Use the provided shorthand commands for
convenience:
# Cpu
cargo test-cpu
# Cuda
cargo test-cuda
# Rocm
cargo test-rocm
# Wgpu / WebGpu
cargo test-wgpu
# Vulkan
cargo test-vulkan
# Metal
cargo test-metal
# Router
cargo test-router
# NdArray
cargo test-ndarray
# LibTorch
cargo test-tch
By default, cargo test fail-fast across integration test binaries. When one integration test
binary fails, Cargo does not run the remaining test binaries. If you want to run all test binaries
regardless of failures, pass --no-fail-fast, for example:
cargo test-cuda --no-fail-fast
tests/tensor.rs: Tensor teststests/autodiff.rs: Autodiff teststests/fusion.rs: Fusion backend tests wrapping tensor and autodiff teststests/cubecl.rs: CubeCL kernel testsEach test module assumes exactly one FloatElemType, IntElemType, and TestBackend in scope.
common/backend.rs: Backend type definitionscommon/tensor.rs: Reusable tensor test suite, split across float, int and bool tensor kindscommon/autodiff.rs: Reusable autodiff test suite, with and without checkpointingThis crate uses a pattern of parameterized test modules to run the same tests with different configurations (backends, dtypes, etc.):
FloatElemType,
IntElemType, and TestBackend#[path = "..."] references shared modules: Points to test files outside the normal module
hierarchy, e.g. "common/tensor.rs"include!() imports test code: Test modules are included multiple times with different type
configurationsuse super::*; propagates types down the module tree: Each level re-exports parent types so
deeply nested tests have access to the configured typesFor example, common/tensor.rs can be included with FloatElemType = f32 for base tests, then
included again with FloatElemType = f16 for half-precision tests, running the same test suite
twice with different dtypes.
Add test modules under tests/tensor/, tests/autodiff/, or tests/cubecl respectively. They will
automatically run for all required configurations.
For tensor tests, make sure to add the test to each relevant tensor kind:
tensor/bool: boolean tensor teststensor/float: float tensor teststensor/int: integer tensor testsGuidelines:
Import types with use super::*; at the top of each module and use the types defined in
common/backend.rs:
/// Collection of types used across tests
pub use burn_autodiff::Autodiff;
pub use burn_tensor::Tensor;
pub type TestBackend = ...;
pub type TestTensor<const D: usize> = Tensor<TestBackend, D>;
pub type TestTensorInt<const D: usize> = Tensor<TestBackend, D, burn_tensor::Int>;
pub type TestTensorBool<const D: usize> = Tensor<TestBackend, D, burn_tensor::Bool>;
pub type FloatElem = burn_tensor::ops::FloatElem<TestBackend>;
pub type IntElem = burn_tensor::ops::IntElem<TestBackend>;
pub type TestAutodiffBackend = Autodiff<TestBackend>;
pub type TestAutodiffTensor<const D: usize> = Tensor<TestAutodiffBackend, D>;
Tests will automatically run with default dtypes and any variants (f16, bf16, etc.) based on the backend configuration.