Files
leleka/control-plane/src/native_pack.rs
T
Pavlo Ratushnyi d9c0c87dcf Narrow the dead glob re-exports of the module splits: pub use x::* becomes use x::* or pub(crate) use x::* (STRA-338)
Where the split left pub use x::* over items that no outside module can name, the compiler said the glob re-exports nothing pub. The glob now has the visibility its items really have: plain use where they are pub(self), pub(crate) where siblings reach them (model.rs file_download, libc-shim launch_interposers). One glob of backend-api scripted.rs was dead and is deleted. 7 globs of control-plane stay with their allow: the compiler calls them unused in the lib build and the lib test build of control-plane cannot be built on Windows, so a test use cannot be ruled out.

cargo check --all-targets on backend-api, control-plane, gateway-domain, gateway-text and libc-shim: no new warning, no new error (the one control-plane lib test error is the pre-existing std::os::unix use).
2026-11-24 08:51:58 +01:00

86 lines
2.2 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 pack_rules;
use pack_rules::*;
mod expert_layout;
use expert_layout::*;
mod convert_tensor;
use convert_tensor::*;
mod dense_files;
use dense_files::*;
mod pack_publication;
pub use pack_publication::*;
mod pack_outputs;
pub use pack_outputs::*;
mod same_bytes;
use same_bytes::*;