pub struct FloatCastAdapter { /* private fields */ }Expand description
Adapter that casts every float tensor to one target dtype.
Unlike HalfPrecisionAdapter, which infers the direction from the
source dtype (F32 <-> F16 only) and converts a fixed list of module types,
this adapter is target-driven: every float tensor (F64, F32, Flex32,
F16, BF16) is converted to the given dtype regardless of which module it
belongs to. Non-float tensors (ints, bools, quantized) and tensors already
in the target dtype pass through unchanged.
This is the right tool for loading a stock checkpoint into a module whose
backend runs at a different float precision, e.g. BF16 safetensors into
an F16 model. HalfPrecisionAdapter passes BF16 tensors through
unconverted and skips custom module types entirely, so the loaded params
silently keep the source dtype instead of the module’s.
§Examples
Cast everything to the backend’s float element on load:
let adapter = FloatCastAdapter::to(<B::FloatElem as Element>::dtype());
// store.with_from_adapter(adapter);Chain after a framework adapter:
let adapter = PyTorchToBurnAdapter.chain(FloatCastAdapter::to(DType::F16));