{"record":{"id":"72216054632b4bd3","repo":"tracel-ai/burn","slug":"conv2d-unsupported-dtype","errorCode":null,"errorMessage":"conv2d: unsupported dtype {:?}","messagePattern":"conv2d: unsupported dtype (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-flex/src/ops/module.rs","lineNumber":74,"sourceCode":"            DType::F16 => conv::conv1d_f16(x, weight, bias, &options),\n            DType::BF16 => conv::conv1d_bf16(x, weight, bias, &options),\n            dtype => panic!(\"conv1d: unsupported dtype {:?}\", dtype),\n        }\n    }\n\n    fn conv2d(\n        x: FloatTensor<Flex>,\n        weight: FloatTensor<Flex>,\n        bias: Option<FloatTensor<Flex>>,\n        options: ConvOptions<2>,\n    ) -> FloatTensor<Flex> {\n        let (x, options) = pad_asymmetric_conv_input::<Flex, 2>(x, options);\n        match x.dtype() {\n            DType::F32 => conv::conv2d_f32(x, weight, bias, &options),\n            DType::F64 => conv::conv2d_f64(x, weight, bias, &options),\n            DType::F16 => conv::conv2d_f16(x, weight, bias, &options),\n            DType::BF16 => conv::conv2d_bf16(x, weight, bias, &options),\n            dtype => panic!(\"conv2d: unsupported dtype {:?}\", dtype),\n        }\n    }\n\n    fn deform_conv2d(\n        x: FloatTensor<Flex>,\n        offset: FloatTensor<Flex>,\n        weight: FloatTensor<Flex>,\n        mask: Option<FloatTensor<Flex>>,\n        bias: Option<FloatTensor<Flex>>,\n        options: DeformConvOptions<2>,\n    ) -> FloatTensor<Flex> {\n        match x.dtype() {\n            DType::F32 => deform_conv::deform_conv2d_f32(\n                x,\n                offset,\n                weight,\n                mask,\n                bias,","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-flex/src/ops/module.rs#L56-L92","documentation":"conv2d in the burn-flex module ops matches the input dtype against F32/F64/F16/BF16 and delegates to the corresponding typed conv kernel; any other dtype hits the catch-all panic. Conv2d requires float tensors, so integer or bool input tensors are rejected at runtime rather than at compile time, since Flex is a dynamic-dtype backend.","triggerScenarios":"Calling conv2d (directly or via a conv2d module) with an input tensor whose dtype is I8/I16/I32/I64/U8/Bool/etc.; passing quantized int8 activations into conv2d without dequantization.","commonSituations":"Running an int8-quantized vision model where the quantized conv node was not mapped to a dequantize-conv-requantize flow; preprocessing images as u8 tensors fed straight into the model; checkpoint dtype mismatches after format conversion.","solutions":["Cast the image/input tensor to a float dtype before conv2d: x.cast(DType::F32).","Check the dtype of both input and weight with .dtype() to locate which tensor is non-float.","For quantized inference, explicitly dequantize int8 activations/weights to f32 or bf16 before the conv.","If support for another dtype is genuinely needed, add the corresponding arm (e.g. conv2d_i8) in crates/burn-flex/src/ops/module.rs."],"exampleFix":"// before\nlet out = model.conv2(image_u8_tensor);\n// panic: conv2d: unsupported dtype U8\n\n// after\nlet x = image_u8_tensor.cast(burn::tensor::DType::F32);\nlet out = model.conv2(x);","handlingStrategy":"validation","validationCode":"let x = if matches!(x.dtype(), DType::F32 | DType::F64 | DType::F16 | DType::BF16) { x } else { x.cast(DType::F32) };\nlet out = conv2d(x, weight, bias, options);","typeGuard":"fn is_float(t: &Tensor<Flex>) -> bool {\n    matches!(t.dtype(), DType::F32 | DType::F64 | DType::F16 | DType::BF16)\n}","tryCatchPattern":"let out = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| conv2d(x.clone(), w.clone(), b.clone(), opts.clone())))\n    .unwrap_or_else(|_| conv2d(x.cast(DType::F32), w, b, opts));","preventionTips":["Cast image tensors from u8 to f32 (with normalization) right after loading.","Dequantize int8 activations before conv2d in quantized pipelines.","Verify checkpoint dtypes at load time and normalize to f32/bf16.","Add dtype assertions in conv module forward() during development."],"tags":["burn","dtype","panic","conv","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"}