code wiki / (root) / nxgguf.nx

nxgguf.nx

buildroot/runtime/nxgguf.nx

19854 B535 linesdepth 6pulls 6 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

nxgguf.nx -- Nishi sovereign tensor weight format. Replaces HuggingFace safetensors / GGUF with content-addressed, memory-mapped, dedupable weight blocks. Single-binary deploy of any model; instant cold-load via mmap; LoRAs share base weights at the storage layer. Format overview: [magic 4] = "NXGF" [version 4] = u32 LE, currently 1 [tensor_count 8] = u64 LE, total tensors [metadata_offset 8] = u64 LE, offset to metadata block [metadata_length 8] = u64 LE, byte length of metadata [block_table_offset 8] = u64 LE, offset to block dir [block_table_length 8] = u64 LE, byte length of block dir [data_offset 8] = u64 LE, where weight bytes start [reserved 16] = zeros = 64 bytes total header metadata block: protobuf-encoded TensorRegistry repeated TensorEntry { string name = 1; // "model.layers.0.attn.q.weight" repeated int64 shape = 2; // [512, 512] int32 dtype = 3; // 0=fp32 1=fp16 2=bf16 3=fp8 4=int8 5=int4 string block_hash = 4; // sha256 of the tensor's bytes int64 byte_length = 5; // raw byte count } block table: array of BlockDescriptor bytes hash (32) // sha256 uint64 file_offset ( 8) // where in file uint64 byte_length ( 8) uint32 ref_count ( 4) // # tensors pointing here uint32 reserved ( 4) = 56 bytes per block descriptor data section: concatenated raw weight bytes; tensor reads `block.byte_length` bytes starting at `block.file_offset`.

dependencies 2 imports · 0 importers

syscalls.nx sha256.nx nxgguf.nx

imports: syscalls.nxsha256.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main nxgguf_open read_u32_le read_u64_le nxgguf_total_bytes read_u64_le ↻ nxgguf_unique_blocks nxgguf_hash_block nxgguf_hash_eq nxgguf_writer_new nxgguf_writer_add nxgguf_hash_block ↻ nxgguf_writer_find_block nxgguf_hash_eq ↻ nxgguf_writer_finalize write_u64_le

structs

85struct NxgFile {
96struct NxgTensor {
108struct NxgBlockDesc {
256struct NxgWriter {

consts

55const NXGGUF_MAGIC: i64 = 0x4647584E
56const NXGGUF_VERSION: i64 = 1
57const NXGGUF_HEADER_BYTES: i64 = 64
58const NXGGUF_BLOCK_DESC_BYTES: i64 = 56
61const DTYPE_FP32: i64 = 0
62const DTYPE_FP16: i64 = 1
63const DTYPE_BF16: i64 = 2
64const DTYPE_FP8: i64 = 3 // E4M3
65const DTYPE_INT8: i64 = 4
66const DTYPE_INT4: i64 = 5 // group-quantized
67const DTYPE_INT2: i64 = 6 // for BitNet b1.58 + similar
68const DTYPE_TERN: i64 = 7 // ternary {-1, 0, 1} packed
253const NXG_MAX_BLOCKS: i64 = 4096
254const NXG_MAX_TENSORS: i64 = 4096

functions

71func dtype_bits(dt: i64) -> i64 {
118func read_u64_le(buf: *u8, off: i64) -> i64 {
128func read_u32_le(buf: *u8, off: i64) -> i64 {
called by 1: nxgguf_open
141func nxgguf_open(file: *NxgFile, base: *u8, length: i64) -> i64 {
called by 1: main calls 2: read_u32_leread_u64_le
166func nxgguf_total_bytes(file: *NxgFile) -> i64 {
called by 1: main calls 1: read_u64_le
180func nxgguf_unique_blocks(file: *NxgFile) -> i64 {
called by 1: main
195func nxgguf_hash_block(bytes: *u8, len: i64, out: *u8) -> i64 {
207func nxgguf_hash_eq(a: *u8, b: *u8) -> i64 {
221func nxgguf_find_block(file: *NxgFile, target_hash: *u8) -> i64 {
calls 1: nxgguf_hash_eq
273func nxgguf_writer_new(out_buf: *u8, out_cap: i64) -> *NxgWriter {
called by 1: main
295func nxgguf_writer_find_block(w: *NxgWriter, target_hash: *u8) -> i64 {
called by 1: nxgguf_writer_add calls 1: nxgguf_hash_eq
309func nxgguf_writer_add(w: *NxgWriter,
366func write_u64_le(out: *u8, off: i64, v: i64) -> i64 {
381func nxgguf_writer_finalize(w: *NxgWriter) -> i64 {
called by 1: main calls 1: write_u64_le
430func main() -> i64 {