{"record":{"id":"d330dd89647435a9","repo":"tracel-ai/burn","slug":"avg-pool2d-unsupported-dtype","errorCode":null,"errorMessage":"avg_pool2d: unsupported dtype {:?}","messagePattern":"avg_pool2d: unsupported dtype (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-flex/src/ops/module.rs","lineNumber":349,"sourceCode":"                ceil_mode,\n            ),\n            DType::F16 => pool::avg_pool2d_f16(\n                x,\n                kernel_size,\n                stride,\n                padding,\n                count_include_pad,\n                ceil_mode,\n            ),\n            DType::BF16 => pool::avg_pool2d_bf16(\n                x,\n                kernel_size,\n                stride,\n                padding,\n                count_include_pad,\n                ceil_mode,\n            ),\n            dtype => panic!(\"avg_pool2d: unsupported dtype {:?}\", dtype),\n        }\n    }\n\n    fn avg_pool2d_backward(\n        x: FloatTensor<Flex>,\n        grad: FloatTensor<Flex>,\n        kernel_size: [usize; 2],\n        stride: [usize; 2],\n        padding: [usize; 2],\n        count_include_pad: bool,\n        _divisor_override: bool,\n    ) -> FloatTensor<Flex> {\n        match x.dtype() {\n            DType::F32 => pool::avg_pool2d_backward_f32(\n                x,\n                grad,\n                kernel_size,\n                stride,","sourceCodeStart":331,"sourceCodeEnd":367,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-flex/src/ops/module.rs#L331-L367","documentation":"avg_pool2d in the burn-flex module ops matches the input dtype (F32/F64/F16/BF16 supported) and delegates to the corresponding typed pooling kernel; any other dtype panics. Pooling ops operate on float activations, so an integer or bool tensor reaching avg_pool2d is a dtype-flow bug in the calling model.","triggerScenarios":"Calling avg_pool2d (or an AvgPool2d module forward) with a non-float input tensor; pooling over quantized int8 feature maps without dequantization; passing integer label/mask tensors through a pooling stage.","commonSituations":"Classification heads pooling int-quantized backbone outputs; pipelines where a cast to integer (e.g. round/clip helper) was inserted before the pool; exported graphs with dtype changes around pooling.","solutions":["Cast the input to a float dtype before avg_pool2d: x.cast(DType::F32).","Check .dtype() on the tensor entering the pool to identify which upstream op changed it to a non-float type.","Move any quantization/dequantization boundary so activations stay float through the pooling stage.","Add a new dtype arm in crates/burn-flex/src/ops/module.rs avg_pool2d if support is genuinely needed."],"exampleFix":"// before\nlet pooled = avg_pool2d(features_i8, [2, 2], [2, 2], [0, 0], true, false);\n// panic: avg_pool2d: unsupported dtype I8\n\n// after\nlet x = features_i8.cast(burn::tensor::DType::F32);\nlet pooled = avg_pool2d(x, [2, 2], [2, 2], [0, 0], true, false);","handlingStrategy":"validation","validationCode":"let x = if matches!(x.dtype(), DType::F32 | DType::F64 | DType::F16 | DType::BF16) { x } else { x.cast(DType::F32) };\nlet pooled = avg_pool2d(x, kernel_size, stride, padding, count_include_pad, ceil_mode);","typeGuard":"fn is_float(t: &Tensor<Flex>) -> bool {\n    matches!(t.dtype(), DType::F32 | DType::F64 | DType::F16 | DType::BF16)\n}","tryCatchPattern":"let pooled = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| avg_pool2d(x.clone(), ks, st, pd, cip, cm)))\n    .unwrap_or_else(|_| avg_pool2d(x.cast(DType::F32), ks, st, pd, cip, cm));","preventionTips":["Keep activations float through pooling stages; place quantize boundaries elsewhere.","Find any round/clip-to-int helpers inserted before pooling and remove or move them.","Assert backbone output dtype before the classification head's pooling.","Check exported graph dtype changes around pool nodes after conversions."],"tags":["burn","dtype","panic","pooling","backend"],"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"}