{"record":{"id":"323d5ceaa91459b9","repo":"huggingface/candle","slug":"invalid-nval-for-entry","errorCode":null,"errorMessage":"Invalid nval for entry {}: {}","messagePattern":"Invalid nval for entry (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"candle-core/src/quantized/imatrix_file.rs","lineNumber":69,"sourceCode":"        let mut name_buf = vec![0u8; len];\n        cursor.read_exact(&mut name_buf).map_err(|e| {\n            crate::Error::msg(format!(\"Failed to read name for entry {}: {}\", i + 1, e))\n        })?;\n        let name = String::from_utf8(name_buf).map_err(|e| {\n            crate::Error::msg(format!(\"Invalid UTF-8 name for entry {}: {}\", i + 1, e))\n        })?;\n\n        // Read ncall and nval\n        let ncall = cursor.read_i32::<LittleEndian>().map_err(|e| {\n            crate::Error::msg(format!(\"Failed to read ncall for entry {}: {}\", i + 1, e))\n        })? as usize;\n\n        let nval = cursor.read_i32::<LittleEndian>().map_err(|e| {\n            crate::Error::msg(format!(\"Failed to read nval for entry {}: {}\", i + 1, e))\n        })? as usize;\n\n        if nval < 1 {\n            crate::bail!(\"Invalid nval for entry {}: {}\", i + 1, nval);\n        }\n\n        let mut data = Vec::with_capacity(nval);\n        for _ in 0..nval {\n            let v = cursor.read_f32::<LittleEndian>().unwrap();\n            if ncall == 0 {\n                data.push(v);\n            } else {\n                data.push(v / ncall as f32);\n            }\n        }\n        all_data.insert(name, data);\n    }\n\n    Ok(all_data)\n}\n","sourceCodeStart":51,"sourceCodeEnd":86,"githubUrl":"https://github.com/huggingface/candle/blob/d5fee525bfde3273eb7c9b75fd2bc4937be867ca/candle-core/src/quantized/imatrix_file.rs#L51-L86","documentation":"Each imatrix entry declares how many f32 values (nval) follow. A value < 1 is invalid since an importance matrix entry must contain at least one value; candle bails with the entry index and the bogus value. This signals corruption or a format mismatch in the imatrix file.","triggerScenarios":"load_imatrix reading an entry whose nval i32 field is 0 or negative — truncated file, misaligned parsing due to earlier corruption, or a file not actually in imatrix format.","commonSituations":"Corrupted downloads; passing a regular GGUF or other binary where an imatrix file is expected; imatrix produced by an incompatible tool version.","solutions":["Regenerate or re-download the imatrix file and verify it was produced by a compatible tool version","Verify the file is actually an imatrix file (correct path/format) before loading","Check the file for truncation/corruption (size and checksum)"],"exampleFix":"// before\nlet imatrix = load_imatrix(\"model.gguf\")?; // wrong file passed\n// after\nlet imatrix = load_imatrix(\"model.imatrix\")?; // correct imatrix file","handlingStrategy":"validation","validationCode":"let meta = std::fs::metadata(\"model.imatrix\")?;\nif meta.len() < 8 {\n    return Err(anyhow!(\"imatrix too small to be valid ({} bytes)\", meta.len()));\n}\nassert_eq!(sha256_file(\"model.imatrix\")?, EXPECTED_SHA256);","typeGuard":null,"tryCatchPattern":"match load_imatrix(&fname) {\n    Ok(m) => m,\n    Err(e) if e.to_string().contains(\"Invalid nval\") => {\n        eprintln!(\"imatrix file corrupt or wrong format; regenerate with a compatible tool\");\n        return Err(e.into());\n    }\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Verify checksums of imatrix files","Use imatrix files produced by the same toolchain version as your candle build","Never pass arbitrary gguf/binaries where an imatrix file is expected"],"tags":["imatrix","corrupt-file","parsing"],"backgroundTag":"empty-input-file","analyzedSha":"d5fee525bfde3273eb7c9b75fd2bc4937be867ca","analyzedAt":"2026-09-02T00:15:47.023Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}