{"record":{"id":"d59d5538758c7e08","repo":"tracel-ai/burn","slug":"deform-conv2d-backward-unsupported-dtype","errorCode":null,"errorMessage":"deform_conv2d_backward: unsupported dtype {:?}","messagePattern":"deform_conv2d_backward: unsupported dtype (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-flex/src/ops/module.rs","lineNumber":243,"sourceCode":"                    cast_to_f32(weight, to),\n                    mask.map(|m| cast_to_f32(m, to)),\n                    bias.map(|b| cast_to_f32(b, to)),\n                    cast_to_f32(output_grad, to),\n                    options.stride,\n                    options.padding,\n                    options.dilation,\n                    options.weight_groups,\n                    options.offset_groups,\n                );\n                (\n                    cast_from_f32(xg, from),\n                    cast_from_f32(og, from),\n                    cast_from_f32(wg, from),\n                    mg.map(|m| cast_from_f32(m, from)),\n                    bg.map(|b| cast_from_f32(b, from)),\n                )\n            }\n            dtype => panic!(\"deform_conv2d_backward: unsupported dtype {:?}\", dtype),\n        };\n        DeformConv2dBackward::new(x_grad, offset_grad, weight_grad, mask_grad, bias_grad)\n    }\n\n    fn conv3d(\n        x: FloatTensor<Flex>,\n        weight: FloatTensor<Flex>,\n        bias: Option<FloatTensor<Flex>>,\n        options: ConvOptions<3>,\n    ) -> FloatTensor<Flex> {\n        match x.dtype() {\n            DType::F32 => conv::conv3d_f32(x, weight, bias, &options),\n            DType::F64 => conv::conv3d_f64(x, weight, bias, &options),\n            DType::F16 => conv::conv3d_f16(x, weight, bias, &options),\n            DType::BF16 => conv::conv3d_bf16(x, weight, bias, &options),\n            dtype => panic!(\"conv3d: unsupported dtype {:?}\", dtype),\n        }\n    }","sourceCodeStart":225,"sourceCodeEnd":261,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-flex/src/ops/module.rs#L225-L261","documentation":"deform_conv2d_backward mirrors the forward deform_conv2d dispatch: it matches the input dtype, casts tensors to f32 to run the f32 backward kernels, then casts gradients back with cast_from_f32. Unrecognized dtypes hit the catch-all panic. It fires during backward passes, so it typically surfaces inside .backward()/training loops rather than at the original call site.","triggerScenarios":"Running backward on a deform_conv2d node where the saved input/weight tensors carry a dtype other than F32/F64/F16/BF16 (e.g. an int dtype from a quantized or mis-cast forward); dtype of x changed between forward and backward.","commonSituations":"Training Deformable DETR / DCN models with a mixed-precision or quantization setup that downcasts activations to integers; a custom autograd graph where casts between forward and backward changed the recorded dtype.","solutions":["Ensure the forward deform_conv2d inputs are float (F32/F16/BF16) so the saved tensors used in backward keep a supported dtype.","Audit any cast/quantize ops between the forward call and backward() that could convert saved tensors to integers.","Reproduce by checking dtype of x_grad inputs in a minimal test: run forward, print .dtype(), then backward.","If a non-float dtype must be supported, extend the match arms in crates/burn-flex/src/ops/module.rs deform_conv2d_backward."],"exampleFix":"// before\nlet grads = loss.backward(); // x saved as I8 by earlier quantize op\n// panic: deform_conv2d_backward: unsupported dtype I8\n\n// after\nlet x = quantized_x.dequantize().cast(burn::tensor::DType::F32);\nlet out = deform_conv2d(x, offset, mask, weight, bias, options);\nlet grads = loss.backward();","handlingStrategy":"validation","validationCode":"// before backward, ensure forward inputs were float\nassert!(matches!(x_saved.dtype(), DType::F32 | DType::F64 | DType::F16 | DType::BF16),\n        \"saved input for deform_conv2d_backward must be float, got {:?}\", x_saved.dtype());","typeGuard":"fn backward_safe(t: &Tensor<Flex>) -> bool {\n    matches!(t.dtype(), DType::F32 | DType::F64 | DType::F16 | DType::BF16)\n}","tryCatchPattern":"let grads = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| loss.backward()))\n    .unwrap_or_else(|_| { // recast saved tensors to f32 and rerun\n        let x = x_saved.cast(DType::F32);\n        deform_conv2d(x, offset, mask, w, b, opts); /* rebuild graph */ loss.backward()\n    });","preventionTips":["Never place quantize/cast-to-int ops between deform_conv2d forward and backward().","Keep saved-for-backward tensors in their original float dtype through the graph.","Run a forward+backward smoke test after any mixed-precision change.","Audit quantization hooks to ensure they only wrap leaf ops, not deform conv nodes."],"tags":["burn","dtype","panic","conv","backward"],"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"}