Skip to content
m8ngotreePublic

About

Low-precision kernels across hardware accelerators: TPU, GPU and Trainium

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

97 Commits

Folders and files

Repository files navigation

quokka — Inkling 2 Small BBBK Megakernel (NVIDIA B300 / sm_103a)

An open, frozen-milestone recreation of Thinking Machines Lab's BBBK (Big Beautiful Blackwell Kernel) 4-bit MoE training and RL megakernel from End-to-End 4-Bit Training, targeting thinkingmachines/Inkling-2-Small (594B total / 17B active, H=4608, I=2304, E=384, top_k=8, 40 NVFP4 layers + 8 MXFP8 layers) on NVIDIA B300 SXM6 AC (sm_103a).

Branches: main is focused strictly on the Inkling 2 Small BBBK megakernel. Earlier multi-accelerator work (TPU v6e MoE kernels and standalone B200 nvfp4_quantize experiments) is preserved on the dev branch.

Same-Process Progression (NVIDIA B300 SXM6 AC, E_loc=48, Cold-L2)

T / GPU v0_pytorch (BF16) v0_unfused_nvfp4 v1_umma_stack v2_epilogue_stack v3_bbbk_fused (1-GPU) v4_bbbk_ep8 (8× B300 E2E) v5_mxfp8_fwd (L40–47) v5_bbbk_bwd (MXFP8 SR)
1 4,610.4 µs 1,828.8 µs 1,046.6 µs 276.2 µs 106.5 µs (17.2× / 43.3× pt) 347.6 µs (1W) 127.5 µs 4,781.5 µs
16 12,754.4 µs 1,795.5 µs 1,071.0 µs 329.7 µs (5.4×) 414.6 µs 400.6 µs (1W) 361.5 µs 2,907.7 µs
64 14,864.8 µs 1,841.8 µs 1,100.9 µs 352.3 µs (5.2×) 434.4 µs 430.5 µs (1W) 389.6 µs 2,847.2 µs
256 15,252.8 µs 2,083.6 µs 1,201.6 µs 381.4 µs (5.5×) 443.5 µs 471.5 µs (1W) 390.5 µs 2,902.9 µs
2048 16,195.3 µs 6,562.9 µs 5,020.3 µs 669.4 µs (9.8×, 1,559 TF) 683.0 µs (542.7 µs warm L2) 1,065.6 µs (2W, 7.84 PF node) 898.1 µs 3,919.5 µs
4096 16,305.4 µs 11,764.3 µs 9,165.4 µs 926.7 µs (12.7× / 17.6× pt, 2,253 TF) 947.5 µs (847.9 µs warm L2) 1,743.6 µs (1W, 9.58 PF node) 1,520.3 µs 4,978.8 µs

Repository Map

  • quokka/reference/ — Exact FP32 PyTorch references: inkling2_moe.py (dual-softcapped SwiGLU, Inkling2TopKRouter, checkpoint NVFP4/MXFP8 codecs, BBBK fwd/bwd), nvfp4.py (fouroversix_mae), mxfp8.py, fixed8.py (S2F6), hadamard.py (32D RHT), requant.py, rounding.py.
  • quokka/cuda/bbbk/ — Frozen sm_103a milestone kernels (v0_baseline.py, v1_gemm_umma.{cu,py}, v2_epilogue_alu.{cu,py}, bbbk_fused_epilogue.{cu,py}, v3_v4_sched_comms.{cu,py}, bbbk_ep8_megakernel.py, v5_mxfp8_bwd.{cu,py}).
  • quokka/cuda/roofline_b300.py — Act 0 NVIDIA B300 roofline calculator (15 PFLOPS NVFP4, 5 PFLOPS MXFP8, 8 TB/s HBM3E, 900 GB/s NVLink 5).
  • quokka/cuda/csrc/ — Base nvfp4_quantize CUDA kernel used by v0_baseline and v2 comparisons.
  • bench/bbbk_harness.py — Same-process, rotating-order verification and benchmark harness across all frozen milestones.
  • scripts/modal_b300.py — Zero-waste Modal B300:1 / B300:8 runner (CPU-only sm_103a compile + SASS/NCU parsing, 2s scaledown, hard subprocess watchdog).
  • docs/learn/bbbk/ — Full lab notebooks, ncu summaries, SASS/register dumps, dead-end post-mortems, and open performance frontiers (start at docs/learn/bbbk/README.md).

Quick Start

# Local CPU reference tests & B300 roofline ($0 GPU)
uv run pytest -q tests/test_inkling2_moe.py tests/test_nvfp4.py tests/test_mxfp8.py tests/test_fixed8.py tests/test_hadamard.py tests/test_requant.py tests/test_rounding.py
uv run python -m quokka.cuda.roofline_b300

# Modal B300: CPU-only sm_103a SASS/PTX dump ($0 GPU)
uv run modal run scripts/modal_b300.py --cpu --cmd "python scripts/dump_asm.py"

# Modal B300:1 same-process v0 -> v5 progression benchmark
uv run modal run scripts/modal_b300.py --no-build --cmd \
    "python bench/bbbk_harness.py --milestones v0_pytorch,v0_unfused_nvfp4,v1_umma_stack,v2_epilogue_stack,v3_bbbk_fused,v5_mxfp8_fwd,v5_bbbk_bwd --tokens 1,16,64,256,2048,4096"

License

Apache-2.0, see LICENSE.

About

Low-precision kernels across hardware accelerators: TPU, GPU and Trainium

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages