tracel-ai/burn · error

interpolate_backward: unsupported mode {:?} / dtype {:?}

Error message

interpolate_backward: unsupported mode {:?} / dtype {:?}

What it means

interpolate_backward mirrors the forward interpolate op: it dispatches on (InterpolateMode, x.dtype()) and implements all four modes for F32/F64/F16/BF16 only. Any other dtype reaches the catch-all arm, which panics reporting the unsupported mode/dtype pair during the gradient computation.

Source

Thrown at crates/burn-flex/src/ops/module.rs:714

            }
            (InterpolateMode::Bicubic, DType::F16) => {
                interpolate::interpolate_bicubic_backward_f16(
                    x,
                    grad,
                    output_size,
                    options.align_corners,
                )
            }
            (InterpolateMode::Bicubic, DType::BF16) => {
                interpolate::interpolate_bicubic_backward_bf16(
                    x,
                    grad,
                    output_size,
                    options.align_corners,
                )
            }
            (mode, dtype) => {
                panic!(
                    "interpolate_backward: unsupported mode {:?} / dtype {:?}",
                    mode, dtype
                )
            }
        }
    }

    fn attention(
        query: FloatTensor<Flex>,
        key: FloatTensor<Flex>,
        value: FloatTensor<Flex>,
        mask: Option<BoolTensor<Flex>>,
        attn_bias: Option<FloatTensor<Flex>>,
        options: AttentionModuleOptions,
    ) -> FloatTensor<Flex> {
        crate::ops::attention::attention(query, key, value, mask, attn_bias, options)
    }

View on GitHub (pinned to d16f7ba2ed)

Solutions

  1. Cast the input/grad to a supported float dtype (e.g. .cast(DType::F32)) before the backward call.
  2. Fix the forward pass so only float tensors reach interpolate, guaranteeing float saved state.
  3. Add the missing (mode, dtype) match arm calling interpolate_<mode>_backward_<dtype> in crates/burn-flex/src/ops/module.rs.

Example fix

// before
let dx = interpolate_backward::<F32>(x_u8, grad, Bilinear); // panics
// after
let dx = interpolate_backward::<F32>(x_u8.cast(DType::F32), grad, Bilinear);
Defensive patterns

Strategy: validation

Validate before calling

assert!(matches!(x.dtype(), burn::tensor::DType::F32 | burn::tensor::DType::F64 | burn::tensor::DType::F16 | burn::tensor::DType::BF16), "interpolate_backward needs a float tensor, got {:?} (mode {:?})", x.dtype(), options.mode);

Type guard

fn is_float_dtype(d: burn::tensor::DType) -> bool {
    matches!(d, burn::tensor::DType::F32 | burn::tensor::DType::F64 | burn::tensor::DType::F16 | burn::tensor::DType::BF16)
}

Try / catch

// Cast before backward through interpolate:
let x = if is_float_dtype(x.dtype()) { x } else { x.cast(burn::tensor::DType::F32) };

Prevention

When it happens

Trigger: Backpropagating through interpolate/upsample on the Flex backend when the saved input tensor x has a dtype other than F32/F64/F16/BF16, for any InterpolateMode.

Common situations: Training vision models where non-float tensors entered an upsampling layer; u8/int image data flowing into training; precision mismatch between forward and saved tensors after checkpoint load or backend switch.

Related errors


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