{"record":{"id":"cba69f3cee47d524","repo":"tracel-ai/burn","slug":"todo-default-implementation-for-grid-sample-2d-w","errorCode":null,"errorMessage":"todo!(\"Default implementation for grid_sample_2d with {:?} unimplemented\", options.mode)","messagePattern":"todo!\\(\"Default implementation for grid_sample_2d with (.+?) unimplemented\", options\\.mode\\)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-backend/src/backend/ops/modules/grid_sample.rs","lineNumber":33,"sourceCode":"///   A [x = -1, y = -1] means top-left, and [x = 1, y = 1] means bottom-right\n/// * `options` - Grid sampling options\n///\n/// # Returns\n///\n/// A tensor with shape (N, C, H_out, W_out)\npub fn float_grid_sample_2d_ref<B: Backend>(\n    tensor: FloatTensor<B>,\n    grid: FloatTensor<B>,\n    options: GridSampleOptions,\n) -> FloatTensor<B> {\n    match options.mode {\n        InterpolateMode::Bilinear => float_grid_sample_2d_bilinear::<B>(\n            tensor,\n            grid,\n            options.padding_mode,\n            options.align_corners,\n        ),\n        _ => todo!(\n            \"Default implementation for grid_sample_2d with {:?} unimplemented\",\n            options.mode\n        ),\n    }\n}\n\n/// Bilinear grid sampling implementation.\nfn float_grid_sample_2d_bilinear<B: Backend>(\n    tensor: FloatTensor<B>,\n    grid: FloatTensor<B>,\n    padding_mode: GridSamplePaddingMode,\n    align_corners: bool,\n) -> FloatTensor<B> {\n    let n = tensor.shape()[0];\n    let c = tensor.shape()[1];\n    let h_in = tensor.shape()[2];\n    let w_in = tensor.shape()[3];\n    let h_out = grid.shape()[1];","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-backend/src/backend/ops/modules/grid_sample.rs#L15-L51","documentation":"The reference implementation of `grid_sample_2d` supports only the Bilinear interpolation mode; other `InterpolateMode` variants hit a `_ => todo!` arm and panic. `grid_sample` in burn is partially implemented: only bilinear sampling has a default (reference) kernel.","triggerScenarios":"Calling `Tensor::grid_sample` (or the module op) with `GridSampleOptions` whose `mode` is not Bilinear (e.g. Nearest or bicubic), or loading an ONNX model whose GridSample node specifies a non-bilinear mode.","commonSituations":"Porting ONNX/PyTorch GridSample models that use `mode='nearest'` or 'bicubic'; copy-pasting options from a PyTorch implementation using nearest-neighbor sampling; experimental features enabled that change interpolation mode.","solutions":["Set `options.mode = InterpolateMode::Bilinear` before calling grid_sample.","Pre-process the sampling in a supported way (implement nearest sampling manually with gather/index ops).","Export/convert the source model with bilinear grid sampling.","Update burn or file an issue upstream if you need another mode."],"exampleFix":"// before\nlet options = GridSampleOptions::new(InterpolateMode::Nearest, padding, align);\nlet out = grid.grid_sample_2d(input, options);\n// after\nlet options = GridSampleOptions::new(InterpolateMode::Bilinear, padding, align);\nlet out = grid.grid_sample_2d(input, options);","handlingStrategy":"validation","validationCode":"use burn::tensor::module::grid_sample::{GridSampleOptions, InterpolateMode};\nfn grid_sample_supported(o: &GridSampleOptions) -> bool {\n    matches!(o.mode, InterpolateMode::Bilinear)\n}","typeGuard":"fn is_bilinear(mode: &InterpolateMode) -> bool { matches!(mode, InterpolateMode::Bilinear) }","tryCatchPattern":null,"preventionTips":["Always construct GridSampleOptions with InterpolateMode::Bilinear.","Validate ONNX GridSample node attributes at conversion time.","Wrap model conversion with a check that rejects non-bilinear sampling.","Implement nearest sampling manually if required."],"tags":["burn","grid-sample","unimplemented","panic"],"backgroundTag":"unimplemented-op","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"}