{"record":{"id":"7cc5e1acb714e794","repo":"tracel-ai/burn","slug":"nearest-exact-interpolation-backward-is-not-suppor-7cc5e1","errorCode":null,"errorMessage":"nearest exact interpolation backward is not supported by PyTorch/tch backend","messagePattern":"nearest exact interpolation backward is not supported by PyTorch/tch backend","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-tch/src/ops/module.rs","lineNumber":460,"sourceCode":"        grad: TchTensor,\n        output_size: [usize; 2],\n        options: InterpolateOptions,\n    ) -> TchTensor {\n        let output_size = output_size.map(|e| e as i64);\n        let [n, c, h_in, w_in] = x.shape().dims();\n        let input_size = [n as i64, c as i64, h_in as i64, w_in as i64];\n        let align_corners = options.align_corners;\n\n        let tensor = match options.mode {\n            InterpolateMode::Nearest => tch::Tensor::upsample_nearest2d_backward(\n                &grad.tensor,\n                output_size,\n                input_size,\n                None,\n                None,\n            ),\n            InterpolateMode::NearestExact => {\n                panic!(\n                    \"nearest exact interpolation backward is not supported by PyTorch/tch backend\"\n                )\n            }\n            InterpolateMode::Bilinear => tch::Tensor::upsample_bilinear2d_backward(\n                &grad.tensor,\n                output_size,\n                input_size,\n                align_corners,\n                None,\n                None,\n            ),\n            InterpolateMode::Bicubic => tch::Tensor::upsample_bicubic2d_backward(\n                &grad.tensor,\n                output_size,\n                input_size,\n                align_corners,\n                None,\n                None,","sourceCodeStart":442,"sourceCodeEnd":478,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-tch/src/ops/module.rs#L442-L478","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nlet options = InterpolateOptions::new(InterpolateMode::NearestExact);\n// after\nlet options = InterpolateOptions::new(InterpolateMode::Nearest);","handlingStrategy":"validation","validationCode":"fn ensure_interpolate_backward_supported(options: &InterpolateOptions) {\n    match options.mode {\n        InterpolateMode::NearestExact | InterpolateMode::Lanczos3 => {\n            panic!(\"mode {:?} has no backward in burn-tch; use Nearest/Bilinear/Bicubic\", options.mode)\n        }\n        _ => {}\n    }\n}","typeGuard":null,"tryCatchPattern":"let result = std::panic::catch_unwind(|| model.forward(x).backward());\nmatch result {\n    Ok(grads) => grads,\n    Err(_) => fallback_to_supported_backend_or_mode(),\n}","preventionTips":["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"],"tags":["rust","burn","tch","unsupported-operation","interpolation","backward-pass"],"backgroundTag":"unsupported-op-backend","analyzedSha":"d16f7ba2ed0d41408189384044cc886fb4c8f957","analyzedAt":"2026-09-05T13:19:14.260Z","contentChangedAt":"2026-09-05T13:19:14.260Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}