nx_nxgguf.nx
buildroot/runtime/nx_nxgguf.nx
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
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
structs
| 91 | struct NxgFile |
| 102 | struct NxgTensor |
| 114 | struct NxgBlockDesc |
| 265 | struct NxgWriter |
consts
| 61 | const NXGGUF_MAGIC: i64 = 0x4647584E |
| 62 | const NXGGUF_VERSION: i64 = 1 |
| 63 | const NXGGUF_HEADER_BYTES: i64 = 64 |
| 64 | const NXGGUF_BLOCK_DESC_BYTES: i64 = 56 |
| 67 | const DTYPE_FP32: i64 = 0 |
| 68 | const DTYPE_FP16: i64 = 1 |
| 69 | const DTYPE_BF16: i64 = 2 |
| 70 | const DTYPE_FP8: i64 = 3 // E4M3 |
| 71 | const DTYPE_INT8: i64 = 4 |
| 72 | const DTYPE_INT4: i64 = 5 // group-quantized |
| 73 | const DTYPE_INT2: i64 = 6 // for BitNet b1.58 + similar |
| 74 | const DTYPE_TERN: i64 = 7 // ternary {-1, 0, 1} packed |
| 199 | const NXGGUF_MAGIC_8192: i64 = 8192 |
| 200 | const NXGGUF_MAGIC_1024: i64 = 1024 |
| 201 | const NXGGUF_MAGIC_65536: i64 = 65536 |
| 262 | const NXG_MAX_BLOCKS: i64 = 4096 |
| 263 | const NXG_MAX_TENSORS: i64 = 4096 |
functions
| 77 | func dtype_bits(dt: i64) -> i64 |
| 124 | func read_u64_le(buf: *u8, off: i64) -> i64 |
| 134 | func read_u32_le(buf: *u8, off: i64) -> i64 called by 1: nxgguf_open |
| 147 | func nxgguf_open(file: *NxgFile, base: *u8, length: i64) -> i64 |
| 172 | func nxgguf_total_bytes(file: *NxgFile) -> i64 |
| 186 | func nxgguf_unique_blocks(file: *NxgFile) -> i64 called by 1: main |
| 204 | func nxgguf_hash_block(bytes: *u8, len: i64, out: *u8) -> i64 |
| 216 | func nxgguf_hash_eq(a: *u8, b: *u8) -> i64 |
| 230 | func nxgguf_find_block(file: *NxgFile, target_hash: *u8) -> i64 calls 1: nxgguf_hash_eq |
| 282 | func nxgguf_writer_new(out_buf: *u8, out_cap: i64) -> *NxgWriter |
| 304 | func nxgguf_writer_find_block(w: *NxgWriter, target_hash: *u8) -> i64 |
| 318 | func nxgguf_writer_add(w: *NxgWriter, |
| 375 | func write_u64_le(out: *u8, off: i64, v: i64) -> i64 called by 1: nxgguf_writer_finalize |
| 390 | func nxgguf_writer_finalize(w: *NxgWriter) -> i64 |
| 439 | func main() -> i64 |