Skip to main content

qualia_core_db/q42/p64_weight/
mod.rs

1//! Phase 4: AOT GGUF → `.p64` **LLM-weight container** compiler.
2//!
3//! A *sibling* of the semantic `.q42` graph format — it carries an **independent section magic** `b"p64\0"`
4//! so the two never collide. Per the architectural decision, the weights are stored as **opaque,
5//! cache-aligned (64-byte), contiguous quantized blobs**.
6//!
7//! The `NQuin` epistemic scaffold is removed from this probabilistic container. The 48-byte
8//! declarative `q42` system manages truth, while this 64-byte aligned `p64` system manages
9//! pure mathematical inference with zero-copy relative WASM pointers.
10//!
11//! Output is **little-endian** on every host via explicit serialization.
12//!
13//! Layout:
14//! ```text
15//! [ P64WeightHeader (64B) ]              magic, version, flags, 32-bit relative offsets
16//! [ P64TensorEntry[] (64B each) ]        role, dtype, rank, dims, relative blob offsets
17//! [ pad → 1<<page_log2 ]
18//! [ tensor blob region ]                 quantized bytes; each tensor START page-aligned
19//!                                        (default 16KB) for single-fetch mmap.
20//! ```
21
22mod compiler;
23mod etalon_adapter;
24mod layout;
25#[cfg(test)]
26mod migration_contract_tests;
27mod reader;
28#[cfg(test)]
29mod tests;
30mod transcode;
31// Historical tests for the pre-P64 Q42W layout are retained as migration
32// documentation only. They refer to the removed 144/80-byte API.
33#[cfg(all(test, any()))]
34mod legacy_tests;
35
36pub use compiler::*;
37pub use layout::*;
38pub use reader::*;
39pub use transcode::*;
40
41// Shared, crate-internal helpers used across the submodules above. They live in the parent
42// module so every child (compiler / transcode / reader / tests) can reach them unchanged,
43// while delegating neutral `.p64` layout & serialization mechanics to `etalon_model::p64`.
44
45#[inline]
46#[allow(dead_code)]
47fn write_manifold_coordinate(
48    coordinate: &crate::modalities::manifold::ManifoldCoordinate10D,
49    out: &mut [u8],
50) {
51    etalon_model::p64::P64ManifoldRecord::write_values_le(&coordinate.as_f32_array(), out);
52}
53
54#[inline]
55#[allow(dead_code)]
56fn write_tensor_entry(entry: &P64TensorEntry, out: &mut [u8]) {
57    entry.write_le(out);
58}