code wiki / _hdl_build / nx_vram_budget.nx
nx_vram_budget.nx
buildroot/runtime/_hdl_build/nx_vram_budget.nx
about
nx_vram_budget.nx -- the team's VRAM FOOTPRINT model + reducer (operator: reduce VRAM while
MEETING/improving functionality). Rule #21 (Resource Awareness) made executable: know the budget,
account for EVERY component, and find the smallest config that still clears the quality floor.
RESEARCHED breakdown (not hand-waved): VRAM = weights + KV cache + activations + overhead.
weights: n_params * weight_bits / 8. Quantize -> 4x (Q4) at ~1.2% perplexity.
KV cache: 2(K+V) * layers * kv_heads * head_dim * seq * batch * kv_bits / 8. GROWS with context
and at long context can RIVAL the weights. Most quantizers IGNORE it (leave it fp16).
Q8 KV = 2x smaller at <0.1% loss; GQA (kv_heads << query_heads) = up to 8x smaller.
activations + overhead: transient buffers + fragmentation (add ~15%).
The reducer answers "reduce VRAM while meeting functionality" = MINIMISE footprint s.t. the total
quality loss stays within the Council floor (quality favoured). Sizes in MB (params in millions).
license_tier: ORIGINAL Refs: KV cache formula (Lyceum/HF); KV quant Q8<0.1% loss (TechPlained).
dependencies 1 imports · 2 importers
imports: nx_syscalls.nx
imported by: nx_vram_budget_test.nxnx_vram_frontier.nx
structs
| none |
consts
| 16 | const VRAM_MAGIC_1000000: i64 = 1000000 |
| 18 | const VRAM_RTX5080_GB: i64 = 16 // the operator's real budget (rule #21) |
functions
| 21 | func vram_weights_mb(params_m: i64, bits: i64) -> i64 { return (params_m * bits) / 8 } |
| 25 | func vram_kv_mb(layers: i64, kv_heads: i64, head_dim: i64, seq: i64, batch: i64, bits: i64) -> i64 |
| 32 | func vram_total_mb(weights_mb: i64, kv_mb: i64, act_mb: i64, overhead_pct: i64) -> i64 called by 1: vram_config_mb |
| 37 | func vram_fits(total_mb: i64, budget_gb: i64) -> i64 { if total_mb <= budget_gb * 1000 { return 1 } return 0 } |
| 41 | func vram_weight_loss(bits: i64) -> i64 { if bits >= 16 { return 0 } if bits >= 8 { return 1 } return 12 } called by 1: vram_best_config |
| 42 | func vram_kv_loss(bits: i64) -> i64 { if bits >= 16 { return 0 } if bits >= 8 { return 1 } return 35 } called by 1: vram_best_config |
| 45 | func vram_config_mb(params_m: i64, layers: i64, kv_heads: i64, head_dim: i64, seq: i64, batch: i64, act_mb: i64, overhead: i64, w_bits: i64, kv_bits: i64) -> i64 |
| 55 | func vram_best_config(params_m: i64, layers: i64, kv_heads: i64, head_dim: i64, seq: i64, batch: i64, act_mb: i64, overhead: i64, budget_gb: i64, floor: i64, out: *i64) -> i64 |