tracel-ai/burn · error

lanczos3 interpolation is not supported by PyTorch/tch backe

Error message

lanczos3 interpolation is not supported by PyTorch/tch backend

What it means

Like NearestExact, `InterpolateMode::Lanczos3` is not implemented for the tch backend because libtorch's upsample2d API exposed through tch does not provide a lanczos kernel here. Choosing Lanczos3 interpolation on the PyTorch/tch backend panics at runtime with this message.

Source

Thrown at crates/burn-tch/src/ops/module.rs:433

    ) -> TchTensor {
        let output_size = output_size.map(|e| e as i64);

        let align_corners = options.align_corners;
        let tensor = match options.mode {
            InterpolateMode::Nearest => {
                tch::Tensor::upsample_nearest2d(&x.tensor, output_size, None, None)
            }
            InterpolateMode::NearestExact => {
                panic!("nearest exact interpolation is not supported by PyTorch/tch backend")
            }
            InterpolateMode::Bilinear => {
                tch::Tensor::upsample_bilinear2d(&x.tensor, output_size, align_corners, None, None)
            }
            InterpolateMode::Bicubic => {
                tch::Tensor::upsample_bicubic2d(&x.tensor, output_size, align_corners, None, None)
            }
            InterpolateMode::Lanczos3 => {
                panic!("lanczos3 interpolation is not supported by PyTorch/tch backend")
            }
        };

        TchTensor::new(tensor)
    }

    fn interpolate_backward(
        x: TchTensor,
        grad: TchTensor,
        output_size: [usize; 2],
        options: InterpolateOptions,
    ) -> TchTensor {
        let output_size = output_size.map(|e| e as i64);
        let [n, c, h_in, w_in] = x.shape().dims();
        let input_size = [n as i64, c as i64, h_in as i64, w_in as i64];
        let align_corners = options.align_corners;

        let tensor = match options.mode {

View on GitHub (pinned to d16f7ba2ed)

Solutions

  1. Use `InterpolateMode::Bicubic` on tch — it's the closest supported high-quality mode.
  2. Pre-resize with lanczos in your image loading pipeline (e.g. image crate / OpenCV) and skip runtime interpolation.
  3. Run this model on a backend that supports Lanczos3, or contribute the op to burn-tch.

Example fix

// before
let options = InterpolateOptions::new(InterpolateMode::Lanczos3); // panics on tch
// after
let options = InterpolateOptions::new(InterpolateMode::Bicubic);
Defensive patterns

Strategy: validation

Validate before calling

fn assert_tch_supported(mode: InterpolateMode) {
    assert!(!matches!(mode, InterpolateMode::Lanczos3),
            "Lanczos3 is not supported by the tch backend");
}

Try / catch

// panic is unconditional; guard the call site
let result = std::panic::catch_unwind(AssertUnwindSafe(|| model.forward(x)));

Prevention

When it happens

Trigger: Calling interpolate/upsample with `InterpolateMode::Lanczos3` while running on the burn-tch backend.

Common situations: Models ported from image-processing pipelines (PIL/OpenCV lanczos resizing) into burn; ONNX imports of resize ops with lanczos mode; running the same model code against different backends where lanczos worked on one backend but not tch.

Related errors


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