tracel-ai/burn · error
deform_conv2d_backward: unsupported dtype {:?}
Error message
deform_conv2d_backward: unsupported dtype {:?} What it means
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.
Source
Thrown at crates/burn-flex/src/ops/module.rs:243
cast_to_f32(weight, to),
mask.map(|m| cast_to_f32(m, to)),
bias.map(|b| cast_to_f32(b, to)),
cast_to_f32(output_grad, to),
options.stride,
options.padding,
options.dilation,
options.weight_groups,
options.offset_groups,
);
(
cast_from_f32(xg, from),
cast_from_f32(og, from),
cast_from_f32(wg, from),
mg.map(|m| cast_from_f32(m, from)),
bg.map(|b| cast_from_f32(b, from)),
)
}
dtype => panic!("deform_conv2d_backward: unsupported dtype {:?}", dtype),
};
DeformConv2dBackward::new(x_grad, offset_grad, weight_grad, mask_grad, bias_grad)
}
fn conv3d(
x: FloatTensor<Flex>,
weight: FloatTensor<Flex>,
bias: Option<FloatTensor<Flex>>,
options: ConvOptions<3>,
) -> FloatTensor<Flex> {
match x.dtype() {
DType::F32 => conv::conv3d_f32(x, weight, bias, &options),
DType::F64 => conv::conv3d_f64(x, weight, bias, &options),
DType::F16 => conv::conv3d_f16(x, weight, bias, &options),
DType::BF16 => conv::conv3d_bf16(x, weight, bias, &options),
dtype => panic!("conv3d: unsupported dtype {:?}", dtype),
}
}View on GitHub (pinned to d16f7ba2ed)
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.
Example fix
// before let grads = loss.backward(); // x saved as I8 by earlier quantize op // panic: deform_conv2d_backward: unsupported dtype I8 // after let x = quantized_x.dequantize().cast(burn::tensor::DType::F32); let out = deform_conv2d(x, offset, mask, weight, bias, options); let grads = loss.backward();
Defensive patterns
Strategy: validation
Validate before calling
// before backward, ensure forward inputs were float
assert!(matches!(x_saved.dtype(), DType::F32 | DType::F64 | DType::F16 | DType::BF16),
"saved input for deform_conv2d_backward must be float, got {:?}", x_saved.dtype()); Type guard
fn backward_safe(t: &Tensor<Flex>) -> bool {
matches!(t.dtype(), DType::F32 | DType::F64 | DType::F16 | DType::BF16)
} Try / catch
let grads = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| loss.backward()))
.unwrap_or_else(|_| { // recast saved tensors to f32 and rerun
let x = x_saved.cast(DType::F32);
deform_conv2d(x, offset, mask, w, b, opts); /* rebuild graph */ loss.backward()
}); Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- conv1d: unsupported dtype {:?}
- conv2d: unsupported dtype {:?}
- deform_conv2d: unsupported dtype {:?}
- conv3d: unsupported dtype {:?}
- adaptive_avg_pool2d_backward: unsupported dtype {:?}
AI-assisted analysis of tracel-ai/burn@d16f7ba2ed (2026-09-05).
Data as JSON: /api/errors/d59d5538758c7e08.
Report an issue: GitHub.