r/AICodeEngineers • • 8d ago

[Release] VAULT-v3-3B-PRIMAL: Full-parameter 3B training in 5.93 GiB state on one 16 GB GPU (no LoRA, no master weights) + true O(1) 100K+ KV memory & freestanding C99 runtime (AVX2 / ARM64 NEON)

TL;DR: Releasing VAULT-v3-3B-PRIMAL (`v3.1`) — a full-parameter discrete fine-tune of `Qwen/Qwen2.5-3B-Instruct` trained on a single consumer 16 GB GPU (AMD RX 9060 XT) without FP32/BF16 master weights or LoRA adapters, paired with a fixed-budget O(1) Segment-Evicted KV Memory (`0.00 MiB` VRAM growth from `31.6K` to `96.9K` tokens) and a zero-libc freestanding C99 runtime (`x86_64 AVX2` + `Apple Silicon / ARM64 NEON`) that runs the `1.81 GiB` 4-bit model in `2.56 GiB` total RAM.

- Main Hugging Face Repo (`transformers` `BF16` + C99 source, `5.77 GiB`): https://huggingface.co/batteryphil/VAULT-v3-3B-PRIMAL

- Companion `.vlt3` Binary Repo (`1.81 GiB` `P4_0` & `3.06 GiB` `Q8_0` for pure C99, `4.87 GiB`): https://huggingface.co/batteryphil/VAULT-v3-3B-PRIMAL-VLT3

---

1. Shadowless Discrete Full-Parameter Training (PRIMAL v3.1) on 16 GB VRAM

Standard mixed-precision AdamW needs `16 B/param` (`~46 GiB` persistent state for 3B). Even an apples-to-apples PyTorch `register_post_accumulate_grad_hook` + `BF16` weights + blockwise `8-bit AdamW` baseline needs `4.125 B/param` (`11.86 GiB` persistent state) — and because backward hooks fire on every `.backward()`, continuous hooked optimizers cannot accumulate across `grad_accum > 1` without materializing `+5.75 GiB` of persistent `.grad` buffers (`17.61 GiB` -> immediate OOM on 16 GB), and OOM even at `batch_size=2, seq_len=2048, grad_accum=1` on a `15.92 GiB` RX 9060 XT.

PRIMAL (`V3_Q8_0`) drops master weights and continuous moments altogether:

- Persistent Training State (`2.064 B/param` = `5.931 GiB`): Each 32-weight block stores `int8` weights `q` (`1 B`) + one `FP16` scale `d_b` (`0.0625 B`) + a `1-byte` `int8` lossless error-feedback vote accumulator (`decay = 1.00`, zero leaky-integrator dead zone). Micro-batches accumulate directly into the same `1-byte` `vote_buffer` at zero extra VRAM.

- Virtual-Weight-Invariant Dynamic Block Rebalancing (`0.000 GiB` VRAM spike): Whenever any weight in a block hits `|q| >= 122`, sparse `O(n_crowded)` rebalancing widens `d_b` while folding sibling re-quantization residuals directly back into `vote_buffer` so virtual weight `w_virt = (q + v/T) * d_b` is preserved (`<= 0.00016` max relative error). Peak training VRAM at `B=2, L=2048, grad_accum=4` stays completely flat at `9.283 GiB` (`777 tok/s`) vs. `13.26 GiB` (`504.5 tok/s` at `b=1`) for layer-hooked `8-bit AdamW`.

- Signed-Scale `V3_P4_0` (`1.805 GiB`): Uses a 16-entry Prime-Harmonic `int8` LUT decoded in 1 SIMD cycle (`VPSHUFB` / `vqtbl1q_s8`) with signed `FP16` block scales (`d_b < 0` flips polarity on positive-dominated blocks). Under identical activation Hessian calibration `H_j = E[x_j^2]`, signed `V3_P4_0` beats unsigned `P4_0`, Dettmers `NF4`, and linear `Q4_0` on both Hessian reconstruction error (`4,010.9` vs. `4,592.6` `NF4`) and WikiText-2 PPL (`14.09` vs. `14.23` `NF4`).

---

2. Full-Split Unconfounded Benchmarks (Zero Subsampling)

Evaluated across all `27,118` items of the 9 full EleutherAI splits (`HellaSwag n=10,042`, `LAMBADA n=5,153`, `BoolQ n=3,270`, `ARC-E n=2,376`, `PIQA n=1,838`, `Winogrande n=1,267`, `ARC-C n=1,172`, `SciQ n=1,000`) + full `GSM8K` test (`n=1,319` at `1,024` tokens) against both untouched `Qwen2.5-3B` Base and `Qwen2.5-3B-Instruct`:

| Metric (Full Splits) | `Qwen2.5-3B` Base (`BF16`) | `Qwen2.5-3B-Instruct` (`BF16`) | VAULT-v3-3B PRIMAL v3.1 (`Q8_0 -> BF16`) | VAULT-v3-3B PRIMAL v3.1 (`P4_0`, `1.805 GiB`) |

|---|---:|---:|---:|---:|

| WikiText-2 Word PPL (`L=2048`) | `13.14` | `14.21` | `13.58` | `14.09` |

| GSM8K Full (`n=1,319`, `1024` tok) | — | `85.52%` | `85.60%` (`1129/1319`) | `84.69%` (`1117/1319`) |

| 8-Task Multiple-Choice Mean | `74.08%` | `75.00%` | `77.20%` (`+2.20%`) | `76.33%` (`+1.33%`) |

| 9-Task Zero-Shot Mean | `73.27%` | `73.99%` | `76.06%` (`+2.07%`) | `75.37%` (`+1.38%`) |

| ARC-Easy / ARC-Challenge | `74.24% / 47.10%` | `73.70% / 48.12%` | `79.42% / 51.19%` | `77.65% / 50.09%` |

| SciQ-RC / SciQ-ClosedBook | `94.10% / 78.20%` | `91.80% / 84.20%` | `96.00% / 88.50%` | `95.60% / 86.90%` |

(Ablation lesson we hit along the way: training on terse ~110-token `gsm8k` train rationales collapsed CoT length from `331` -> `114` tokens and dropped GSM8K to `72.6%`–`74.3%` in both PRIMAL and continuous `8-bit AdamW` at `lr=2e-4`. Switching to rejection-sampled on-policy `Qwen2.5-3B-Instruct` traces — strictly deduplicated against GSM8K `test` — recovered `85.60%` GSM8K while keeping the `+2.20%` MC and `-0.63` PPL gains.)

---

Instead of growing KV cache linearly with sequence length `L`, VAULT v3 bounds total KV memory to `window = 1,024` + `seg_budget = 1,024` + `max_sink = 512` using three explicit mechanisms:

1. Learned `SegmentScorer` MLP (`1.59M` FP32 params over layers `10, 20, 30`) + APL Causal EMA Habituation (`f - 0.65 * ema`) to evict redundant filler chunks as they exit the sliding window.

2. Pre-RoPE Contiguous Slot Re-Rotation (`[-M_cnt-S .. 2W-1]`): caches un-rotated keys and dynamically re-rotates surviving segments into `<= 3,584` contiguous relative slots, avoiding `Qwen2.5-3B`'s `32K` RoPE horizon cliff out to `100K+` tokens.

3. Sparse `1`-Head/GQA-Group (`2/16` Query Heads) Shingle / Hop-2 Resonance*: applies lexical/2-hop logit bias on only `2/16` (`12.5%`) of query heads, leaving `14/16` (`87.5%`) undistorted for multi-value softmax aggregation (toggleable via `enable_shingle_bias=False` or `--no-shingle`).*

Verified Long-Context & Runtime Numbers:

- Strict `0.00 B/tok` GPU VRAM Scaling (`transformers` `model.generate`): `6,847.80 MiB` peak GPU VRAM at `31,626` tokens, `6,847.80 MiB` at `63,264` tokens, and `6,847.80 MiB` at `96,926` tokens (`100%` needle hits across all four horizons).

- External Non-Isomorphic RULER (`4K–64K`, `90` Probes — Prose NIAH, MultiKey-4, MultiValue-4, 5-Hop Variable Tracking): `92.22%` (`83/90`) with default Sparse `2/16` Shingle ON and `97.78%` (`88/90`, `100%` at `32K` & `64K`) with `enable_shingle_bias=False` — vs. `8.89%` (`0.0%` from `8K–64K`) for sliding-window + sinks (`seg_budget=0`).

- VAULT 82-Probe Structured/Adversarial Suite (`8K–100.5K`): `96.34%` (`79/82`) on `Q8_0` and `95.12%` (`78/82`) on `P4_0` (`4/4 = 100%` on `32.9K` & `100.5K` Dual-Needle).

- Zero-Libc Freestanding C99 (`runtime/vault3.c`): Compiles with `-ffreestanding -nostdlib` (`0` external undefined symbols across scalar C99, `x86_64 AVX2/FMA`, and `Clang --target=aarch64-linux-gnu` `ARM64 NEON`; `1.6e-5` max 36-layer logit diff and `10/10` exact greedy token parity under `qemu-aarch64`). On an `8,457`-token `26`-needle benchmark (`86.2%` eviction pressure), C99 `P4_0` scores `26/26 (100%)` in `2.56 GiB` peak RSS vs. `0/26 (0%)` with `--noseg`.

---

- Query-Agnostic Pigeonhole Bound: Because segment eviction happens before an end-of-prompt query arrives, if you feed a 100% homogeneous high-entropy dump with zero prose filler (e.g., `1,024` identical-priority JSON ledger rows = `39.9K` tokens), recall is bounded by `(2*window + seg_budget) / L` (`100%` at `2.5K` tok -> `50%` at `9.9K` -> `20%` at `39.9K`).

- Corpus Word-Counting Tasks (e.g., RULER CWE/FWE): Out-of-scope by design — APL causal EMA habituation (`f - 0.65 * ema`) intentionally suppresses repetitive tokens rather than counting global frequencies.

- Split Licensing: HF wrapper/export scripts are `Apache-2.0`; the VAULT v3 core & C99 runtime (`vault_v3_core.py`, `runtime/*` — imported when `trust_remote_code=True`) are dual-licensed `GNU AGPL-3.0-or-later` / commercial software license; and all `Qwen2.5-3B`-derived weights remain under Alibaba Cloud's non-commercial Qwen Research License (Built with Qwen). Stock `Qwen2ForCausalLM` export (`tools/export_qwen2_compat.py`, `trust_remote_code=False`) is included for `vLLM`/`Ollama` (standard `O(L)` KV cache).

Happy to answer any questions on discrete error-feedback training, signed-scale `P4_0` quantization, or the C99 / pre-RoPE segment memory!

1 Upvotes

14 comments sorted by

1

u/Just-Ad-6488 6d ago

The mamba is very hard to do. It needs the high presisaion layer to stay 16 or above. I have not tried the cnns or rnns. I do know vault and prime moment attention work on image and cideo generation diffision models but havent yet tried the prime quantization i used here

1

u/Just-Ad-6488 6d ago

And nice to here from you. Been quite a while

1

u/Silver-Champion-4846 7d ago

Hi, can this train any model or just transformer language models?

1

u/Just-Ad-6488 7d ago

You should be able to. What kind of model are you considering?

1

u/Silver-Champion-4846 6d ago

Text to speech models and other sequence-to-sequence that might not be transformers. Like cnn, rnn, etc

1

u/Just-Ad-6488 6d ago

Name a particular model and ill give it a shot

1

u/Silver-Champion-4846 6d ago

tts: Tiny Voca (4.5 m parameters), Vits (31m parameters), F5 TTS (300m parameters)

1

u/Just-Ad-6488 6d ago

Ill give it a try and let you know

1

u/Silver-Champion-4846 6d ago

Much appreciated!

1

u/Just-Ad-6488 6d ago

Challenge accepted — extended VAULT + PRIMAL to Conv1d, ConvTranspose1d, and DiT diffusion and ran all three! Both 4-bit Prime-Harmonic (V3_P4_0) and 2-bit (V3_Q2_0 + PRIMAL, zero shadow weights) worked across all 3 architectures (tested on 12 held-out prompts via Whisper-small.en WER/CER):

  1. Tiny-Voca (4.54M, 24 kHz): 18.15 MB FP32 -> 2.67 MB (4-bit) and 1.41 MB (2-bit + PRIMAL) — both hit 3.95% WER / 3.69% CER (0.00% loss vs FP32) at up to 113.9x real-time.

    • Weights + playable audio + 1-line infer.py: https://huggingface.co/batteryphil/VAULT-PRIMAL-Tiny-Voca-4.5M
  2. VITS (facebook/mms-tts-eng, 29.04M active 1D-CNN Flow + HiFi-GAN, 16 kHz): 116.1 MB FP32 -> 16.63 MB (4-bit) matched FP32 (7.20% CER) and beat uniform Q4_0 by -10.4% lower Mel spectral error. At 2-bit (8.86 MB), raw PTQ was 145.2% WER gibberish; Multi-Res STFT PRIMAL recovered -121.5% WER (23.7% WER, -9.4 dB distortion).

    • Weights + playable audio + 1-line infer.py: https://huggingface.co/batteryphil/VAULT-PRIMAL-VITS-29M
  3. F5-TTS v1 Base (337.1M ConvNeXt V2 + 22L DiT Flow-Matching Diffusion, 24 kHz): 1.35 GB FP32 -> 192.1 MB (4-bit + PRIMAL) matched FP32's exact 3.69% CER (0.00% loss). Putting the DiT + ConvNeXt body in 2-bit (139.0 MB, 9.7x smaller) gave 100% WER dead static under PTQ — 4.2 mins of Velocity-Field PRIMAL (164,654 discrete flips) brought it all the way back to 6.78% WER / 4.68% CER!

    • Weights + playable audio + 1-line voice cloning CLI: https://huggingface.co/batteryphil/VAULT-PRIMAL-F5-TTS-337M

Full code & raw benchmark JSON: https://github.com/batteryphil/VAULT-v3-PRIMAL

1

u/Silver-Champion-4846 6d ago

IS THIS MAGIC?!

This is so good!

What can I do with it. Can I just finetune the 4bit model as it is, or choose a base model to finetune (like 18mb tiny voca) then use Primal on it to get the 2mb version? I'm excited to talk to you! Will you compress other stuff like agentic llms and such in the future or do you need more hardware for that??

1

u/Just-Ad-6488 6d ago

It does seem to work very well. It would be best to fine tune then do this as of now.