tracel-ai/burn · error

Same padding with an even kernel size is not supported

Error message

Same padding with an even kernel size is not supported

What it means

Configuration guard in conv layer checks: `padding: SamePadding` was requested with an even kernel size, which burn's conv implementation cannot express as symmetric padding (see burn issue #2676); construction of the layer panics.

Source

Thrown at crates/burn-nn/src/modules/conv/checks.rs:19

pub(crate) fn checks_channels_div_groups(channels_in: usize, channels_out: usize, groups: usize) {
    let channels_in_div_by_group = channels_in.is_multiple_of(groups);
    let channels_out_div_by_group = channels_out.is_multiple_of(groups);

    if !channels_in_div_by_group || !channels_out_div_by_group {
        panic!(
            "Both channels must be divisible by the number of groups. Got \
             channels_in={channels_in}, channels_out={channels_out}, groups={groups}"
        );
    }
}

// https://github.com/tracel-ai/burn/issues/2676
/// Only symmetric padding is currently supported. As such, using `Same` padding with an even kernel
/// size is not supported as it will not produce the same output size.
pub(crate) fn check_same_padding_support(kernel_size: &[usize]) {
    for k in kernel_size.iter() {
        if k % 2 == 0 {
            unimplemented!("Same padding with an even kernel size is not supported");
        }
    }
}

View on GitHub (pinned to d16f7ba2ed)

Solutions

  1. Use an odd kernel size (e.g., 3 instead of 2) with SamePadding
  2. Switch to explicit numeric padding that yields the desired output size
  3. Pad the input manually before the convolution
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/burn-nn/src/modules/conv/checks.rs:19 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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