{"record":{"id":"1f546e0faf7ecaae","repo":"huggingface/candle","slug":"internal-error-inconsistent-lhs-and-rhs-lhs-r","errorCode":null,"errorMessage":"INTERNAL ERROR inconsistent lhs and rhs {lhs:?} {rhs:?}","messagePattern":"INTERNAL ERROR inconsistent lhs and rhs (.+?) (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"candle-core/src/streaming.rs","lineNumber":191,"sourceCode":"            BinOp::Div => Tensor::div(lhs, rhs),\n        }\n    }\n\n    pub fn step(&mut self, lhs: &StreamTensor, rhs: &StreamTensor) -> Result<StreamTensor> {\n        let lhs = StreamTensor::cat2(&self.prev_lhs, lhs, self.dim)?;\n        let rhs = StreamTensor::cat2(&self.prev_rhs, rhs, self.dim)?;\n        let lhs_len = lhs.seq_len(self.dim)?;\n        let rhs_len = rhs.seq_len(self.dim)?;\n        let common_len = usize::min(lhs_len, rhs_len);\n        let (lhs, prev_lhs) = lhs.split(self.dim, common_len)?;\n        let (rhs, prev_rhs) = rhs.split(self.dim, common_len)?;\n        let ys = match (lhs.0, rhs.0) {\n            (Some(lhs), Some(rhs)) => {\n                let ys = self.forward(&lhs, &rhs)?;\n                StreamTensor::from_tensor(ys)\n            }\n            (None, None) => StreamTensor::empty(),\n            (lhs, rhs) => crate::bail!(\"INTERNAL ERROR inconsistent lhs and rhs {lhs:?} {rhs:?}\"),\n        };\n        self.prev_lhs = prev_lhs;\n        self.prev_rhs = prev_rhs;\n        Ok(ys)\n    }\n}\n\n/// Simple wrapper that doesn't do any buffering.\npub struct Map<T: crate::Module>(T);\n\nimpl<T: crate::Module> StreamingModule for Map<T> {\n    fn reset_state(&mut self) {}\n\n    fn step(&mut self, xs: &StreamTensor) -> Result<StreamTensor> {\n        xs.apply(&self.0)\n    }\n}\n","sourceCodeStart":173,"sourceCodeEnd":209,"githubUrl":"https://github.com/huggingface/candle/blob/d5fee525bfde3273eb7c9b75fd2bc4937be867ca/candle-core/src/streaming.rs#L173-L209","documentation":"In a streaming module's step(), the left and right StreamTensor inputs must both be present or both be absent; a mismatch (one Some, one None) indicates the streaming pipeline desynchronized, which candle treats as an internal invariant violation rather than a user-facing error.","triggerScenarios":"Calling StreamTensor::step on a streaming module where one input stream produced a value while the other produced empty() at the same step — e.g. feeding streams of unequal lengths or misaligned step counts.","commonSituations":"Streaming a sequence through a module with two inputs (e.g. attention with separate query/key streams) where one input ran out of frames earlier than the other; off-by-one in a streaming loop.","solutions":["Audit your streaming loop to ensure both input streams are fed the same number of steps and finish at the same time.","Check StreamTensor is_empty() on both inputs before calling step and handle end-of-stream on either side jointly.","Verify that upstream modules output matching stream lengths; pad/trim streams to align them."],"exampleFix":"// before\nys = module.step(&lhs, &rhs)?; // may be one empty, one Some\n// after\nif lhs.is_empty() != rhs.is_empty() {\n    // align or end both streams before stepping\n    return Err(anyhow!(\"streams desynchronized\"));\n}\nys = module.step(&lhs, &rhs)?;","handlingStrategy":"validation","validationCode":"if lhs.is_empty() != rhs.is_empty() {\n    return Err(anyhow!(\"stream inputs desynchronized: lhs empty={} rhs empty={}\", lhs.is_empty(), rhs.is_empty()));\n}\nlet ys = module.step(&lhs, &rhs)?;","typeGuard":null,"tryCatchPattern":"match module.step(&lhs, &rhs) {\n    Ok(ys) => ys,\n    Err(e) if e.to_string().contains(\"inconsistent lhs and rhs\") => {\n        // re-align streams: drop/pad frames until both sides agree, then retry\n        ...\n    }\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Feed both input streams the same number of steps; end them together.","Check is_empty() on both StreamTensors before each step.","Log stream lengths per step during development to catch drift early."],"tags":["streaming","invariant-violation","internal"],"backgroundTag":"stream-input-mismatch","analyzedSha":"d5fee525bfde3273eb7c9b75fd2bc4937be867ca","analyzedAt":"2026-09-02T00:15:47.023Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}