{"record":{"id":"b197977b7d28895d","repo":"tracel-ai/burn","slug":"max-pool2d-with-indices-backward-unsupported-dtyp","errorCode":null,"errorMessage":"max_pool2d_with_indices_backward: unsupported dtype {:?}","messagePattern":"max_pool2d_with_indices_backward: unsupported dtype (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-flex/src/ops/module.rs","lineNumber":541,"sourceCode":"        MaxPool2dWithIndices::new(output, indices)\n    }\n\n    fn max_pool2d_with_indices_backward(\n        x: FloatTensor<Flex>,\n        _kernel_size: [usize; 2],\n        _stride: [usize; 2],\n        _padding: [usize; 2],\n        _dilation: [usize; 2],\n        _ceil_mode: bool,\n        output_grad: FloatTensor<Flex>,\n        indices: IntTensor<Flex>,\n    ) -> MaxPool2dBackward<Flex> {\n        let x_grad = match x.dtype() {\n            DType::F32 => pool::max_pool2d_backward_f32(x, output_grad, indices),\n            DType::F64 => pool::max_pool2d_backward_f64(x, output_grad, indices),\n            DType::F16 => pool::max_pool2d_backward_f16(x, output_grad, indices),\n            DType::BF16 => pool::max_pool2d_backward_bf16(x, output_grad, indices),\n            dtype => panic!(\n                \"max_pool2d_with_indices_backward: unsupported dtype {:?}\",\n                dtype\n            ),\n        };\n        MaxPool2dBackward::new(x_grad)\n    }\n\n    fn interpolate(\n        x: FloatTensor<Flex>,\n        output_size: [usize; 2],\n        options: InterpolateOptions,\n    ) -> FloatTensor<Flex> {\n        match (options.mode, x.dtype()) {\n            (InterpolateMode::Nearest, DType::F32) => {\n                interpolate::interpolate_nearest_f32(x, output_size, options.align_corners)\n            }\n            (InterpolateMode::Nearest, DType::F64) => {\n                interpolate::interpolate_nearest_f64(x, output_size, options.align_corners)","sourceCodeStart":523,"sourceCodeEnd":559,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-flex/src/ops/module.rs#L523-L559","documentation":"max_pool2d_with_indices_backward computes the input gradient by dispatching on x.dtype(), supporting only F32, F64, F16 and BF16. Any other dtype reaches the catch-all arm and panics. This guards the backward pass of max pooling with indices on the Flex backend.","triggerScenarios":"Backpropagating through MaxPool2d (with indices) on the Flex backend when the saved input x has a dtype other than F32/F64/F16/BF16.","commonSituations":"Training where an integer tensor entered max pooling; precision mismatch between forward-saved tensors and backward expectations; pipeline bugs feeding Int data into vision models.","solutions":["Cast x/output_grad/indices appropriately so x is a supported float dtype before backward.","Ensure the forward pass only receives float tensors so the saved state is float.","Add a match arm calling pool::max_pool2d_backward_<dtype> in crates/burn-flex/src/ops/module.rs if a new dtype is needed."],"exampleFix":"// before\nlet dx = max_pool2d_with_indices_backward::<F32>(x_int, grad, idx); // panics\n// after\nlet dx = max_pool2d_with_indices_backward::<F32>(x_int.cast(DType::F32), grad, idx);","handlingStrategy":"validation","validationCode":"assert!(matches!(x.dtype(), burn::tensor::DType::F32 | burn::tensor::DType::F64 | burn::tensor::DType::F16 | burn::tensor::DType::BF16), \"max_pool2d_with_indices_backward needs a float tensor, got {:?}\", x.dtype());","typeGuard":"fn is_float_dtype(d: burn::tensor::DType) -> bool {\n    matches!(d, burn::tensor::DType::F32 | burn::tensor::DType::F64 | burn::tensor::DType::F16 | burn::tensor::DType::BF16)\n}","tryCatchPattern":"// Ensure float input before backward:\nlet x = if is_float_dtype(x.dtype()) { x } else { x.cast(burn::tensor::DType::F32) };","preventionTips":["Confirm saved max-pool inputs are float before calling backward.","Match precision settings between training config and checkpoint.","Run a full forward/backward smoke test after backend or dtype changes."],"tags":["rust","dtype","panic","pooling","backward","burn"],"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"}