- Updated stablediffusion crate path from "../stable-diffusion-burn" to "./crates/stable-diffusion-burn" for proper workspace resolution - Enhanced .gitignore to include generated model files (.mpk, .pt, .bin, .safetensors, .ckpt) and user_data directory - Added Cargo.lock to gitignore with appropriate comment - Reorganized IDE files section in gitignore for better clarity - Added newline at end of file for proper formatting
3.6 KiB
Burn Backend Tests
This crate provides a comprehensive suite of tests for Burn backends, covering:
- Tensor operations: tests/tensor/
- Autodiff: tests/autodiff/
- (Optional) CubeCL kernels correctness: tests/cubecl/
Running Tests
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
Structure
tests/tensor.rs: Tensor teststests/autodiff.rs: Autodiff teststests/fusion.rs: Fusion backend tests wrapping tensor and autodiff teststests/cubecl.rs: CubeCL kernel tests
Each test module assumes exactly one FloatElemType, IntElemType, and TestBackend in scope.
Common Modules
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 checkpointing
Test Reusability
This crate uses a pattern of parameterized test modules to run the same tests with different configurations (backends, dtypes, etc.):
- Type aliases define the configuration: Each test scope declares
FloatElemType,IntElemType, andTestBackend #[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 types
For 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.
Adding New Tests
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 tests
Guidelines:
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.