nxgguf.nx
buildroot/runtime/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: syscalls.nxsha256.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| 85 | struct NxgFile { |
| 96 | struct NxgTensor { |
| 108 | struct NxgBlockDesc { |
| 256 | struct NxgWriter { |
consts
| 55 | const NXGGUF_MAGIC: i64 = 0x4647584E |
| 56 | const NXGGUF_VERSION: i64 = 1 |
| 57 | const NXGGUF_HEADER_BYTES: i64 = 64 |
| 58 | const NXGGUF_BLOCK_DESC_BYTES: i64 = 56 |
| 61 | const DTYPE_FP32: i64 = 0 |
| 62 | const DTYPE_FP16: i64 = 1 |
| 63 | const DTYPE_BF16: i64 = 2 |
| 64 | const DTYPE_FP8: i64 = 3 // E4M3 |
| 65 | const DTYPE_INT8: i64 = 4 |
| 66 | const DTYPE_INT4: i64 = 5 // group-quantized |
| 67 | const DTYPE_INT2: i64 = 6 // for BitNet b1.58 + similar |
| 68 | const DTYPE_TERN: i64 = 7 // ternary {-1, 0, 1} packed |
| 253 | const NXG_MAX_BLOCKS: i64 = 4096 |
| 254 | const NXG_MAX_TENSORS: i64 = 4096 |
functions
| 71 | func dtype_bits(dt: i64) -> i64 { |
| 118 | func read_u64_le(buf: *u8, off: i64) -> i64 { |
| 128 | func read_u32_le(buf: *u8, off: i64) -> i64 {
called by 1: nxgguf_open |
| 141 | func nxgguf_open(file: *NxgFile, base: *u8, length: i64) -> i64 { |
| 166 | func nxgguf_total_bytes(file: *NxgFile) -> i64 { |
| 180 | func nxgguf_unique_blocks(file: *NxgFile) -> i64 {
called by 1: main |
| 195 | func nxgguf_hash_block(bytes: *u8, len: i64, out: *u8) -> i64 { |
| 207 | func nxgguf_hash_eq(a: *u8, b: *u8) -> i64 { |
| 221 | func nxgguf_find_block(file: *NxgFile, target_hash: *u8) -> i64 {
calls 1: nxgguf_hash_eq |
| 273 | func nxgguf_writer_new(out_buf: *u8, out_cap: i64) -> *NxgWriter {
called by 1: main |
| 295 | func nxgguf_writer_find_block(w: *NxgWriter, target_hash: *u8) -> i64 { |
| 309 | func nxgguf_writer_add(w: *NxgWriter, |
| 366 | func write_u64_le(out: *u8, off: i64, v: i64) -> i64 {
called by 1: nxgguf_writer_finalize |
| 381 | func nxgguf_writer_finalize(w: *NxgWriter) -> i64 { |
| 430 | func main() -> i64 { |