tracel-ai/burn · error

Unsupported grid_sample interpolation mode: {:?}

Error message

Unsupported grid_sample interpolation mode: {:?}

What it means

grid_sample on the CubeCL backend currently only implements bilinear interpolation. Any other InterpolateMode (nearest, bicubic, etc.) hits the catch-all match arm and panics at dispatch time. The message echoes the unsupported mode so you can see what was requested.

Source

Thrown at crates/burn-cubecl/src/kernel/grid_sample/base.rs:12

use cubecl::prelude::*;

use crate::tensor::CubeTensor;
use burn_backend::ops::{GridSampleOptions, GridSamplePaddingMode, InterpolateMode};

use super::bilinear::grid_sample_bilinear_launch;

/// Grid sample operation supporting bilinear interpolation
pub fn grid_sample(input: CubeTensor, grid: CubeTensor, options: GridSampleOptions) -> CubeTensor {
    match options.mode {
        InterpolateMode::Bilinear => grid_sample_bilinear_launch(input, grid, options),
        _ => panic!(
            "Unsupported grid_sample interpolation mode: {:?}",
            options.mode
        ),
    }
}

/// Compile-time padding mode for kernel specialization
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum PaddingMode {
    /// Fill with zeros for out-of-bounds coordinates.
    Zeros,
    /// Clamp coordinates to the border (use nearest edge value).
    Border,
    /// Reflect coordinates at the boundary.
    Reflection,
}

impl From<GridSamplePaddingMode> for PaddingMode {

View on GitHub (pinned to d16f7ba2ed)

Solutions

  1. Set options.mode to InterpolateMode::Bilinear
  2. Implement or request a nearest/bicubic grid_sample kernel, or fall back to a different backend that supports it
  3. Wrap the mode in config validation before building GridSampleOptions

Example fix

// before
let opts = GridSampleOptions { mode: InterpolateMode::Nearest, .. };
grid_sample(input, grid, opts);
// after
let opts = GridSampleOptions { mode: InterpolateMode::Bilinear, .. };
grid_sample(input, grid, opts);
Defensive patterns

Strategy: validation

Validate before calling

assert!(matches!(options.mode, InterpolateMode::Bilinear), "grid_sample supports only bilinear");

Prevention

When it happens

Trigger: Calling grid_sample with GridSampleOptions whose mode is anything other than InterpolateMode::Bilinear, e.g. Nearest or Bicubic.

Common situations: Porting models that use nearest-neighbor grid sampling (common in optical-flow / STN architectures) from PyTorch to Burn, or reusing option structs configured for interpolate() with grid_sample.

Related errors


AI-assisted analysis of tracel-ai/burn@d16f7ba2ed (2026-09-05). Data as JSON: /api/errors/f5c1128e86396492. Report an issue: GitHub.