{"record":{"id":"5bc4c6320a644d90","repo":"tracel-ai/burn","slug":"avg-pool2d-backward-unsupported-dtype","errorCode":null,"errorMessage":"avg_pool2d_backward: unsupported dtype {:?}","messagePattern":"avg_pool2d_backward: unsupported dtype (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-flex/src/ops/module.rs","lineNumber":395,"sourceCode":"                count_include_pad,\n            ),\n            DType::F16 => pool::avg_pool2d_backward_f16(\n                x,\n                grad,\n                kernel_size,\n                stride,\n                padding,\n                count_include_pad,\n            ),\n            DType::BF16 => pool::avg_pool2d_backward_bf16(\n                x,\n                grad,\n                kernel_size,\n                stride,\n                padding,\n                count_include_pad,\n            ),\n            dtype => panic!(\"avg_pool2d_backward: unsupported dtype {:?}\", dtype),\n        }\n    }\n\n    fn adaptive_avg_pool2d(x: FloatTensor<Flex>, output_size: [usize; 2]) -> FloatTensor<Flex> {\n        match x.dtype() {\n            DType::F32 => pool::adaptive_avg_pool2d_f32(x, output_size),\n            DType::F64 => pool::adaptive_avg_pool2d_f64(x, output_size),\n            DType::F16 => pool::adaptive_avg_pool2d_f16(x, output_size),\n            DType::BF16 => pool::adaptive_avg_pool2d_bf16(x, output_size),\n            dtype => panic!(\"adaptive_avg_pool2d: unsupported dtype {:?}\", dtype),\n        }\n    }\n\n    fn adaptive_avg_pool2d_backward(\n        x: FloatTensor<Flex>,\n        grad: FloatTensor<Flex>,\n    ) -> FloatTensor<Flex> {\n        match x.dtype() {","sourceCodeStart":377,"sourceCodeEnd":413,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-flex/src/ops/module.rs#L377-L413","documentation":"The burn-flex backend's avg_pool2d_backward dispatches on the gradient tensor's dtype and only implements F32, F64, F16 and BF16. If the tensor carries any other dtype (e.g. an integer or bool dtype that ended up in a float slot), the catch-all match arm panics with this message. It is an exhaustive-dispatch guard, not a recoverable error.","triggerScenarios":"Calling the Burn Tensor API's avg_pool2d backward (e.g. training through AvgPool2d) on the Flex backend with a tensor whose dtype is not one of F32/F64/F16/BF16 — typically after an int_cast or a model that produced integer tensors feeding the pooling layer.","commonSituations":"Integer/quantized tensors passed where floats are expected; a dtype mismatch after loading weights or checkpoints saved with a different dtype; mixing backends where an Int tensor is accidentally fed into a float op.","solutions":["Check tensor.dtype() before the pooling backward call and cast to a supported float dtype with tensor.cast(DType::F32) (or .float()).","Fix the source of the wrong dtype upstream (e.g. an int_cast, integer input pipeline, or loaded checkpoint) so float tensors reach AvgPool2d.","If you need another float dtype implemented, add a match arm calling pool::avg_pool2d_backward_<dtype> in crates/burn-flex/src/ops/module.rs."],"exampleFix":"// before\nlet grad = grad_int; // DType::I32\nlet x_grad = avg_pool2d_backward(x, grad, ...); // panics\n// after\nlet grad = grad_int.cast(DType::F32);\nlet x_grad = avg_pool2d_backward(x, grad, ...);","handlingStrategy":"validation","validationCode":"assert!(matches!(grad.dtype(), burn::tensor::DType::F32 | burn::tensor::DType::F64 | burn::tensor::DType::F16 | burn::tensor::DType::BF16), \"avg_pool2d_backward needs a float tensor, got {:?}\", grad.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":"// Panics are not catchable in Rust; validate dtype first:\nlet grad = if is_float_dtype(grad.dtype()) { grad } else { grad.cast(burn::tensor::DType::F32) };","preventionTips":["Always call .float() (or cast to F32) on tensors coming from data loaders before feeding pooling layers.","Check tensor.dtype() at model boundaries and assert float dtypes in debug builds.","Keep checkpoint dtype and model dtype configuration consistent."],"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"}