Skip to content

I can’t reproduce the prefill performance on the RTX 3090 #5

Closed

Description

@chfwinter

Hello,

Thanks for sharing this, looks great!! I’m trying to follow along and reproduce it with your scripts.

One thing I noticed is prefill perf is much slower than the reported 37k tok/s. I’m only seeing around 8.5k. Not sure if I’m missing something.

Also need to install flash-linear-attention to boost PyTorch HF performance so it looks better, but decoding is still lagging behind.

  +------------------+----------+----------+
  | Method           |  pp520   |  tg128   |
  +------------------+----------+----------+
  | Our megakernel   | 8505 t/s |  408 t/s |
  | PyTorch HF       | 8747 t/s |   26 t/s |
  +------------------+----------+----------+

Software

  Python:       3.12.3
  PyTorch:      2.10.0+cu128
  Transformers: 5.5.3
  FLA:          0.4.2
  Triton:       3.6.0 (upstream)
  GPU:          RTX 3090  (sm_86)

Activity

  1. self-assigned this
    on Apr 10, 2026
  2. davide221 commented on Apr 10, 2026

    @davide221
    Contributor

    Hey, thanks for trying it out!

    bench_pp_tg.py is a quick correctness check, it does 1 warmup + 1 timed run, which isn't enough to warm cuBLAS on the prefill path. Run final_bench.py instead: it does 10 warmup + 20 timed runs averaged and also uses a proper manual past_key_values loop for the HF baseline. That's how we got the 37,800 prefill and 108 t/s HF decode numbers.
    We're updating the README to point there by default.

  3. chfwinter commented on Apr 10, 2026

    @chfwinter
    Author

    Thanks, I tried running final_bench.py, but the perf numbers didn’t really change, even after locking power and clocks with sudo nvidia-smi -pl 400 && sudo nvidia-smi -lgc 2100.

    I might try running it in a container to see if I can reproduce the issue.

  4. ateamlunchbox commented on Apr 14, 2026

    @ateamlunchbox

    Hi, I have the same issue reported here in that I have been unable to replicate the reported results.

    I forked the repo and created this PR with a Dockerfile and instructions on how to build/run it (see comments in the Dockerfile). I am hoping there is some small error in my configuration that will explain why the execution speeds are slower than reported.

    I spent the last 24 hours trying to get luce-megakernel working on Debian 13, and then switched to docker when it seemed that CUDA 13.2 (which I had installed on my Debian 13 host) was causing problems with luce-megakernel.

    My hope is to get to a containerized version of luce-megakernel so anyone can easily replicate the results on an RTX 3090.

    Note: the container image is ~20GB 🙂

    Please let me know if there is anything I can do to help get this working.

  5. dknos commented on Apr 17, 2026

    @dknos

    I hit what looks like the same bug while porting this to RTX 5080 / sm_120a on CUDA 12.8 + PyTorch 2.10+cu128 (same stack you're on). Prefill was 4x slower than expected and the fingerprint matched what you're seeing: our megakernel prefill (cuBLAS) and the PyTorch HF baseline landed on nearly identical tok/s, which happens when both paths share a single slow GEMM dispatcher.

    30-second diagnostic — add this to a test script or drop into bench_pp_tg.py around one prefill call:

    with torch.profiler.profile(activities=[torch.profiler.ProfilerActivity.CUDA]) as prof:
        prefill(long_ids)
        torch.cuda.synchronize()
    print(prof.key_averages().table(sort_by="self_cuda_time_total", row_limit=10))

    Then grep the kernel names:

    • magma_sgemmEx_kernel<float, __nv_bfloat16, __nv_bfloat16> → cuBLAS fell back to the CUDA-core path, ~10x slower than tensor cores. This is the trap.
    • cutlass_80_tensorop_bf16_s16816gemm_* → actual tensor cores; slowdown is elsewhere (DVFS, thermal, driver).

    If it's magma: I have a drop-in fix in dknos/luce-megakernel#1. It replaces cublas_bf16_gemm with a call to at::mm_out, which uses the CUTLASS tensor-core kernels torch already ships in libtorch. Zero new link deps since torch_bindings.cpp already pulls in libtorch. On sm_120a it gave a 1.85x sustained prefill speedup (pp302: 87ms → 47ms); on sm_86 the effect could be larger since the pre-fix is even slower relative to the theoretical ceiling.

    Things I ruled out along the way that didn't help, in case you try them:

    • CUBLAS_GEMM_DEFAULT_TENSOR_OP (algo 99, deprecated in 12.8, silently maps to DEFAULT)
    • CUBLAS_COMPUTE_32F_FAST_16BF compute type hint
    • 32MB cublasSetWorkspace
    • Full cuBLASLt with cublasLtMatmulAlgoGetHeuristic — same dispatcher, same magma fallback

    Please drop the profiler output here if you run it — if it's not magma we've at least ruled out one thing and can narrow the search.

  6. davide221 commented on Apr 21, 2026

    @davide221
    Contributor

    Thanks @dknos, really appreciate the deep dive. We're heads-down on another part of the repo right now and can't give the prefill path proper attention for a bit. The 37k number most likely came from an experiment branch that we didn't merge and needs retesting.

    If you want, open a PR with the at::mm_out swap and we'll pick it up on our RTX 3090 when we're back on this code. Huge thanks for the work.

  7. added
    bug
    enhancement
    on Apr 27, 2026
  8. added 2 commits that reference this issue on Apr 28, 2026
  9. LeiYangGH commented on Apr 30, 2026

    @LeiYangGH

    on 29th Apr 2026 i built on windows using latest code. but performance is no much better than llama.cpp (i my smoke test).
    i've put my logs in folk branch

  10. removed their assignment
    on Apr 30, 2026
  11. davide221 commented on May 4, 2026

    @davide221
    Contributor

    Prefill performance of the qwen3.5 megakernel are a little bit better better of llamacpp (20k tok/s compared 18k tok/s). On the decode side there is no competition. Closing the issue with updated performances in the readme.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions