huggingface/candle · error
internal error, unexpected current position {tensor_start_po
Error message
internal error, unexpected current position {tensor_start_pos} {offset} {pos} What it means
During GGUF writing, candle computes exact byte offsets for each tensor's data and asserts the writer's stream position matches the expected offset before writing each tensor. A mismatch indicates an internal invariant violation (a bug in offset calculation or an I/O layer that skipped/inserted bytes), not user error.
Source
Thrown at candle-core/src/quantized/gguf_file.rs:627
w.write_u32::<LittleEndian>(dims.len() as u32)?;
for &dim in dims.iter().rev() {
w.write_u64::<LittleEndian>(dim as u64)?;
}
w.write_u32::<LittleEndian>(tensor.dtype().to_u32())?;
w.write_u64::<LittleEndian>(offset as u64)?;
offsets.push(offset);
let size_in_bytes = tensor.storage_size_in_bytes();
let padding = 31 - (31 + size_in_bytes) % 32;
offset += size_in_bytes + padding;
}
let pos = w.stream_position()? as usize;
let padding = 31 - (31 + pos) % 32;
w.write_all(&vec![0u8; padding])?;
let tensor_start_pos = w.stream_position()? as usize;
for (offset, (_name, tensor)) in offsets.iter().zip(tensors.iter()) {
let pos = w.stream_position()? as usize;
if tensor_start_pos + offset != pos {
crate::bail!(
"internal error, unexpected current position {tensor_start_pos} {offset} {pos}"
)
}
let data = tensor.data()?;
let size_in_bytes = data.len();
w.write_all(&data)?;
let padding = 31 - (31 + size_in_bytes) % 32;
w.write_all(&vec![0u8; padding])?;
}
Ok(())
}
View on GitHub (pinned to d5fee525bf)
Solutions
- Write directly to a File or BufWriter<File> instead of a custom wrapper writer
- Update candle-core; if reproducible, file a bug with a minimal reproduction
- Ensure no concurrent writes to the same underlying stream
Example fix
// before
let file = CustomFilteringWriter::new(std::fs::File::create("out.gguf")?); // custom wrapper
// after
let file = std::io::BufWriter::new(std::fs::File::create("out.gguf")?); Defensive patterns
Strategy: try-catch
Try / catch
match GgufFile::write(tensors, &mut w) {
Ok(_) => {},
Err(e) if e.to_string().contains("unexpected current position") => {
eprintln!("gguf write offset invariant failed; retry with a plain File/BufWriter and report if reproducible");
return Err(e.into());
}
Err(e) => return Err(e.into()),
} Prevention
- Write gguf output through std File/BufWriter, not custom transforming writers
- Keep candle-core updated
- Never share one writer across threads
When it happens
Trigger: GgufFile::write when the underlying writer's position deviates from the computed tensor_start_pos + offset — e.g., a non-seekable or misbehaving writer adapter, or a genuine candle bug.
Common situations: Writing through custom wrapper writers that buffer or transform bytes; hitting a candle version bug in GGUF serialization offset alignment.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- multiple value-types in the same array {value_type:?}
- not a f32 {v:?}
- not a f64 {v:?}
- not a bool {v:?}
- not a vec {v:?}
AI-assisted analysis of huggingface/candle@d5fee525bf (2026-09-02).
Data as JSON: /api/errors/4b566159dd1fbd18.
Report an issue: GitHub.