tracel-ai/burn · error
nearest exact interpolation is not supported by PyTorch/tch
Error message
nearest exact interpolation is not supported by PyTorch/tch backend
What it means
The tch (PyTorch) backend's `interpolate` implementation supports Nearest, Bilinear, and Bicubic modes via tch's upsample kernels. `InterpolateMode::NearestExact` has no equivalent tch call wired up here, so selecting it panics at runtime. It's an explicit unsupported-feature guard, not a data error.
Source
Thrown at crates/burn-tch/src/ops/module.rs:424
let tensor = tch::Tensor::adaptive_avg_pool1d(&x.tensor, output_size as i64);
TchTensor::new(tensor)
}
fn interpolate(
x: TchTensor,
output_size: [usize; 2],
options: InterpolateOptions,
) -> 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,View on GitHub (pinned to d16f7ba2ed)
Solutions
- Switch the interpolation mode to `InterpolateMode::Nearest`, which behaves nearly identically for most upsampling use cases.
- Use a backend that supports NearestExact (e.g. wgpu/cubecl or ndarray) for this model.
- Implement a manual nearest-exact path (compute source indices with the exact formula) using tch tensor ops, or upcycle via burn's ONNX export to a runtime that supports it.
Example fix
// before let options = InterpolateOptions::new(InterpolateMode::NearestExact); // panics on tch // after let options = InterpolateOptions::new(InterpolateMode::Nearest);
Defensive patterns
Strategy: validation
Validate before calling
fn assert_tch_supported(mode: InterpolateMode) {
assert!(!matches!(mode, InterpolateMode::NearestExact | InterpolateMode::Lanczos3),
"{mode:?} 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
- Check backend op support tables before switching features/backends
- Use Nearest or Bicubic modes in tch-targeted code
- Add a unit test per backend for every interpolation mode your model uses
When it happens
Trigger: Running a model (or calling `Module::interpolate`/upsample ops) on the burn-tch backend with `InterpolateOptions::new(InterpolateMode::NearestExact)`.
Common situations: Porting a model from burn's ndarray/wgpu/cubecl backends (which support NearestExact) to tch; copying interpolation config from an ONNX-imported graph that emits nearest-exact resize; switching backends via a feature flag without auditing op support.
Related errors
- lanczos3 interpolation is not supported by PyTorch/tch backe
- nearest exact interpolation backward is not supported by PyT
- lanczos3 interpolation backward is not supported by PyTorch/
- Not a valid float kind
- capture tensor operations must run inside CaptureDevice::cap
AI-assisted analysis of tracel-ai/burn@d16f7ba2ed (2026-09-05).
Data as JSON: /api/errors/c9e8cce7ae6736fd.
Report an issue: GitHub.