huggingface/candle · error

more dilations than expected in conv2d {s:?} {}

Error message

more dilations than expected in conv2d {s:?} {}

What it means

candle-onnx handles Conv nodes with weight rank 1 (conv1d), 2 (conv2d) or 4 (via batched-matmul path); any other weight rank has no mapped implementation, so the catch-all match arm bails with this message including the actual rank.

Source

Thrown at candle-onnx/src/eval.rs:965

                            }
                            Some(s) => {
                                bail!("more strides than expected in conv2d {s:?} {}", node.name)
                            }
                        };
                        let dilations = match dilations {
                            None => 1,
                            Some([p]) => *p as usize,
                            Some([p1, p2]) => {
                                if p1 != p2 {
                                    bail!(
                                        "dilations have to be the same on both axis {pads:?} {}",
                                        node.name
                                    )
                                }
                                *p1 as usize
                            }
                            Some(s) => {
                                bail!("more dilations than expected in conv2d {s:?} {}", node.name)
                            }
                        };
                        xs.conv2d(ws, pads, strides, dilations, groups as usize)?
                    }
                    rank => bail!(
                        "unsupported rank for weight matrix {rank} in conv {}",
                        node.name
                    ),
                };
                let ys = if node.input.len() > 2 {
                    let bs = get(&node.input[2])?;
                    let mut bs_shape = vec![1; ys.rank()];
                    bs_shape[1] = bs.elem_count();
                    ys.broadcast_add(&bs.reshape(bs_shape)?)?
                } else {
                    ys
                };
                values.insert(node.output[0].clone(), ys);

View on GitHub (pinned to d5fee525bf)

Solutions

  1. Rewrite the model to use supported ops (e.g. express 3D conv as 2D convs or matmuls) and re-export
  2. Reshape weights to rank 4 and adjust the graph accordingly when semantics permit
  3. Use onnxruntime or another backend that supports arbitrary-rank Conv for this model
  4. Contribute/patch conv3d support in candle-onnx

Example fix

// before: 3D conv weights shape [64, 32, 3, 3, 3]
// after: reshape to [64, 32*3, 3, 3] and use two stacked 2D convs, then re-export
Defensive patterns

Strategy: validation

Validate before calling

for node in &model.graph.node {
    if node.op_type == "Conv" {
        let w_name = &node.input[1];
        let w = model.graph.initializer.iter().find(|t| &t.name == w_name);
        if let Some(t) = w {
            let rank = t.dims.len();
            if !matches!(rank, 1 | 2 | 4) {
                panic!("node {}: conv weight rank {} unsupported", node.name, rank);
            }
        }
    }
}

Type guard

fn conv_weight_rank_ok(dims: &[i64]) -> bool {
    matches!(dims.len(), 1 | 2 | 4)
}

Try / catch

match candle_onnx::simple_eval(&model, &inputs) {
    Err(e) if e.to_string().contains("unsupported rank for weight matrix") => {
        eprintln!("model uses an unsupported conv weight rank: {e}");
    }
    other => other?,
}

Prevention

When it happens

Trigger: A Conv node whose weight (W) input is 3D, 5D, or otherwise not rank 1/2/4, e.g. a 3D convolution exported with the generic Conv op.

Common situations: 3D convolutions (video/volumetric models) exported to ONNX; models exported with squeezed/reshaped weights; converters that emit non-standard weight ranks.

Related errors


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