Repository navigation
Fuse the CUDA decode step and LayerNorm kernels - #11
Conversation
Each LayerNorm thread now reads its share of the row from memory once and keeps it in registers for the mean, the variance and the output, with the same summation order, so the results are bit-identical. A layer's last norm also writes the next layer's first norm, which drops one launch per layer and the device copy after it. On an RTX 5090 the encoder's LayerNorm time on LibriSpeech test-clean falls from 1.08 s to 0.92 s.
A greedy decode step ran 15 launches: cuBLAS GEMVs for each LSTM gate product and the predictor projection, plus small kernels for the embedding, the cell update, the joint input and the bias fill. Batch 1 decode is bound by launch latency, so the step now runs the joint GEMM, decode_decide, one decode_lstm per predictor layer and decode_project. decode_lstm computes a layer's gates and its cell update in one launch, reading the embedding row directly for the first layer. decode_project writes the predictor projection, the next step's joint input and the joint bias the next GEMM accumulates onto. Both keep a block's weights in registers and reuse them across 8 batch rows per pass, so long-form batches of 16 do not walk their rows one at a time. decode_decide keeps each thread's class logits in registers instead of rereading them for every pass, with the same results. On an RTX 5090 with TF32, LibriSpeech test-clean goes from 953x to 1108x real time and Earnings-21 from 2508x to 2528x, with unchanged transcripts and WER.
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 18 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
[Medium impact] The PR appears safe to merge, with the earlier predictor test-coverage concern addressed.
|
decode_lstm and decode_project carry 8 batch rows per pass and leave rows that do not emit untouched, which the NeMo parity tests at batch 1 and 8 never reach. The test runs two steps on 17 rows with different rows emitting each step and holds the state, projection, joint input and logits to a host predictor.
|
@greptileai review |
Closes #3.
Changes
decode_decide, onedecode_lstmper predictor layer, anddecode_project.decode_lstmcomputes a layer's gates and cell update in one launch. The first layer reads its embedding row directly.decode_projectwrites the predictor projection and the next step's joint input. It also pre-fills the logits with the joint bias, which the next GEMM accumulates onto withbeta = 1.decode_decide: each thread keeps its class logits in registers, and warp 0 finds the best duration. Results are the same as before.Results
RTX 5090, TF32, Parakeet v3. Each build was measured on the same GPU.
just gpu-paritypasses 17/17. FP32 output still matches NeMo token for token, and the encoder's FP32 errors against NeMo are unchanged to every printed digit.Kernel time, LibriSpeech (nsys, graph nodes)
decode_lstm1.55 s +decode_project0.29 s)decode_decideOn one long call (4360674.wav, batch 16),
decode_lstmtakes 20 µs per layer anddecode_project6.4 µs per step.Tried and not kept
Fusing the first subsampling convolution into the first depthwise convolution. The first feature map is no longer stored, which saves about 1.2 GB per long-form shape. But each depthwise output recomputes nine first-stage taps, so subsampling got slower:
LibriSpeech fell to 1056x. Reverted.
A first version of
decode_lstmanddecode_projectthat handled batch rows one at a time. It took LibriSpeech to 1047x but slowed Earnings-21 to 2045x (79 µs per LSTM layer at batch 16). Replaced by the batched version above.