{"record":{"id":"07ddd4aa5e7aa116","repo":"tracel-ai/burn","slug":"grid-sample-2d-mode-is-not-supported","errorCode":null,"errorMessage":"grid_sample_2d: {:?} mode is not supported","messagePattern":"grid_sample_2d: (.+?) mode is not supported","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-flex/src/ops/grid_sample.rs","lineNumber":31,"sourceCode":"use burn_std::{Bytes, Shape, bf16, f16};\n\nuse num_traits::{Float, NumCast};\n\nuse crate::{FlexTensor, Layout};\n\n/// Grid sample 2D (bilinear and nearest-neighbor interpolation).\n///\n/// Input tensor shape: [N, C, H_in, W_in]\n/// Grid shape: [N, H_out, W_out, 2] (x, y normalized to [-1, 1])\n/// Output shape: [N, C, H_out, W_out]\npub fn grid_sample_2d(\n    tensor: FlexTensor,\n    grid: FlexTensor,\n    options: GridSampleOptions,\n) -> FlexTensor {\n    match options.mode {\n        InterpolateMode::Bilinear | InterpolateMode::Nearest => {}\n        other => panic!(\"grid_sample_2d: {:?} mode is not supported\", other),\n    }\n\n    let tensor = tensor.to_contiguous();\n    let grid = grid.to_contiguous();\n\n    match tensor.dtype() {\n        DType::F32 => grid_sample_2d_impl::<f32>(tensor, grid, options),\n        DType::F64 => grid_sample_2d_impl::<f64>(tensor, grid, options),\n        DType::F16 => grid_sample_2d_impl::<f16>(tensor, grid, options),\n        DType::BF16 => grid_sample_2d_impl::<bf16>(tensor, grid, options),\n        _ => panic!(\"grid_sample_2d: unsupported dtype {:?}\", tensor.dtype()),\n    }\n}\n\nfn grid_sample_2d_impl<T>(\n    tensor: FlexTensor,\n    grid: FlexTensor,\n    options: GridSampleOptions,","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-flex/src/ops/grid_sample.rs#L13-L49","documentation":"burn-flex's grid_sample_2d only implements Bilinear and Nearest interpolation modes. Any other InterpolateMode (e.g. bicubic, as offered by other backends or future modes) hits this panic, because there is no implementation for it in this backend.","triggerScenarios":"Calling grid_sample_2d with GridSampleOptions whose mode is anything other than InterpolateMode::Bilinear or InterpolateMode::Nearest.","commonSituations":"Config copied from a PyTorch/torchvision model that used mode='bicubic'; a shared options struct set for another backend that supports more modes; a version change where a new InterpolateMode variant became available but burn-flex has not implemented it.","solutions":["Set the interpolation mode to InterpolateMode::Bilinear (most common for grid_sample)","Use InterpolateMode::Nearest if exact nearest-neighbor semantics are acceptable","Implement or request bicubic support upstream in burn-flex, or switch to a backend that supports it","Add a runtime assertion/whitelist of modes before constructing the options"],"exampleFix":"// before\nlet options = GridSampleOptions::new(InterpolateMode::Cubic, PaddingMode::Zeros, true);\nlet out = backend.grid_sample_2d(tensor, grid, options); // panic\n// after\nlet options = GridSampleOptions::new(InterpolateMode::Bilinear, PaddingMode::Zeros, true);\nlet out = backend.grid_sample_2d(tensor, grid, options);","handlingStrategy":"validation","validationCode":"// before calling grid_sample_2d\nmatch options.mode {\n    burn::tensor::InterpolateMode::Bilinear | burn::tensor::InterpolateMode::Nearest => {},\n    other => panic!(\"burn-flex grid_sample_2d does not support {:?}\", other),\n}","typeGuard":"fn grid_sample_mode_supported(m: &InterpolateMode) -> bool {\n    matches!(m, InterpolateMode::Bilinear | InterpolateMode::Nearest)\n}","tryCatchPattern":null,"preventionTips":["Restrict configurable interpolation modes to Bilinear/Nearest when targeting burn-flex","Map bicubic requests to bilinear with a warning at config load time"],"tags":["panic","unsupported-feature","grid-sample","rust"],"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"}