Liger-Kernel icon indicating copy to clipboard operation
Liger-Kernel copied to clipboard

Suggestion: per-kernel roofline/bandwidth-efficiency benchmarks in docs

Open ragulk143 opened this issue 5 months ago • 5 comments

Liger Kernel's README reports excellent aggregate numbers (20% throughput increase, 60% memory reduction on LLaMA 3-8B). I haven't seen a per-kernel breakdown of bandwidth efficiency (% of theoretical peak HBM bandwidth) for the individual ops (RMSNorm, RoPE, SwiGLU, Softmax) — that level of detail would help users understand why a given kernel is fast, and which ones are closer to their hardware ceiling than others.

I built a small from-scratch reimplementation of these four kernels for my own learning, with that exact kind of analysis (roofline-based, including a documented failed optimization attempt on the RoPE kernel where "fixing" a strided memory access pattern actually made performance worse): https://github.com/ragulk143/inference-kernels

Not suggesting any change to Liger's actual kernels — they're clearly more mature and production-tested than mine. Just wondering if a per-kernel efficiency benchmark section (with a roofline-style table) might be a useful addition to the docs for users trying to understand kernel-level performance characteristics, not just aggregate end-to-end numbers.

Happy to contribute a draft if this is something the maintainers would find valuable.

Image

ragulk143 avatar Jun 27 '26 13:06 ragulk143

Quick update with real data, since I just finished profiling all four kernels with Nsight Compute on my reference implementation (not Liger's code, my own learning repo mentioned above).

Measured memory throughput vs theoretical roofline estimate, RTX 3050:

Kernel Hand-calculated roofline estimate Nsight Compute measured
RMSNorm ~68% 93.74%
SwiGLU ~68% 94.23%
RoPE ~44% 94.70%
Softmax N/A (baseline) 92.99%

The gap between the simple roofline model (bytes moved / peak bandwidth) and the real measured numbers is consistently large -- 25+ percentage points in every case. My read on this is L2 cache reuse, which the simple model doesn't account for at all.

This reinforces the original suggestion: a per-kernel measured-bandwidth table (not just the theoretical estimate) would be a genuinely useful addition to the docs, since the gap between "what the simple formula predicts" and "what Nsight actually measures" seems to be a consistent, nontrivial pattern, at least at this scale. Happy to share the full profiling output if useful.

ragulk143 avatar Jun 30 '26 11:06 ragulk143

Hi, is this something you'd want in the docs? I profile LLM fine-tuning kernels with Nsight Compute at work, and I could measure Liger's own kernels (the numbers above came from a separate reimplementation) for achieved memory bandwidth against the GPU's roofline, then add a short docs page with the exact commands so anyone can re-run it. If you'd rather keep benchmark numbers out of the docs, a script under benchmark/ could hold it instead. Which would you prefer?

bhargavchintam avatar Oct 31 '26 08:10 bhargavchintam

Hi @bhargavchintam, thanks for offering to run this on Liger's actual kernels!

Just to clarify for anyone following: the numbers in my table above are from my own from-scratch reimplementation [ragulk143/inference-kernels] for learning, not from Liger's kernels. So they shouldn't be taken as Liger's efficiency numbers.

The pattern I found is the gap itself - hand-calculated bytes / peak BW vs ncu dram__throughput was 25pp+ off because the simple model misses L2 reuse. That is the part I think is worth documenting.

I would love this as:

  1. A script benchmark/benchmark_roofline.py that prints achieved dram__bytes + % of measured peak via ncu --metrics and saves a CSV.
  2. A short docs page showing how to re-run it and an example table with columns: Kernel | Achieved BW | % Peak | Notes (e.g. L2 hit rate).

Since you have the proper fine-tuning setup and I only have a RTX 3050 6GB, would you be open to me opening a draft PR for the script + docs skeleton using my methodology, and you can then plug in / verify the real numbers on your hardware? Happy to start with just 2 kernels (RMSNorm + SwiGLU) to keep the PR small.

Let me know if that works and which metric set you prefer - dram__throughput vs dram__bytes.sum.per_second.

ragulk143 avatar Oct 31 '26 11:10 ragulk143

Thanks for clarifying. That plan works for me: go ahead with the draft PR for the script and docs, starting with RMSNorm and SwiGLU. I'd use dram__bytes.sum.per_second and take % of peak against a measured copy-kernel bandwidth, since that counts the bytes that really reached DRAM after L2. Once the skeleton is up, I'll run both kernels on a B200 and add the numbers.

bhargavchintam avatar Oct 31 '26 23:10 bhargavchintam

Update: re-measured on Liger's actual kernels

I re-measured with Nsight Compute, this time on Liger's actual RMSNorm and SwiGLU forward kernels (RTX 3050 6GB laptop GPU, LLaMA 3-8B shapes, fp16), not my reimplementation.

Findings

  • Measured DRAM bytes match a simple reads+writes model within 1% for both kernels, so L2 reuse does not explain the gap I reported earlier between my hand-calculated estimate and the ncu numbers.
  • I can't say exactly where that earlier discrepancy came from, but it wasn't caching.
  • Normalizing against a measured copy-kernel bandwidth instead of a datasheet peak, both Liger kernels reach ~100% of achievable bandwidth on this GPU.

Links

  • Draft PR (script, methodology, docs page): https://github.com/linkedin/Liger-Kernel/pull/1584
  • Branch: https://github.com/ragulk143/Liger-Kernel/tree/docs/roofline-benchmark

@bhargavchintam, it's ready for the B200 run. To reproduce:

git clone https://github.com/ragulk143/Liger-Kernel.git && cd Liger-Kernel
git checkout docs/roofline-benchmark
pip install -e .
NCU=$(which ncu) bash benchmark/run_roofline.sh roofline_out

It profiles a copy baseline, RMSNorm and SwiGLU with ncu and prints a table: achieved GB/s, % of copy peak, L2 hit rate, and measured vs modeled DRAM bytes.

Please paste the table here or push it into docs/Roofline-Benchmark.md. If ncu reports ERR_NVGPUCTRPERM, enable GPU counter access for your user first.

ragulk143 avatar Nov 01 '26 06:11 ragulk143