{"record":{"id":"930e4b34e8922ef4","repo":"huggingface/candle","slug":"unsupported-nearest-mode-for-resize","errorCode":null,"errorMessage":"Unsupported nearest_mode for resize: {}","messagePattern":"Unsupported nearest_mode for resize: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"candle-onnx/src/eval.rs","lineNumber":2354,"sourceCode":"                        .collect::<Vec<_>>(),\n                    (None, None) => bail!(\"Either scales or sizes should be present\"),\n                };\n\n                let coordinate_transformation_mode =\n                    get_attr_opt::<str>(node, \"coordinate_transformation_mode\")?\n                        .unwrap_or(\"half_pixel\");\n                // Interpolation mode: nearest, linear, or cubic.\n                let mode = get_attr_opt::<str>(node, \"mode\")?.unwrap_or(\"nearest\");\n                // How to determine the \"nearest\" pixel in nearest interpolation mode.\n                let nearest_mode =\n                    get_attr_opt::<str>(node, \"nearest_mode\")?.unwrap_or(\"round_prefer_floor\");\n\n                if mode != \"nearest\" {\n                    bail!(\"Unsupported resize mode: {}\", mode);\n                }\n\n                if nearest_mode != \"floor\" {\n                    bail!(\"Unsupported nearest_mode for resize: {}\", nearest_mode);\n                }\n\n                if coordinate_transformation_mode != \"asymmetric\" {\n                    bail!(\n                        \"Unsupported coordinate_transformation_mode for resize: {}\",\n                        coordinate_transformation_mode\n                    );\n                }\n\n                let h = output_dims[2];\n                let w = output_dims[3];\n                let output = input.upsample_nearest2d(h, w)?;\n\n                values.insert(node.output[0].clone(), output);\n            }\n            \"Trilu\" => {\n                let input = get(&node.input[0])?;\n","sourceCodeStart":2336,"sourceCodeEnd":2372,"githubUrl":"https://github.com/huggingface/candle/blob/d5fee525bfde3273eb7c9b75fd2bc4937be867ca/candle-onnx/src/eval.rs#L2336-L2372","documentation":"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.","triggerScenarios":"Evaluating a Resize node with mode=\"nearest\" but nearest_mode set to (or defaulting to) anything other than \"floor\".","commonSituations":"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.","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"],"exampleFix":"// before\n// attribute nearest_mode absent (defaults to \"round_prefer_floor\")\n// after\nnode.attribute.push(onnx_attr(\"nearest_mode\", \"floor\"));","handlingStrategy":"validation","validationCode":"if node.op_type == \"Resize\" {\n    let nm = get_attr_opt::<String>(node, \"nearest_mode\")?.unwrap_or_else(|| \"round_prefer_floor\".into());\n    if nm != \"floor\" { return Err(format!(\"nearest_mode {} unsupported\", nm)); }\n}","typeGuard":"fn uses_floor_nearest(node: &Node) -> bool {\n    get_attr_opt::<String>(node, \"nearest_mode\").ok().flatten().map_or(false, |m| m == \"floor\")\n}","tryCatchPattern":"match eval(...) {\n    Err(e) if e.contains(\"Unsupported nearest_mode\") => rewrite_nearest_mode_to_floor(model).and_then(eval),\n    other => other,\n}","preventionTips":["Set nearest_mode='floor' explicitly at export time","Validate resize attributes after export","Note the ONNX default is round_prefer_floor, not floor"],"tags":["onnx","resize","unsupported-feature"],"backgroundTag":"unsupported-operator-feature","analyzedSha":"d5fee525bfde3273eb7c9b75fd2bc4937be867ca","analyzedAt":"2026-09-02T00:15:47.023Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}