tracel-ai/burn · error
todo!("Default implementation for grid_sample_2d with {:?} u
Error message
todo!("Default implementation for grid_sample_2d with {:?} unimplemented", options.mode) What it means
The reference implementation of `grid_sample_2d` supports only the Bilinear interpolation mode; other `InterpolateMode` variants hit a `_ => todo!` arm and panic. `grid_sample` in burn is partially implemented: only bilinear sampling has a default (reference) kernel.
Source
Thrown at crates/burn-backend/src/backend/ops/modules/grid_sample.rs:33
/// A [x = -1, y = -1] means top-left, and [x = 1, y = 1] means bottom-right
/// * `options` - Grid sampling options
///
/// # Returns
///
/// A tensor with shape (N, C, H_out, W_out)
pub fn float_grid_sample_2d_ref<B: Backend>(
tensor: FloatTensor<B>,
grid: FloatTensor<B>,
options: GridSampleOptions,
) -> FloatTensor<B> {
match options.mode {
InterpolateMode::Bilinear => float_grid_sample_2d_bilinear::<B>(
tensor,
grid,
options.padding_mode,
options.align_corners,
),
_ => todo!(
"Default implementation for grid_sample_2d with {:?} unimplemented",
options.mode
),
}
}
/// Bilinear grid sampling implementation.
fn float_grid_sample_2d_bilinear<B: Backend>(
tensor: FloatTensor<B>,
grid: FloatTensor<B>,
padding_mode: GridSamplePaddingMode,
align_corners: bool,
) -> FloatTensor<B> {
let n = tensor.shape()[0];
let c = tensor.shape()[1];
let h_in = tensor.shape()[2];
let w_in = tensor.shape()[3];
let h_out = grid.shape()[1];View on GitHub (pinned to d16f7ba2ed)
Solutions
- Set `options.mode = InterpolateMode::Bilinear` before calling grid_sample.
- Pre-process the sampling in a supported way (implement nearest sampling manually with gather/index ops).
- Export/convert the source model with bilinear grid sampling.
- Update burn or file an issue upstream if you need another mode.
Example fix
// before let options = GridSampleOptions::new(InterpolateMode::Nearest, padding, align); let out = grid.grid_sample_2d(input, options); // after let options = GridSampleOptions::new(InterpolateMode::Bilinear, padding, align); let out = grid.grid_sample_2d(input, options);
Defensive patterns
Strategy: validation
Validate before calling
use burn::tensor::module::grid_sample::{GridSampleOptions, InterpolateMode};
fn grid_sample_supported(o: &GridSampleOptions) -> bool {
matches!(o.mode, InterpolateMode::Bilinear)
} Type guard
fn is_bilinear(mode: &InterpolateMode) -> bool { matches!(mode, InterpolateMode::Bilinear) } Prevention
- Always construct GridSampleOptions with InterpolateMode::Bilinear.
- Validate ONNX GridSample node attributes at conversion time.
- Wrap model conversion with a check that rejects non-bilinear sampling.
- Implement nearest sampling manually if required.
When it happens
Trigger: Calling `Tensor::grid_sample` (or the module op) with `GridSampleOptions` whose `mode` is not Bilinear (e.g. Nearest or bicubic), or loading an ONNX model whose GridSample node specifies a non-bilinear mode.
Common situations: Porting ONNX/PyTorch GridSample models that use `mode='nearest'` or 'bicubic'; copy-pasting options from a PyTorch implementation using nearest-neighbor sampling; experimental features enabled that change interpolation mode.
Related errors
- todo!("grid_sample_2d with {:?} mode is not implemented", op
- SVD fallback failed: {err}
- Quantization scheme is not valid for dtype {other:?}
- Can't store native sub-byte values
- {other:?} doesn't support native packing
AI-assisted analysis of tracel-ai/burn@d16f7ba2ed (2026-09-05).
Data as JSON: /api/errors/cba69f3cee47d524.
Report an issue: GitHub.