code wiki / (root) / nx_nxgguf.nx

nx_nxgguf.nx

buildroot/runtime/nx_nxgguf.nx

19764 B544 linesdepth 5pulls 5 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

nx_syscalls.nx nx_sha256.nx nx_nxgguf.nx

imports: nx_syscalls.nxnx_sha256.nx

imported by: nobody (leaf or entry point)

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

main sys_mmap nxgguf_open read_u32_le read_u64_le nxgguf_total_bytes read_u64_le ↻ nxgguf_unique_blocks nxgguf_hash_block sys_mmap ↻ sha256_init sys_mmap ↻ sha256_k sha256_update sha256_compress_ni_blocks blk_set_byte sha256_compress sha256_compress_ni blk_word blk_byte sha256_final blk_set_byte ↻ sha256_compress ↻ nxgguf_hash_eq nxgguf_writer_new sys_mmap ↻ nxgguf_writer_add sys_mmap ↻ nxgguf_hash_block ↻ nxgguf_writer_find_block nxgguf_hash_eq ↻ nxgguf_writer_finalize write_u64_le

structs

91struct NxgFile
102struct NxgTensor
114struct NxgBlockDesc
265struct NxgWriter

consts

61const NXGGUF_MAGIC: i64 = 0x4647584E
62const NXGGUF_VERSION: i64 = 1
63const NXGGUF_HEADER_BYTES: i64 = 64
64const NXGGUF_BLOCK_DESC_BYTES: i64 = 56
67const DTYPE_FP32: i64 = 0
68const DTYPE_FP16: i64 = 1
69const DTYPE_BF16: i64 = 2
70const DTYPE_FP8: i64 = 3 // E4M3
71const DTYPE_INT8: i64 = 4
72const DTYPE_INT4: i64 = 5 // group-quantized
73const DTYPE_INT2: i64 = 6 // for BitNet b1.58 + similar
74const DTYPE_TERN: i64 = 7 // ternary {-1, 0, 1} packed
199const NXGGUF_MAGIC_8192: i64 = 8192
200const NXGGUF_MAGIC_1024: i64 = 1024
201const NXGGUF_MAGIC_65536: i64 = 65536
262const NXG_MAX_BLOCKS: i64 = 4096
263const NXG_MAX_TENSORS: i64 = 4096

functions

77func dtype_bits(dt: i64) -> i64
124func read_u64_le(buf: *u8, off: i64) -> i64
134func read_u32_le(buf: *u8, off: i64) -> i64
called by 1: nxgguf_open
147func nxgguf_open(file: *NxgFile, base: *u8, length: i64) -> i64
called by 1: main calls 2: read_u32_leread_u64_le
172func nxgguf_total_bytes(file: *NxgFile) -> i64
called by 1: main calls 1: read_u64_le
186func nxgguf_unique_blocks(file: *NxgFile) -> i64
called by 1: main
204func nxgguf_hash_block(bytes: *u8, len: i64, out: *u8) -> i64
216func nxgguf_hash_eq(a: *u8, b: *u8) -> i64
230func nxgguf_find_block(file: *NxgFile, target_hash: *u8) -> i64
calls 1: nxgguf_hash_eq
282func nxgguf_writer_new(out_buf: *u8, out_cap: i64) -> *NxgWriter
called by 1: main calls 1: sys_mmap
304func nxgguf_writer_find_block(w: *NxgWriter, target_hash: *u8) -> i64
called by 1: nxgguf_writer_add calls 1: nxgguf_hash_eq
318func nxgguf_writer_add(w: *NxgWriter,
375func write_u64_le(out: *u8, off: i64, v: i64) -> i64
390func nxgguf_writer_finalize(w: *NxgWriter) -> i64
called by 1: main calls 1: write_u64_le
439func main() -> i64