tracel-ai/burn · error
nearest exact interpolation backward is not supported by PyT
Error message
nearest exact interpolation backward is not supported by PyTorch/tch backend
What it means
The burn-tch (LibTorch) backend does not implement the backward pass for NearestExact interpolation mode; calling it panics. PyTorch has no direct upsample_nearest_exact2d_backward binding exposed via tch, so the backend intentionally aborts instead of silently producing wrong gradients. This is an unimplemented-feature panic, not a data or environment problem.
Source
Thrown at crates/burn-tch/src/ops/module.rs:460
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 {
InterpolateMode::Nearest => tch::Tensor::upsample_nearest2d_backward(
&grad.tensor,
output_size,
input_size,
None,
None,
),
InterpolateMode::NearestExact => {
panic!(
"nearest exact interpolation backward is not supported by PyTorch/tch backend"
)
}
InterpolateMode::Bilinear => tch::Tensor::upsample_bilinear2d_backward(
&grad.tensor,
output_size,
input_size,
align_corners,
None,
None,
),
InterpolateMode::Bicubic => tch::Tensor::upsample_bicubic2d_backward(
&grad.tensor,
output_size,
input_size,
align_corners,
None,
None,View on GitHub (pinned to d16f7ba2ed)
Solutions
- Switch the interpolate layer to InterpolateMode::Nearest for tch (backward is supported and usually numerically close)
- Use InterpolateMode::Bilinear or Bicubic, both of which have supported backward passes in tch
- Run this model/graph on a backend that implements NearestExact backward (e.g. burn-cube/wgpu)
- Guard the mode at startup: validate InterpolateOptions before building the training loop and reject NearestExact when the tch backend is selected
Example fix
// before let options = InterpolateOptions::new(InterpolateMode::NearestExact); // after let options = InterpolateOptions::new(InterpolateMode::Nearest);
Defensive patterns
Strategy: validation
Validate before calling
fn ensure_interpolate_backward_supported(options: &InterpolateOptions) {
match options.mode {
InterpolateMode::NearestExact | InterpolateMode::Lanczos3 => {
panic!("mode {:?} has no backward in burn-tch; use Nearest/Bilinear/Bicubic", options.mode)
}
_ => {}
}
} Try / catch
let result = std::panic::catch_unwind(|| model.forward(x).backward());
match result {
Ok(grads) => grads,
Err(_) => fallback_to_supported_backend_or_mode(),
} Prevention
- Never use InterpolateMode::NearestExact or Lanczos3 in models that will train on burn-tch
- Centralize interpolate options in one config module and assert backend compatibility at startup
- Add a smoke test that backprops through every layer/mode combination you ship
- Prefer Bilinear for resize layers on tch
When it happens
Trigger: Backward pass of a model whose interpolate (upsample) layer uses InterpolateOptions { mode: InterpolateMode::NearestExact } on the tch backend — i.e. during autodiff training or gradient computation of a resize/upsample op configured with mode=nearest-exact.
Common situations: Porting a model from the burn-cube/wgpu backend (where NearestExact works) to burn-tch for training; configuring interpolation mode to match an ONNX/PyTorch 'nearest-exact' resize; shared training code that lets a config file pick the mode.
Related errors
- lanczos3 interpolation backward is not supported by PyTorch/
- Can't use deformable convolution backwards pass without atom
- nearest exact interpolation is not supported by PyTorch/tch
- lanczos3 interpolation is not supported by PyTorch/tch backe
- Not a valid float kind
AI-assisted analysis of tracel-ai/burn@d16f7ba2ed (2026-09-05).
Data as JSON: /api/errors/7cc5e1acb714e794.
Report an issue: GitHub.