Make compaction transitions recoverable

This commit is contained in:
Georg Bauer
2026-07-26 10:56:19 +02:00
parent 6aa45b2cf0
commit 2a14b93335
13 changed files with 329 additions and 26 deletions

View File

@@ -1,4 +1,5 @@
use memmap2::{Mmap, MmapOptions};
use sha2::{Digest, Sha256};
use std::collections::HashMap;
use std::fs::File;
use std::path::{Path, PathBuf};
@@ -176,6 +177,32 @@ impl Gguf {
self.map.len() as u64
}
pub(super) fn checkpoint_identity(&self) -> [u8; 32] {
let mut hash = Sha256::new();
hash.update(b"DS4Server GGUF checkpoint identity v1");
hash.update(
self.path
.canonicalize()
.unwrap_or_else(|_| self.path.clone())
.to_string_lossy()
.as_bytes(),
);
hash.update(self.len().to_le_bytes());
hash.update(self.data_offset.to_le_bytes());
let mut tensors = self.tensors.iter().collect::<Vec<_>>();
tensors.sort_by_key(|(name, _)| *name);
for (name, tensor) in tensors {
hash.update(name.as_bytes());
hash.update(tensor.kind.to_le_bytes());
hash.update(tensor.offset.to_le_bytes());
hash.update(tensor.bytes.to_le_bytes());
for dimension in &tensor.dims {
hash.update(dimension.to_le_bytes());
}
}
hash.finalize().into()
}
pub(super) fn map_ptr(&self) -> *const u8 {
self.map.as_ptr()
}