tracel-ai/burn · error

nearest exact interpolation backward is not supported for nd

Error message

nearest exact interpolation backward is not supported for ndarray backend

What it means

interpolate_backward on the ndarray backend only implements the Nearest mode's backward pass; NearestExact, Bilinear, and Bicubic have no backward implementation and panic. Training (backward) with these upsample modes on ndarray is unsupported.

Source

Thrown at crates/burn-ndarray/src/ops/module.rs:353

                    align_corners
                )
                .into())
            }
        }
    }

    fn interpolate_backward(
        x: FloatTensor<Self>,
        grad: FloatTensor<Self>,
        output_size: [usize; 2],
        options: InterpolateOptions,
    ) -> FloatTensor<Self> {
        match options.mode {
            InterpolateMode::Nearest => module_op!(inp(x, grad), opt(), E, |x, grad| {
                nearest_interpolate_backward::<E>(x, grad, output_size).into()
            }),
            InterpolateMode::NearestExact => {
                panic!("nearest exact interpolation backward is not supported for ndarray backend")
            }
            InterpolateMode::Bilinear => {
                panic!("bilinear interpolation backward is not supported for ndarray backend")
            }
            InterpolateMode::Bicubic => {
                panic!("bicubic interpolation backward is not supported for ndarray backend")
            }
            InterpolateMode::Lanczos3 => {
                panic!("lanczos3 interpolation backward is not supported for ndarray backend")
            }
        }
    }

    fn conv3d(
        x: FloatTensor<Self>,
        weight: FloatTensor<Self>,
        bias: Option<FloatTensor<Self>>,
        options: ConvOptions<3>,

View on GitHub (pinned to d16f7ba2ed)

Solutions

  1. Use InterpolateMode::Nearest for upsampling during training on ndarray (only mode with backward support).
  2. Train with a backend that implements the backward pass (burn-tch, burn-cubecl) for bilinear/bicubic.
  3. Replace learned upsampling with unexpand/upsample via ConvTranspose2d (which has ndarray backward support).
  4. Detach at the upsample layer (inference-only upsample) if gradients through it are acceptable to drop.

Example fix

// before (training, ndarray backend)
let up = x.interpolate([h*2, w*2], InterpolateOptions::new(InterpolateMode::Bilinear));
// backward panics
// after
let up = x.interpolate([h*2, w*2], InterpolateOptions::new(InterpolateMode::Nearest));
// or switch to BurnTch backend for bilinear training
Defensive patterns

Strategy: fallback

Validate before calling

fn has_interpolate_backward(mode: &InterpolateMode) -> bool {
    matches!(mode, InterpolateMode::Nearest) // ndarray backward support
}

Prevention

When it happens

Trigger: Backward pass through an interpolate/upsample layer with InterpolateMode::NearestExact, Bilinear, or Bicubic on the NdArray backend (e.g. in a U-Net-style autoencoder during training).

Common situations: Training segmentation/super-resolution models with bilinear upsampling on ndarray; models exported with nearest-exact resize then fine-tuned.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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