{"record":{"id":"82eb32705597a362","repo":"tracel-ai/burn","slug":"lanczos3-interpolation-is-not-supported-by-pytorch","errorCode":null,"errorMessage":"lanczos3 interpolation is not supported by PyTorch/tch backend","messagePattern":"lanczos3 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":433,"sourceCode":"    ) -> 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,\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 {","sourceCodeStart":415,"sourceCodeEnd":451,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-tch/src/ops/module.rs#L415-L451","documentation":"Like NearestExact, `InterpolateMode::Lanczos3` is not implemented for the tch backend because libtorch's upsample2d API exposed through tch does not provide a lanczos kernel here. Choosing Lanczos3 interpolation on the PyTorch/tch backend panics at runtime with this message.","triggerScenarios":"Calling interpolate/upsample with `InterpolateMode::Lanczos3` while running on the burn-tch backend.","commonSituations":"Models ported from image-processing pipelines (PIL/OpenCV lanczos resizing) into burn; ONNX imports of resize ops with lanczos mode; running the same model code against different backends where lanczos worked on one backend but not tch.","solutions":["Use `InterpolateMode::Bicubic` on tch — it's the closest supported high-quality mode.","Pre-resize with lanczos in your image loading pipeline (e.g. image crate / OpenCV) and skip runtime interpolation.","Run this model on a backend that supports Lanczos3, or contribute the op to burn-tch."],"exampleFix":"// before\nlet options = InterpolateOptions::new(InterpolateMode::Lanczos3); // panics on tch\n// after\nlet options = InterpolateOptions::new(InterpolateMode::Bicubic);","handlingStrategy":"validation","validationCode":"fn assert_tch_supported(mode: InterpolateMode) {\n    assert!(!matches!(mode, InterpolateMode::Lanczos3),\n            \"Lanczos3 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":["Prefer Bicubic on the tch backend","Do lanczos resizing in the image-loading pipeline instead of in the model","Test models on each backend you intend to deploy to"],"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"}