| name | burn-backends |
| description | This skill should be used when the user asks about "Burn backend", "WGPU", "NdArray", "Candle", "LibTorch", "custom kernel", "CubeCL", "quantization", "WebAssembly", "no_std", or backend selection and extension. |
| version | 0.1.0 |
Burn Backends
Knowledge for selecting, configuring, and extending Burn compute backends.
Available Backends
| Backend | Use Case | Features Flag |
|---|
| WGPU | GPU, cross-platform | wgpu |
| NdArray | CPU, testing | ndarray |
| Candle | Hugging Face ecosystem | candle |
| LibTorch | PyTorch interop | tch |
Backend Selection
Choose in Cargo.toml:
[dependencies]
burn = { version = "0.16", features = ["wgpu"] }
Use in code:
use burn::backend::Wgpu;
type MyBackend = Wgpu;
type MyBackend = Autodiff<Wgpu>;
let device = WgpuDevice::default();
Device Configuration
Each backend has its device type:
let device = WgpuDevice::default();
let device = WgpuDevice::Cpu;
let device = NdArrayDevice::Cpu;
let device = LibTorchDevice::Cuda(0);
let device = LibTorchDevice::Cpu;
Backend Portability
Write backend-agnostic code with generics:
fn train<B: AutodiffBackend>(device: B::Device) {
let model: Model<B> = ModelConfig::new().init(&device);
}
Custom Kernels (CubeCL)
For performance-critical operations:
use burn_cube::prelude::*;
#[cube(launch)]
fn custom_kernel<F: Float>(input: &Tensor<F>, output: &mut Tensor<F>) {
let idx = ABSOLUTE_POS;
output[idx] = input[idx] * F::new(2.0);
}
Quantization
Reduce model size and improve inference speed:
use burn::module::Quantizer;
let quantizer = Quantizer::new(QuantizationScheme::Symmetric);
let quantized_model = quantizer.quantize(model);
WebAssembly Deployment
Burn supports WASM targets:
[dependencies]
burn = { version = "0.16", features = ["wgpu", "wasm-bindgen"] }
Build with:
wasm-pack build --target web
Additional Resources
Consult references/topic-map-backends.md for:
- Detailed backend comparison
- Custom WGPU kernel guide
- Quantization schemes and calibration
- No-std embedded deployment