{"record":{"id":"d9d668898b79274b","repo":"tracel-ai/burn","slug":"max-pool2d-with-indices-unsupported-dtype","errorCode":null,"errorMessage":"max_pool2d_with_indices: unsupported dtype {:?}","messagePattern":"max_pool2d_with_indices: unsupported dtype (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-flex/src/ops/module.rs","lineNumber":518,"sourceCode":"                ceil_mode,\n            ),\n            DType::F16 => pool::max_pool2d_with_indices_f16(\n                x,\n                kernel_size,\n                stride,\n                padding,\n                dilation,\n                ceil_mode,\n            ),\n            DType::BF16 => pool::max_pool2d_with_indices_bf16(\n                x,\n                kernel_size,\n                stride,\n                padding,\n                dilation,\n                ceil_mode,\n            ),\n            dtype => panic!(\"max_pool2d_with_indices: unsupported dtype {:?}\", dtype),\n        };\n        if indices.dtype() != DType::from(indices_dtype) {\n            indices = Flex::int_cast(indices, indices_dtype);\n        }\n        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() {","sourceCodeStart":500,"sourceCodeEnd":536,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-flex/src/ops/module.rs#L500-L536","documentation":"max_pool2d_with_indices dispatches on the input tensor's dtype across F32/F64/F16/BF16 only. Any other dtype hits the catch-all match arm and panics before the op returns output and index tensors. This is the indices-returning variant of max pooling on the Flex backend.","triggerScenarios":"Calling Tensor::max_pool2d_with_indices on the Flex backend with a non-float (non F32/F64/F16/BF16) input tensor.","commonSituations":"Integer tensors from preprocessing entering max-pool-with-indices layers; dtype drift after model load or backend switch; mixing Int and Float tensors in a vision model.","solutions":["Cast the input to a supported float dtype, e.g. x.cast(DType::F32), before the call.","Fix the dtype at the tensor's origin so pooling always receives floats.","Add the missing dtype arm (pool::max_pool2d_with_indices_<dtype>) in crates/burn-flex/src/ops/module.rs."],"exampleFix":"// before\nlet (out, idx) = x_int.max_pool2d_with_indices([2, 2], [2, 2], [0, 0], [1, 1]); // panics\n// after\nlet (out, idx) = x_int.cast(DType::F32).max_pool2d_with_indices([2, 2], [2, 2], [0, 0], [1, 1]);","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 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":"// Cast before the indices-returning pool op:\nlet x = if is_float_dtype(x.dtype()) { x } else { x.cast(burn::tensor::DType::F32) };\nlet (out, idx) = x.max_pool2d_with_indices([2, 2], [2, 2], [0, 0], [1, 1]);","preventionTips":["Ensure upstream layers output float tensors before max-pool-with-indices.","Keep integer tensors (indices, labels) out of float compute paths.","Assert float dtype in model construction and integration tests."],"tags":["rust","dtype","panic","pooling","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"}