{"record":{"id":"c9e8cce7ae6736fd","repo":"tracel-ai/burn","slug":"nearest-exact-interpolation-is-not-supported-by-py","errorCode":null,"errorMessage":"nearest exact interpolation is not supported by PyTorch/tch backend","messagePattern":"nearest exact interpolation is not supported by PyTorch/tch backend","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-tch/src/ops/module.rs","lineNumber":424,"sourceCode":"        let tensor = tch::Tensor::adaptive_avg_pool1d(&x.tensor, output_size as i64);\n\n        TchTensor::new(tensor)\n    }\n\n    fn interpolate(\n        x: TchTensor,\n        output_size: [usize; 2],\n        options: InterpolateOptions,\n    ) -> TchTensor {\n        let output_size = output_size.map(|e| e as i64);\n\n        let align_corners = options.align_corners;\n        let tensor = match options.mode {\n            InterpolateMode::Nearest => {\n                tch::Tensor::upsample_nearest2d(&x.tensor, output_size, None, None)\n            }\n            InterpolateMode::NearestExact => {\n                panic!(\"nearest exact interpolation is not supported by PyTorch/tch backend\")\n            }\n            InterpolateMode::Bilinear => {\n                tch::Tensor::upsample_bilinear2d(&x.tensor, output_size, align_corners, None, None)\n            }\n            InterpolateMode::Bicubic => {\n                tch::Tensor::upsample_bicubic2d(&x.tensor, output_size, align_corners, None, None)\n            }\n            InterpolateMode::Lanczos3 => {\n                panic!(\"lanczos3 interpolation is not supported by PyTorch/tch backend\")\n            }\n        };\n\n        TchTensor::new(tensor)\n    }\n\n    fn interpolate_backward(\n        x: TchTensor,\n        grad: TchTensor,","sourceCodeStart":406,"sourceCodeEnd":442,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-tch/src/ops/module.rs#L406-L442","documentation":"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.","triggerScenarios":"Running a model (or calling `Module::interpolate`/upsample ops) on the burn-tch backend with `InterpolateOptions::new(InterpolateMode::NearestExact)`.","commonSituations":"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.","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."],"exampleFix":"// before\nlet options = InterpolateOptions::new(InterpolateMode::NearestExact); // panics on tch\n// after\nlet options = InterpolateOptions::new(InterpolateMode::Nearest);","handlingStrategy":"validation","validationCode":"fn assert_tch_supported(mode: InterpolateMode) {\n    assert!(!matches!(mode, InterpolateMode::NearestExact | InterpolateMode::Lanczos3),\n            \"{mode:?} is not supported by the tch backend\");\n}","typeGuard":null,"tryCatchPattern":"// panic is unconditional; guard the call site\nlet result = std::panic::catch_unwind(AssertUnwindSafe(|| model.forward(x)));","preventionTips":["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"],"tags":["rust","panic","tch","pytorch","unsupported-operation"],"backgroundTag":"unsupported-interpolation-mode","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"}