{"record":{"id":"ddbab676aeca768a","repo":"huggingface/candle","slug":"unexpected-len-from-chunk-ys-ddbab6","errorCode":null,"errorMessage":"unexpected len from chunk {ys:?}","messagePattern":"unexpected len from chunk (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"candle-transformers/src/models/flux/quantized_model.rs","lineNumber":89,"sourceCode":"#[derive(Debug, Clone)]\nstruct Modulation1 {\n    lin: Linear,\n}\n\nimpl Modulation1 {\n    fn new(dim: usize, vb: VarBuilder) -> Result<Self> {\n        let lin = linear(dim, 3 * dim, vb.pp(\"lin\"))?;\n        Ok(Self { lin })\n    }\n\n    fn forward(&self, vec_: &Tensor) -> Result<ModulationOut> {\n        let ys = vec_\n            .silu()?\n            .apply(&self.lin)?\n            .unsqueeze(1)?\n            .chunk(3, D::Minus1)?;\n        if ys.len() != 3 {\n            candle::bail!(\"unexpected len from chunk {ys:?}\")\n        }\n        Ok(ModulationOut {\n            shift: ys[0].clone(),\n            scale: ys[1].clone(),\n            gate: ys[2].clone(),\n        })\n    }\n}\n\n#[derive(Debug, Clone)]\nstruct Modulation2 {\n    lin: Linear,\n}\n\nimpl Modulation2 {\n    fn new(dim: usize, vb: VarBuilder) -> Result<Self> {\n        let lin = linear(dim, 6 * dim, vb.pp(\"lin\"))?;\n        Ok(Self { lin })","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/huggingface/candle/blob/d5fee525bfde3273eb7c9b75fd2bc4937be867ca/candle-transformers/src/models/flux/quantized_model.rs#L71-L107","documentation":"Identical guard to model.rs:250 but in the quantized (GGUF/quantized weights) Flux variant: QModulation1::forward projects the conditioning vector to 3*dim and chunks it into shift/scale/gate. The bail fires when chunk(3, D::Minus1) does not return 3 chunks, meaning the quantized modulation linear's output last dimension is not divisible by 3 — almost always a hidden_size/config mismatch or a quantized checkpoint whose linear weights were incorrectly dequantized/loaded.","triggerScenarios":"Running the quantized Flux model (candle-transformers::models::flux::quantized_model) with a FluxConfig whose hidden_size does not match the GGUF checkpoint; loading mismatched GGUF shards; a vec_ conditioning tensor with wrong feature width entering the block.","commonSituations":"Using GGUF-quantized Flux.1 files with hand-built configs; GGUF files from different model revisions (dev vs schnell metadata); bugs in custom GGUF conversion scripts producing wrong linear dimensions.","solutions":["Verify the FluxConfig.hidden_size used with the quantized model matches the GGUF file (inspect tensor names/shapes with gguf metadata tools).","Inspect the {ys:?} debug in the error message to see the actual chunk count and derive the real feature dim.","Re-download the GGUF checkpoint from a trusted source; a corrupt or partially downloaded GGUF can yield wrong tensor shapes.","If self-converted, fix the conversion script so modulation lin weights map to the correct (3*hidden_size, hidden_size) shape."],"exampleFix":"// before: config invented for a GGUF file\nlet config = FluxConfig { hidden_size: 2048, .. };\nlet model = Flux::new(&config, gguf_content, vb)?;\n\n// after: hidden_size matching the quantized checkpoint\nlet config = FluxConfig { hidden_size: 3072, .. };\nlet model = Flux::new(&config, gguf_content, vb)?;","handlingStrategy":"validation","validationCode":"// Rust: verify GGUF tensor shapes against config before building the quantized model\nlet hidden = cfg.hidden_size;\nlet expected: String = format!(\"double_blocks.0.modulation.lin.weight\");\nif let Some(t) = content.tensor(&expected) {\n    if t.dims() != [3 * hidden, hidden] {\n        candle::bail!(\"gguf lin shape {:?} != [{}, {}]\", t.dims(), 3 * hidden, hidden);\n    }\n}","typeGuard":"fn gguf_mod_shape_ok(dims: &[usize], hidden: usize) -> bool {\n    dims == [3 * hidden, hidden]\n}","tryCatchPattern":"match quantized_flux.forward(&img, &img_ids, &txt, &txt_ids, &ts, &y, guidance) {\n    Ok(t) => t,\n    Err(e) if e.to_string().contains(\"unexpected len from chunk\") => {\n        eprintln!(\"quantized checkpoint/config mismatch: {e}\");\n        return Err(e);\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Inspect GGUF metadata (tensor names and dims) before constructing FluxConfig.","Download GGUF files from trusted repos and verify checksums; corrupted quantized files can yield wrong shapes.","Use the candle quantized-flux example's config logic verbatim when loading GGUF.","If self-quantizing, validate modulation lin weights round-trip to (3*hidden, hidden) after conversion."],"tags":["candle","gguf","quantized","tensor-shape","chunk","flux"],"backgroundTag":"tensor-shape-mismatch","analyzedSha":"d5fee525bfde3273eb7c9b75fd2bc4937be867ca","analyzedAt":"2026-09-02T00:15:47.023Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}