8000 GitHub - VizuaraAI/4bit-training-b200: End-to-end 4-bit training tested on one NVIDIA B200: real NVFP4 forward and FP8 backward GEMMs inside PyTorch, quantize kernels, TinyStories runs and results · GitHub
[go: up one dir, main page]

Skip to content

About

End-to-end 4-bit training tested on one NVIDIA B200: real NVFP4 forward and FP8 backward GEMMs inside PyTorch, quantize kernels, TinyStories runs and results

Resources

Stars

4 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

4-bit training, tested on one NVIDIA B200

Code and results for 4-Bit Training, Tested on a Real B200, a first-principles walk through Thinking Machines' article End-to-End 4-Bit Training (Jack Cook and Thinking Machines Lab, November 2026) and a test of its recipe on real hardware.

The recipe: do the forward pass of the big linear layers with 4-bit multiplies (NVFP4), and the backward pass with 8-bit multiplies whose operands are re-quantized with stochastic rounding. Here the multiplies are real tensor-core GEMMs on a B200, called from PyTorch.

Results (one B200 rented from Modal, 15 November 2026)

840M-parameter GPT, TinyStories, 2,000 steps training time final validation loss
PyTorch BF16 (two seeds) 333 s, 339 s 1.6886, 1.6873
real 8-bit forward and backward 274 s 1.6861
real 4-bit forward, 8-bit backward (two seeds) 262 s, 256 s 1.6912, 1.6910
the same, backward rounded to nearest 258 s 1.6904
  • One full training step against PyTorch BF16, timed back to back on one GPU: 1.18x faster at width 2,048, 1.28x at 4,096, 1.38x at 8,192 (3.3 billion parameters). Against the all-8-bit run: 1.006x, 1.013x, 1.035x.
  • A single NVFP4 GEMM is 3.6x faster than BF16 at width 8,192.
  • The real NVFP4 GEMM matches the reference arithmetic in q4.py to 6 parts in 100 million.
  • Quantize kernels written with Blackwell's conversion instructions are 2 to 5x faster than the same kernels written with compares, shifts and masks.

Every number in the article comes from the JSON files in results/.

Files

File What it is
fb.cu A small C/CUDA library: cuBLASLt GEMMs (BF16, FP8, NVFP4) on raw device pointers, and the quantize kernels in two versions (software rounding, and Blackwell's conversion instructions). Compiled with nvcc inside the container.
real.py Loads fb.cu into PyTorch with ctypes; the MLP layer with its custom backward pass; the wide GPT; and the Modal functions behind every result: probe, kprobe, bench, profile, train_real, analyze_real, detcheck, specs.
q4.py Every format (E2M1, E4M3, NVFP4, MXFP8, S2F6, the random Hadamard transform) in about 200 lines of plain PyTorch, with a self-test. This is the reference arithmetic.
train.py Downloads and tokenizes TinyStories (prep). It also holds an earlier small-model experiment that simulates the formats on any GPU; the article does not use it.
mo.py A launcher for Modal.
results/ probe.json, kprobe.json, bench.json, profile.json, real/*.json (training runs), analysis.json, specs.json.

Running it

You need a Modal account with access to a B200. Nothing runs on your own machine except the launcher.

pip install modal
python3 mo.py modal deploy train.py
python3 mo.py call prep                       # download and tokenize TinyStories once
python3 mo.py modal deploy real.py
export FOURBIT_APP=fourbit-real
python3 mo.py call probe                      # hardware against arithmetic, first timings
python3 mo.py call kprobe                     # software kernels against conversion-instruction kernels
python3 mo.py call bench                      # full training steps at three widths
python3 mo.py spawn train_real arm=nvfp4 d=4096 steps=2000 lr=0.0002

arm is bf16, fp8, nvfp4 or nvfp4_rtn. A width-4,096 run takes four to six minutes of B200 time.

How these runs differ from the article's recipe

  • The backward pass uses FP8 (E4M3) with one scale per tensor, not MXFP8 with a power-of-two scale per 32 values.
  • Activations get one outer scale per tensor, not one per token.
  • Tensor scales are measured every step for the first 24 steps and every 8th step after that, and used with headroom.
  • No Four Over Six. One GPU, so no dispatch or combine between GPUs.
  • The GEMMs are cuBLASLt's. We wrote the kernels around the multiply, not the multiply.
  • The BF16 baseline is stock PyTorch autocast.

Limits

Most arms have one seed. The width-8,192 run is 1,000 steps and undertrained. The model has four blocks and the data is TinyStories. Nothing multi-GPU was tested.

Written by Dr. Raj Dandekar and the team at Vizuara AI Labs.

About

End-to-end 4-bit training tested on one NVIDIA B200: real NVFP4 forward and FP8 backward GEMMs inside PyTorch, quantize kernels, TinyStories runs and results

Resources

Stars

4 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

0