{"record":{"id":"851064992d6920a9","repo":"tracel-ai/burn","slug":"deform-conv2d-unsupported-dtype","errorCode":null,"errorMessage":"deform_conv2d: unsupported dtype {:?}","messagePattern":"deform_conv2d: unsupported dtype (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-flex/src/ops/module.rs","lineNumber":143,"sourceCode":"                cast_from_f32(result, f16::from_f32)\n            }\n            DType::BF16 => {\n                use burn_std::bf16;\n                let result = deform_conv::deform_conv2d_f32(\n                    cast_to_f32(x, bf16::to_f32),\n                    cast_to_f32(offset, bf16::to_f32),\n                    cast_to_f32(weight, bf16::to_f32),\n                    mask.map(|m| cast_to_f32(m, bf16::to_f32)),\n                    bias.map(|b| cast_to_f32(b, bf16::to_f32)),\n                    options.stride,\n                    options.padding,\n                    options.dilation,\n                    options.weight_groups,\n                    options.offset_groups,\n                );\n                cast_from_f32(result, bf16::from_f32)\n            }\n            dtype => panic!(\"deform_conv2d: unsupported dtype {:?}\", dtype),\n        }\n    }\n\n    fn deform_conv2d_backward(\n        x: FloatTensor<Flex>,\n        offset: FloatTensor<Flex>,\n        weight: FloatTensor<Flex>,\n        mask: Option<FloatTensor<Flex>>,\n        bias: Option<FloatTensor<Flex>>,\n        output_grad: FloatTensor<Flex>,\n        options: DeformConvOptions<2>,\n    ) -> DeformConv2dBackward<Flex> {\n        let (x_grad, offset_grad, weight_grad, mask_grad, bias_grad) = match x.dtype() {\n            DType::F32 => deform_conv::deform_conv2d_backward_f32(\n                x,\n                offset,\n                weight,\n                mask,","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-flex/src/ops/module.rs#L125-L161","documentation":"deform_conv2d in the burn-flex backend computes by casting the inputs to f32, running the f32 deformable-convolution, then casting back to the original float dtype. The dispatch only recognizes F32/F64/F16/BF16; any other dtype panics. Because the op round-trips through f32, integer dtypes were never considered valid inputs.","triggerScenarios":"Calling deform_conv2d with x, offset, or mask tensors whose dtype is not one of F32/F64/F16/BF16 (e.g. I32 offset grid, U8 mask); feeding integer coordinate tensors as the offset input.","commonSituations":"Building deformable attention/conv modules (e.g. DCN, Deformable DETR) where the sampling grid offsets are kept as integers; converting an ONNX deform-conv graph whose offset outputs are int; exporting pipelines that change dtypes silently.","solutions":["Cast every input (x, offset, mask) to a float dtype before deform_conv2d, e.g. offset.cast(DType::F32).","Verify each tensor's dtype with .dtype(); usually only one of the inputs (often offset/mask) is the culprit.","Insert a .float()/cast step right after the subnetwork that produces the offsets so the grid stays float end-to-end.","If integer offsets are by design, convert them in the model definition (e.g. grid_sample-style offsets computed in f32)."],"exampleFix":"// before\nlet out = deform_conv2d(x, int_offset, mask, weight, bias, options);\n// panic: deform_conv2d: unsupported dtype I32\n\n// after\nlet offset = int_offset.cast(burn::tensor::DType::F32);\nlet out = deform_conv2d(x, offset, mask, weight, bias, options);","handlingStrategy":"validation","validationCode":"for t in [&x, &offset, &mask] {\n    assert!(matches!(t.dtype(), DType::F32 | DType::F64 | DType::F16 | DType::BF16), \"deform_conv2d needs float inputs, got {:?}\", t.dtype());\n}\nlet out = deform_conv2d(x, offset, mask, weight, bias, options);","typeGuard":"fn all_float(dtypes: [DType; 3]) -> bool {\n    dtypes.iter().all(|d| matches!(d, DType::F32 | DType::F64 | DType::F16 | DType::BF16))\n}","tryCatchPattern":"let out = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| deform_conv2d(x.clone(), offset.clone(), mask.clone(), w.clone(), b.clone(), opts.clone())))\n    .unwrap_or_else(|_| deform_conv2d(x.cast(DType::F32), offset.cast(DType::F32), mask.cast(DType::F32), w, b, opts));","preventionTips":["Cast offset/mask subnetwork outputs to f32 immediately after production.","Remember deform_conv2d internally uses f32: keeping offsets float avoids surprises.","Check all three inputs (x, offset, mask) — often only one is the wrong dtype.","Test deform modules with a tiny float and a tiny int tensor to lock down behavior."],"tags":["burn","dtype","panic","conv","deformable"],"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"}