{"record":{"id":"8b97ccfa19bd3d4c","repo":"tracel-ai/burn","slug":"grid-sample-2d-unsupported-dtype","errorCode":null,"errorMessage":"grid_sample_2d: unsupported dtype {:?}","messagePattern":"grid_sample_2d: unsupported dtype (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-flex/src/ops/grid_sample.rs","lineNumber":42,"sourceCode":"pub 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,\n) -> FlexTensor\nwhere\n    T: Float + Element + bytemuck::Pod,\n{\n    let t_shape = tensor.layout().shape();\n    let g_shape = grid.layout().shape();\n\n    assert_eq!(t_shape.num_dims(), 4, \"grid_sample_2d: input must be 4D\");\n    assert_eq!(g_shape.num_dims(), 4, \"grid_sample_2d: grid must be 4D\");\n    assert_eq!(g_shape[3], 2, \"grid_sample_2d: grid last dim must be 2\");\n    assert_eq!(","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-flex/src/ops/grid_sample.rs#L24-L60","documentation":"grid_sample_2d dispatches to a generic implementation only for float dtypes (F32, F64, F16, BF16). Integer dtypes have no grid-sample meaning in this backend, so any other dtype panics with the unsupported dtype message.","triggerScenarios":"Calling grid_sample_2d with a tensor whose DType is I64, I32, U8, etc. — e.g. a uint8 image tensor passed straight in.","commonSituations":"Passing a quantized/uint8 image tensor directly instead of normalizing to float first; porting code from frameworks where grid_sample implicitly casts; dtype drift after a pipeline refactor introduced an int tensor.","solutions":["Cast the input tensor (and grid, if needed) to a float dtype: tensor.cast::<f32>()","Normalize integer image data to [0,1] floats before grid sampling","Add a dtype check/assert before the call to fail early with a clearer message","Check the pipeline for an accidental int cast before grid_sample_2d"],"exampleFix":"// before\nlet out = backend.grid_sample_2d(image_u8, grid, options); // panic: unsupported dtype U8\n// after\nlet img_f32 = image_u8.cast::<f32>() / 255f32;\nlet out = backend.grid_sample_2d(img_f32, grid, options);","handlingStrategy":"validation","validationCode":"// before calling grid_sample_2d\nmatch tensor.dtype() {\n    DType::F32 | DType::F64 | DType::F16 | DType::BF16 => {},\n    other => tensor = tensor.cast::<f32>(), // or reject\n}","typeGuard":"fn is_float_dtype(d: DType) -> bool {\n    matches!(d, DType::F32 | DType::F64 | DType::F16 | DType::BF16)\n}","tryCatchPattern":null,"preventionTips":["Cast image tensors to f32 (and normalize) before grid sampling","Insert dtype assertions at pipeline boundaries to catch accidental int casts early"],"tags":["panic","dtype-mismatch","grid-sample","rust"],"backgroundTag":"unsupported-dtype","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"}