huggingface/candle · error

pad-mode 'reflect' is not supported

Error message

pad-mode 'reflect' is not supported

What it means

pad1d in the Mimi conv module supports Constant (zero-pad) and Replicate padding, but Reflect padding is not implemented in candle, so it bails when a layer's pad_mode is Reflect. The function is called from forward and step for each padded conv computation, so the error surfaces during inference.

Source

Thrown at candle-transformers/src/models/mimi/conv.rs:226

}

fn get_extra_padding_for_conv1d(
    xs: &Tensor,
    k_size: usize,
    stride: usize,
    padding_total: usize,
) -> Result<usize> {
    let len = xs.dim(D::Minus1)?;
    let n_frames = (len + padding_total).saturating_sub(k_size) as f64 / stride as f64 + 1.0;
    let ideal_len =
        ((n_frames.ceil() as usize - 1) * stride + k_size).saturating_sub(padding_total);
    Ok(ideal_len.saturating_sub(len))
}

fn pad1d(xs: &Tensor, pad_l: usize, pad_r: usize, mode: PadMode) -> Result<Tensor> {
    match mode {
        PadMode::Constant => xs.pad_with_zeros(D::Minus1, pad_l, pad_r),
        PadMode::Reflect => candle::bail!("pad-mode 'reflect' is not supported"),
        PadMode::Replicate => xs.pad_with_same(D::Minus1, pad_l, pad_r),
    }
}

fn unpad1d(xs: &Tensor, unpad_l: usize, unpad_r: usize) -> Result<Tensor> {
    let len = xs.dim(D::Minus1)?;
    if len < unpad_l + unpad_r {
        candle::bail!("unpad1d: tensor len {len} is too low, {unpad_l} + {unpad_r}")
    }
    xs.narrow(D::Minus1, unpad_l, len - (unpad_l + unpad_r))
}

#[derive(Debug, Clone)]
pub struct StreamableConv1d {
    conv: NormConv1d,
    causal: bool,
    pad_mode: PadMode,
    state_prev_xs: StreamTensor,

View on GitHub (pinned to d5fee525bf)

Solutions

  1. Set the conv config's pad_mode to PadMode::Constant or PadMode::Replicate
  2. Use the standard Mimi checkpoint, which does not require reflect padding
  3. Implement reflect padding in candle (e.g. via index flip and concat) if reflect semantics are required

Example fix

// before
let cfg = Conv1dConfig { pad_mode: PadMode::Reflect, .. };
// after
let cfg = Conv1dConfig { pad_mode: PadMode::Replicate, .. };
Defensive patterns

Strategy: validation

Validate before calling

if cfg.pad_mode == PadMode::Reflect {
    return Err("candle mimi does not support reflect padding; use Constant or Replicate");
}

Try / catch

let out = layer.forward(&xs)
    .map_err(|e| format!("padding failed: {e}"))?;

Prevention

When it happens

Trigger: Running a Mimi model whose conv layers specify pad_mode = PadMode::Reflect; the failure occurs when forward or step invokes pad1d with that mode.

Common situations: Loading a Mimi/EnCodec checkpoint variant that used reflect padding; converting configs from PyTorch (where F.pad mode='reflect' exists) without adjusting to candle's supported modes.

Related errors


AI-assisted analysis of huggingface/candle@d5fee525bf (2026-09-02). Data as JSON: /api/errors/4d14a8a3d1a0086f. Report an issue: GitHub.