tracel-ai/burn · error

Can't differentiate interpolate backward.

Error message

Can't differentiate interpolate backward.

What it means

interpolate_backward in the autodiff backend panics: gradients through the interpolate (resize) op are not implemented. The forward resize works, but a training step that backpropagates through it hits this panic.

Source

Thrown at crates/burn-autodiff/src/ops/module.rs:1933

        {
            OpsKind::Tracked(mut prep) => {
                let x_state = prep.checkpoint(&x);
                let output = B::interpolate(x.primitive.clone(), output_size, options.clone());
                prep.finish((x_state, output_size, options), output)
            }
            OpsKind::UnTracked(prep) => {
                prep.finish(B::interpolate(x.primitive, output_size, options))
            }
        }
    }

    fn interpolate_backward(
        _x: FloatTensor<Autodiff<B, C>>,
        _grad: FloatTensor<Autodiff<B, C>>,
        _output_size: [usize; 2],
        _options: InterpolateOptions,
    ) -> AutodiffTensor<B> {
        panic!("Can't differentiate interpolate backward.");
    }

    fn attention(
        query: FloatTensor<Autodiff<B, C>>,
        key: FloatTensor<Autodiff<B, C>>,
        value: FloatTensor<Autodiff<B, C>>,
        mask: Option<burn_backend::tensor::BoolTensor<Autodiff<B, C>>>,
        attn_bias: Option<FloatTensor<Autodiff<B, C>>>,
        options: AttentionModuleOptions,
    ) -> FloatTensor<Autodiff<B, C>> {
        attention_fallback::<Self>(query, key, value, mask, attn_bias, options)
    }

    fn ctc_loss(
        log_probs: FloatTensor<Autodiff<B, C>>,
        targets: IntTensor<Autodiff<B, C>>,
        input_lengths: IntTensor<Autodiff<B, C>>,
        target_lengths: IntTensor<Autodiff<B, C>>,

View on GitHub (pinned to d16f7ba2ed)

Solutions

  1. Use ConvTranspose2d or conv-based upsampling instead of interpolate inside the trained graph
  2. Implement the resize backward as a composition of supported ops (e.g. gather/unsqueeze/broadcast)
  3. Detach at the resize boundary: resize outside the autodiff graph or call detach() on its input
  4. Use an inner backend whose interpolate backward exists and wrap only supported ops in autodiff

Example fix

// before
let up = interpolate(&x, [64, 64], InterpolateOptions::nearest());
// after
let up = conv_transpose2d(&x, upsample_weight, None, [2, 2], [0, 0], [1, 1]);
Defensive patterns

Strategy: fallback

Validate before calling

if graph_contains_interpolate && is_training {
    eprintln!("interpolate backward panics in burn-autodiff; use conv_transpose2d or move resize outside the graph");
}

Prevention

When it happens

Trigger: Training any model whose graph contains interpolate (image resize/upsampling, e.g. U-Net upsampling layers) with the autodiff backend.

Common situations: Segmentation/upsampling architectures (U-Net style) that resize feature maps; preprocessing inside the differentiable graph; migrating torchvision interpolate-based decoders.

Related errors


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