huggingface/candle · error
Unsupported nearest_mode for resize: {}
Error message
Unsupported nearest_mode for resize: {} What it means
Even in nearest mode, candle-onnx only supports nearest_mode="floor" for the Resize operator. Other ONNX nearest_mode values (`round_prefer_floor`, the default, `round_prefer_ceil`, `ceil`) are rejected with this error. Note the ONNX default is round_prefer_floor, so models that never set the attribute explicitly will still hit this.
Source
Thrown at candle-onnx/src/eval.rs:2354
.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);
}
"Trilu" => {
let input = get(&node.input[0])?;
View on GitHub (pinned to d5fee525bf)
Solutions
- Patch the graph to set nearest_mode="floor" on Resize nodes (results may differ slightly)
- Set nearest_mode='floor' at export time (e.g. onnx-surgement or onnx.helper edit)
- Implement the other nearest modes in candle-onnx
- Pre-compute the resize outside the graph
Example fix
// before
// attribute nearest_mode absent (defaults to "round_prefer_floor")
// after
node.attribute.push(onnx_attr("nearest_mode", "floor")); Defensive patterns
Strategy: validation
Validate before calling
if node.op_type == "Resize" {
let nm = get_attr_opt::<String>(node, "nearest_mode")?.unwrap_or_else(|| "round_prefer_floor".into());
if nm != "floor" { return Err(format!("nearest_mode {} unsupported", nm)); }
} Type guard
fn uses_floor_nearest(node: &Node) -> bool {
get_attr_opt::<String>(node, "nearest_mode").ok().flatten().map_or(false, |m| m == "floor")
} Try / catch
match eval(...) {
Err(e) if e.contains("Unsupported nearest_mode") => rewrite_nearest_mode_to_floor(model).and_then(eval),
other => other,
} Prevention
- Set nearest_mode='floor' explicitly at export time
- Validate resize attributes after export
- Note the ONNX default is round_prefer_floor, not floor
When it happens
Trigger: Evaluating a Resize node with mode="nearest" but nearest_mode set to (or defaulting to) anything other than "floor".
Common situations: Models exported with default nearest_mode (round_prefer_floor) since the exporter did not set it explicitly; YOLO/SSD detection heads using round-prefer-floor upsampling.
Related errors
- Unsupported resize mode: {}
- Unsupported coordinate_transformation_mode for resize: {}
- Either scales or sizes should be present
- attribute {} was of type TENSOR, but no tensor was found
- attribute {} of type TENSOR was an invalid data_type number
AI-assisted analysis of huggingface/candle@d5fee525bf (2026-09-02).
Data as JSON: /api/errors/930e4b34e8922ef4.
Report an issue: GitHub.