scripts/dev/split_module.py (lexer-based, with 16 self-tests) moves the top-level fn and impl items of 59 oversize module files in control-plane, desktop-core, model-format, gateway-text, leleka-memory, experimental-ref, context, serving-policy, tokenizer, backend-api, quant-core, harmony, igpu, libc-shim, npu-service and runtime-client into foo/<name>.rs groups of about 250 lines; types, constants, macros, nested modules and tests stay, every path stays valid through pub use re-exports, restricted visibilities keep their scope one level down, include paths and super:: paths are shifted. Not touched: leleka-runtime, cuda-driver, native-cpu-expert, sampler-ref and cpu-* (hot path, next wave) and the files kar-off-ab edits. The baseline drops from 311 to 263 oversize files and from 273,600 to about 233,000 lines; the path-include ratchet ignores dir/name.rs child declarations.
103 lines
2.2 KiB
Rust
103 lines
2.2 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::*;
|