huggingface/candle · error

Unsupported resize mode: {}

Error message

Unsupported resize mode: {}

What it means

candle-onnx only implements the `nearest` interpolation mode for the ONNX Resize operator. Any other `mode` attribute value (`linear`, `cubic`) is rejected at evaluation time with this message. The op is unsupported, not invalid — the model itself is spec-compliant.

Source

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

                    (None, Some(sizes_tensor)) => sizes_tensor
                        .to_vec1::<i64>()?
                        .iter()
                        .map(|&d| d as usize)
                        .collect::<Vec<_>>(),
                    (None, None) => bail!("Either scales or sizes should be present"),
                };

                let coordinate_transformation_mode =
                    get_attr_opt::<str>(node, "coordinate_transformation_mode")?
                        .unwrap_or("half_pixel");
                // Interpolation mode: nearest, linear, or cubic.
                let mode = get_attr_opt::<str>(node, "mode")?.unwrap_or("nearest");
                // How to determine the "nearest" pixel in nearest interpolation mode.
                let nearest_mode =
                    get_attr_opt::<str>(node, "nearest_mode")?.unwrap_or("round_prefer_floor");

                if mode != "nearest" {
                    bail!("Unsupported resize mode: {}", mode);
                }

                if nearest_mode != "floor" {
                    bail!("Unsupported nearest_mode for resize: {}", nearest_mode);
                }

                if coordinate_transformation_mode != "asymmetric" {
                    bail!(
                        "Unsupported coordinate_transformation_mode for resize: {}",
                        coordinate_transformation_mode
                    );
                }

                let h = output_dims[2];
                let w = output_dims[3];
                let output = input.upsample_nearest2d(h, w)?;

                values.insert(node.output[0].clone(), output);

View on GitHub (pinned to d5fee525bf)

Solutions

  1. Change the model to use nearest-neighbor resize (mode="nearest") if acceptable
  2. Pre-resize outside the graph and remove the Resize node from the model
  3. Implement linear/cubic resize support in candle-onnx and rebuild
  4. Use a different ONNX runtime (onnxruntime) for models needing linear/cubic resize

Example fix

# before
# node attribute: mode = "linear"
# after (PyTorch export)
F.interpolate(x, scale_factor=2, mode='nearest')
Defensive patterns

Strategy: validation

Validate before calling

for node in &graph.node {
    if node.op_type == "Resize" {
        let mode = get_attr_opt::<String>(node, "mode")?.unwrap_or_else(|| "nearest".into());
        if mode != "nearest" { return Err(format!("mode {} unsupported", mode)); }
    }
}

Type guard

fn is_nearest_resize(node: &Node) -> bool {
    node.op_type == "Resize"
        && get_attr_opt::<String>(node, "mode").ok().flatten().map_or(true, |m| m == "nearest")
}

Try / catch

match eval(...) {
    Err(e) if e.contains("Unsupported resize mode") => fallback_to_onnxruntime(model),
    other => other,
}

Prevention

When it happens

Trigger: Running a model containing `Resize` nodes with attribute mode="linear" (common for bilinear upsampling) or mode="cubic" through simple_eval/simple_eval_.

Common situations: Vision models using bilinear resize (segmentation, super-resolution, U-Net variants) exported from PyTorch F.interpolate(mode='bilinear'); centripetal/bicubic resampling in preprocessing graphs.

Related errors


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