tracel-ai/burn · critical

Torch bindings don't support deform_conv2d

Error message

Torch bindings don't support deform_conv2d

What it means

The LibTorch backend in burn-tch does not implement deformable convolution: deform_conv2d is a hard stub that panics with unimplemented!(), because the underlying tch (C++ LibTorch) bindings do not expose deform_conv2d. Calling it on a LibTorch tensor always panics regardless of inputs.

Source

Thrown at crates/burn-tch/src/ops/module.rs:131

            bias.map(|t| t.tensor),
            options.stride.map(|i| i as i64),
            options.padding_begin().map(|i| i as i64),
            options.dilation.map(|i| i as i64),
            options.groups as i64,
        );

        TchTensor::new(tensor)
    }

    fn deform_conv2d(
        _x: TchTensor,
        _offset: TchTensor,
        _weight: TchTensor,
        _mask: Option<TchTensor>,
        _bias: Option<TchTensor>,
        _options: DeformConvOptions<2>,
    ) -> TchTensor {
        unimplemented!("Torch bindings don't support deform_conv2d");
    }

    fn deform_conv2d_backward(
        _x: TchTensor,
        _offset: TchTensor,
        _weight: TchTensor,
        _mask: Option<TchTensor>,
        _bias: Option<TchTensor>,
        _out_grad: TchTensor,
        _options: DeformConvOptions<2>,
    ) -> DeformConv2dBackward<Self> {
        unimplemented!("Torch bindings don't support deform_conv2d");
    }

    fn conv_transpose1d(
        x: TchTensor,
        weight: TchTensor,
        bias: Option<TchTensor>,

View on GitHub (pinned to d16f7ba2ed)

Solutions

  1. Use a backend that implements deform_conv2d (e.g. burn-cubecl/wgpu or NdArray as available) for this model
  2. Replace deform_conv2d with a standard conv2d (losing deformability) or implement the op manually from primitive ops
  3. Implement deform_conv2d via a custom op/torch extension (torchvision) and register it
  4. File/vote on a burn issue to add deform_conv2d support to the tch backend

Example fix

// before
let out = x.deform_conv2d(offset, weight, mask, bias, options); // panics on LibTorch

// after
// run on a backend with support:
let out = x_cuda.deform_conv2d(offset, weight, mask, bias, options); // burn-cubecl backend
Defensive patterns

Strategy: fallback

Validate before calling

// compile-time/backend check before building the model
fn supports_deform_conv<B: Backend>() -> bool {
    // LibTorch (tch) does not implement deform_conv2d
    !(std::any::type_name::<B>().contains("LibTorch") || std::any::type_name::<B>().contains("Tch"))
}

Try / catch

let out = std::panic::catch_unwind(|| {
    x.clone().deform_conv2d(offset.clone(), weight.clone(), mask.clone(), bias.clone(), options.clone())
}).unwrap_or_else(|_| x.deform_conv2d_fallback(offset, weight, mask, bias, options));

Prevention

When it happens

Trigger: Calling Tensor::deform_conv2d (or a model layer that uses it, e.g. DCN/DCNv2-style modules) on a tensor using the LibTorch (tch) backend.

Common situations: Running deformable-convolution vision models (DCN for detection/segmentation) on the burn-tch backend; switching a model from burn-candle/wgpu (where it may exist) to LibTorch; trying to leverage torch through burn for DCN ops that require custom extensions like torchvision's deform_conv2d.

Related errors


AI-assisted analysis of tracel-ai/burn@d16f7ba2ed (2026-09-05). Data as JSON: /api/errors/4f80e587b5aa6366. Report an issue: GitHub.