tracel-ai/burn · error

Invalid dimensionality

Error message

Invalid dimensionality

What it means

conv_data_backward_fallback implements the data-gradient of convolution by rewriting it as a transposed convolution over an unpermuted layout. It only handles 1D, 2D and 3D convolutions; for any other dimensionality it hits the catch-all arm and panics with this unimplemented!.

Source

Thrown at crates/burn-cubecl/src/kernel/conv/backward_data/fallback.rs:117

            None,
            ConvTransposeOptions::new(
                [options.stride[0], options.stride[1], options.stride[2]],
                [
                    options.padding_begin()[0],
                    options.padding_begin()[1],
                    options.padding_begin()[2],
                ],
                [padding_out[0], padding_out[1], padding_out[2]],
                [
                    options.dilation[0],
                    options.dilation[1],
                    options.dilation[2],
                ],
                options.groups,
            ),
        )
        .unwrap()),
        _ => unimplemented!("Invalid dimensionality"),
    }?;
    Ok(permute_nchw_to_nhwc(in_grad))
}

fn conv_transpose1d_from_conv_transpose2d(
    x: CubeTensor,
    weight: CubeTensor,
    options: ConvTransposeOptions<1>,
) -> Result<CubeTensor, ConvSetupError> {
    let [channels_in, channels_out, kernel_size] = weight.shape().dims();
    let [batch_size, _channels_in, length_in] = x.shape().dims();

    let weight = reshape(
        weight,
        Shape::new([channels_in, channels_out, kernel_size, 1]),
    );
    let x = reshape(x, Shape::new([batch_size, channels_in, length_in, 1]));

View on GitHub (pinned to d16f7ba2ed)

Solutions

  1. Restrict the model to 1D/2D/3D convolutions when using the CubeCL backend
  2. Compute the weight/gradient path manually or on a backend that supports N-d conv backward
  3. Upgrade burn — check if higher-rank conv backward support was added
  4. Wrap higher-rank conv as multiple lower-rank ops (e.g. loop over extra dims)

Example fix

// before
let grad = conv4d_backward(x, weight, options); // panics: Invalid dimensionality
// after
let grad = conv2d_backward(x, weight, ConvOptions::new(stride2d, pad2d, dil2d, groups)); // supported rank
Defensive patterns

Strategy: validation

Validate before calling

fn assert_supported_conv_rank(rank: usize) {
    assert!((1..=3).contains(&rank), "CubeCL conv backward supports rank 1-3, got {rank}");
}

Type guard

fn is_conv_backward_supported(options: &ConvOptions) -> bool {
    matches!(options.rank, 1 | 2 | 3)
}

Try / catch

// Panic-based; guard instead:
if options.rank <= 3 { conv_data_backward(x, weight, options) } else { /* manual or CPU fallback */ }

Prevention

When it happens

Trigger: Calling backward on a convolution whose options.rank is not 1, 2 or 3 (e.g. 4D/5D convolution) on the CubeCL backend, or constructing ConvOptions with a mismatched rank vector so the match falls through.

Common situations: Implementing a custom 4D convolution layer and calling backward on GPU; porting models from frameworks that allow N-d convolution; misconfigured ConvOptions rank after refactoring.

Related errors


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