Files
leleka/control-plane/src/prepare_preview.rs
T

111 lines
2.4 KiB
Rust

//! Small, explicitly lossy F32 GGUF-to-KAR integration path. It exercises the
//! native acquisition/index/codec/writer chain without claiming target-model
//! support or a quality-approved serving configuration.
use std::{
fs::{self, File},
io::{BufWriter, Read, Seek, SeekFrom, Write},
path::{Path, PathBuf},
};
use sha2::{Digest, Sha256};
use crate::{
derived_iq3, derived_mixed, gguf, gguf_f32_stream, iq3_s, kar, kar_codec, kar_sample,
kar_stream_encode, kar_writer,
model::{self, Manifest},
stream_parts,
};
const MAX_SOURCE_BYTES: u64 = 64 * 1024 * 1024;
const MAX_TENSORS: usize = 1000;
const MAX_TENSOR_ELEMENTS: u64 = 1_000_000;
#[derive(Clone, Copy)]
enum PreviewKind {
F32,
Iq3,
Mixed,
}
enum DerivedIdentity {
Iq3(derived_iq3::Identity),
Mixed(derived_mixed::Identity),
}
struct DerivedTensorRef<'a> {
name: &'a str,
source_kind: u32,
source_digest: &'a [u8; 32],
f32_digest: &'a [u8; 32],
offset: u64,
bytes: u64,
}
#[derive(Debug)]
pub struct PreviewSummary {
pub archive: kar::Summary,
pub archive_digest: [u8; 32],
pub maximum_relative_l2: f64,
pub tensor_distortions: Vec<TensorDistortion>,
pub provenance_path: Option<PathBuf>,
}
#[derive(Debug)]
pub struct TensorDistortion {
pub name: String,
pub relative_l2: f64,
pub source_kind: u32,
pub section_bytes: u64,
}
struct PreparedTensor {
name: String,
dims: Vec<u64>,
source_digest: [u8; 32],
source_offset: u64,
section_path: PathBuf,
section_bytes: u64,
section_digest: [u8; 32],
}
struct StreamedTensor {
prepared: PreparedTensor,
nested: bool,
}
struct StagingDir(PathBuf);
#[cfg(test)]
mod tests;
mod minimum_part_payload_bytes;
#[allow(unused_imports)]
pub use minimum_part_payload_bytes::*;
mod prepare_sharded;
#[allow(unused_imports)]
pub use prepare_sharded::*;
mod prepare_sharded_streamed_with_policy;
#[allow(unused_imports)]
pub use prepare_sharded_streamed_with_policy::*;
mod spool_raw_f32;
#[allow(unused_imports)]
pub use spool_raw_f32::*;
mod prepare;
#[allow(unused_imports)]
pub use prepare::*;
mod encode_preview_tensor;
#[allow(unused_imports)]
pub use encode_preview_tensor::*;
mod verify_derived;
#[allow(unused_imports)]
pub use verify_derived::*;
mod preview_common;
use preview_common::*;
mod sharded_encode;
use sharded_encode::*;
mod streamed_encode;
use streamed_encode::*;
mod verify_sharded_parts;
use verify_sharded_parts::*;