{"record":{"id":"cb779269a8f07baf","repo":"tracel-ai/burn","slug":"max-pool2d-unsupported-dtype","errorCode":null,"errorMessage":"max_pool2d: unsupported dtype {:?}","messagePattern":"max_pool2d: unsupported dtype (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-flex/src/ops/module.rs","lineNumber":472,"sourceCode":"        stride: [usize; 2],\n        padding: [usize; 2],\n        dilation: [usize; 2],\n        ceil_mode: bool,\n    ) -> FloatTensor<Flex> {\n        match x.dtype() {\n            DType::F32 => {\n                pool::max_pool2d_f32(x, kernel_size, stride, padding, dilation, ceil_mode)\n            }\n            DType::F64 => {\n                pool::max_pool2d_f64(x, kernel_size, stride, padding, dilation, ceil_mode)\n            }\n            DType::F16 => {\n                pool::max_pool2d_f16(x, kernel_size, stride, padding, dilation, ceil_mode)\n            }\n            DType::BF16 => {\n                pool::max_pool2d_bf16(x, kernel_size, stride, padding, dilation, ceil_mode)\n            }\n            dtype => panic!(\"max_pool2d: unsupported dtype {:?}\", dtype),\n        }\n    }\n\n    fn max_pool2d_with_indices(\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        indices_dtype: IntDType,\n    ) -> MaxPool2dWithIndices<Flex> {\n        let (output, mut indices) = match x.dtype() {\n            DType::F32 => pool::max_pool2d_with_indices_f32(\n                x,\n                kernel_size,\n                stride,\n                padding,","sourceCodeStart":454,"sourceCodeEnd":490,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-flex/src/ops/module.rs#L454-L490","documentation":"max_pool2d in the burn-flex backend dispatches on the input dtype and implements only F32, F64, F16 and BF16 variants. Any other dtype reaches the catch-all arm and panics. It is a fail-fast guard ensuring pooling kernels never receive non-float data.","triggerScenarios":"Calling Tensor::max_pool2d on the Flex backend with a tensor whose dtype is not one of F32/F64/F16/BF16, e.g. an Int tensor.","commonSituations":"Feeding integer feature maps (e.g. from a quantized or index-based stage) into MaxPool2d; forgetting .float() after an image pipeline; dtype changes when switching backends or loading checkpoints.","solutions":["Cast the input to a supported float dtype before pooling: x.cast(DType::F32).","Fix the upstream producer of the tensor so float dtype is guaranteed.","Add a match arm for the needed dtype calling pool::max_pool2d_<dtype> in crates/burn-flex/src/ops/module.rs."],"exampleFix":"// before\nlet pooled = feats_i32.max_pool2d([2, 2], [2, 2], [0, 0], [1, 1], false); // panics\n// after\nlet pooled = feats_i32.cast(DType::F32).max_pool2d([2, 2], [2, 2], [0, 0], [1, 1], false);","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 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":"// Normalize dtype before pooling:\nlet x = if is_float_dtype(x.dtype()) { x } else { x.cast(burn::tensor::DType::F32) };\nlet pooled = x.max_pool2d([2, 2], [2, 2], [0, 0], [1, 1], false);","preventionTips":["Apply .float() to feature maps entering MaxPool2d.","Verify dtype after loading checkpoints or switching backends.","Write a smoke test that runs one forward/backward pass per pooling layer."],"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"}