AppState now holds ports instead of concrete types: `engine: Option<SharedEngine>` replaces the mpsc::Sender<GenerationCommand>, `responses: SharedResponseStore` replaces Arc<RwLock<ResponseHistory>>, `clock: SharedClock` serves queue deadlines, uptime and response timestamps, `mcp` is a ToolHub and `vision` a VisionEncoder. The channel (adapters::ChannelEngine), the history with its disk snapshot (responses::HistoryResponseStore), the system clock, mcp::Hub and vision::Vision are the adapters; main.rs serve() composes them. No behaviour change: the HTTP handlers make the same calls in the same order, the queue claim race is unchanged, only the deadline now reads the injected clock. Ports are called per request, never per token or stream event (docs/architecture/gateway-ports.md). ports/fakes has an in-memory adapter per port; control-plane/tests/ports_fakes.rs (12 tests), queue.rs and adapters/channel_engine.rs add tests that drive the real handlers through them. Architecture gate: dyn-trait:strata-control fell 35 -> 21 (a BoxError alias replaces 20 `Box<dyn Error>` spellings, which pays for the 6 new port aliases); main.rs 1156 -> 1155 lines. Also adds scripts/dev/test-outcomes.py (per-test outcome comparison of two cargo test logs) and scripts/dev/wsl-cargo.sh.
90 lines
2.3 KiB
Rust
90 lines
2.3 KiB
Rust
//! Native GGUF serving-pack preparation. Quantized tensors remain in source
|
|
//! shards; float conversions are exact unless `--compat-bf16` is given. No runtime Python.
|
|
use std::{
|
|
collections::{BTreeMap, HashSet},
|
|
fs::{self, File},
|
|
io::{Read, Seek, SeekFrom, Write},
|
|
path::{Path, PathBuf},
|
|
};
|
|
|
|
use serde_json::json;
|
|
use sha2::{Digest, Sha256};
|
|
|
|
use crate::{gguf, gguf_f32_stream, kar_codec, model, tokenizer, tokenizer_assets};
|
|
|
|
type Result<T> = std::result::Result<T, crate::BoxError>;
|
|
|
|
struct Shard {
|
|
path: PathBuf,
|
|
index: gguf::TensorIndex,
|
|
}
|
|
|
|
struct Layout<'a> {
|
|
text: String,
|
|
n_expert: u64,
|
|
total: u64,
|
|
/// Per layer: the gate, up and down tensors with the index of the shard holding each.
|
|
layers: Vec<[(usize, &'a gguf::TensorInfo); 3]>,
|
|
}
|
|
|
|
/// Running comparison of converted values with their sources, as `iq_pack.convert` reports it.
|
|
struct Error64 {
|
|
exact: bool,
|
|
max_abs_err: f64,
|
|
}
|
|
|
|
struct Record {
|
|
name: String,
|
|
shard: String,
|
|
src_type: &'static str,
|
|
dst_type: &'static str,
|
|
method: String,
|
|
exact: bool,
|
|
max_abs_err: f64,
|
|
source_sha256: String,
|
|
}
|
|
|
|
struct Converted {
|
|
/// Index `kind` column.
|
|
index_kind: u32,
|
|
written: u64,
|
|
dst: u64,
|
|
/// `(method, exact, max_abs_err)` when `conversions.json` lists the tensor.
|
|
record: Option<(String, bool, f64)>,
|
|
source_sha256: String,
|
|
}
|
|
|
|
/// Optional parts of `tools/iq_pack.py` beyond the exact default pack.
|
|
#[derive(Clone, Debug, Default)]
|
|
pub struct Options {
|
|
/// Dequantize/round the small projections the engine reads as BF16/F16/F32 (`--compat-bf16`).
|
|
pub compat_bf16: bool,
|
|
/// Also write `experts.bin` and its `experts.bin.src.json` sidecar (`--experts-bin`).
|
|
pub experts_bin: bool,
|
|
/// Reuse the float tensors of a canonical base pack (`--base`): `index.txt` and `extra.bin` are derived from
|
|
/// it, `dense.bin` is linked.
|
|
pub base: Option<PathBuf>,
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests;
|
|
|
|
mod safe_name;
|
|
#[allow(unused_imports)]
|
|
pub use safe_name::*;
|
|
mod expert_layout;
|
|
#[allow(unused_imports)]
|
|
pub use expert_layout::*;
|
|
mod convert_tensor;
|
|
#[allow(unused_imports)]
|
|
pub use convert_tensor::*;
|
|
mod dense_files;
|
|
#[allow(unused_imports)]
|
|
pub use dense_files::*;
|
|
mod conversions_inexact;
|
|
#[allow(unused_imports)]
|
|
pub use conversions_inexact::*;
|
|
mod same_bytes;
|
|
#[allow(unused_imports)]
|
|
pub use same_bytes::*;
|