Repository navigation
cuda: out_prod on BF16 tensor cores for quantized 2D weights — ~2x on the backward's frozen-base GEMMs (includes #9's perf cases) - #11
Conversation
…and 27B projections, the output head; Q4_K beside F32 and Q8_0) Measured on an RTX 5090 (CUDA 13.2): out_prod(W, dy^T) at 1024 tokens, us/run: 1536x1536 Q4_K 101; 1536x8960 429; 8960x1536 438; 5120x5120 745; 5120x17408 2948 (F32 2229, Q8_0 2698); 17408x5120 3512; the 5120x151936 head 23357. The dequantized copy costs about a third over the F32 GEMM at the ffn shape; the F32 GEMM itself is the bulk, so an F16 tensor-core GEMM on the dequantized block is the next cut. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc
…es (cublasGemmEx, F32 accumulate) The backward's frozen-base GEMMs ran as F32 Sgemm on a dequantized copy, ~3x the forward's int8 tensor-core cost. When the weight type has a BF16 dequantizer, each row block goes to BF16, the gradient goes to BF16 once per op (dense, orientation kept), and the blocks accumulate through cublasGemmEx with F32 compute. BF16 not F16: the gradient can be tiny and F16 would flush it to zero. Other types keep the F32 path. RTX 5090, CUDA 13.2, us/op at 1024 tokens (F32 path -> BF16): 1536x1536 101 -> 63; 1536x8960 429 -> 281; 8960x1536 438 -> 274; 5120x5120 745 -> 518; 5120x17408 Q4_K 2948 -> 1481, Q8_0 2698 -> 1481 (F32 src0 unchanged 2229); 17408x5120 3512 -> 1405; 5120x151936 head 23357 -> 12652. test-backend-ops -o OUT_PROD vs CPU: 234/234. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc
|
APPROVED at
~2x on the 27B shapes, with 234/234 parity, is the measurement. One consequence to write down, not a blocker: with the gradient rounded to BF16 (8-bit mantissa), a CUDA training run matches the CPU oracle's per-step LOSS only to roughly 1e-3 relative, not the ~1e-5 the F32 path gives. The op-level parity above is within its NMSE bound either way. For the cross-backend step-parity gate (CPU oracle vs CUDA vs Metal on the same data and seed), either compare at that looser tolerance or keep a debug switch that forces the F32 path, so a real kernel bug can't hide inside BF16 rounding. Co-Authored-By: Claude Opus 5.5 [email protected] |
4483cb5
into
feat/props-weight-residency
Two commits: #9's OUT_PROD perf cases (the before) and the BF16 tensor-core path (the after).
When the weight type has a BF16 dequantizer (K-quants, Q4/Q5/Q8, ...), each row block of W goes to BF16, the gradient goes to BF16 once per op (dense, orientation kept), and the blocks accumulate through cublasGemmEx with F32 compute. BF16 rather than F16 because the gradient operand can be tiny and F16 would flush it to zero; BF16 keeps F32's exponent range. Types without a BF16 dequantizer keep the F32 path.
RTX 5090, CUDA 13.2, us/op at 1024 tokens, F32 path -> BF16:
Parity: test-backend-ops test -b CUDA0 -o OUT_PROD against the CPU backend, 234/234, 0 FAIL.
27B reading: a layer's out_prods go from ~12 ms to ~6.4 ms per 1024 tokens; the step's out_prod ceiling moves from ~1.3k to ~2.5k tok/s.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc