Skip to content

PFlash NIAH benchmark on RTX 5090 #82

Closed

Description

@ppsx

Thanks for the great work on PFlash! I've validated the stack on RTX 5090
(sm_120, CUDA 13.2) using current main branch and want to report three
findings.

Setup

  • GPU: NVIDIA RTX 5090 32GB (sm_120)
  • CUDA: 13.2
  • Build: cmake -DCMAKE_CUDA_ARCHITECTURES=120 -DDFLASH27B_ENABLE_BSA=ON
  • Models: Qwen3.6-27B Q4_K_M target + z-lab/Qwen3.6-27B-DFlash + Qwen3-0.6B BF16
  • All test_flashprefill_kernels passing (BSA enabled correctly)

Finding 1: bench_niah_cpp.py does not set DFLASH_FP_USE_BSA / DFLASH_FP_ALPHA

These env vars are documented in pflash/README.md as required for
NIAH validation, but bench_niah_cpp.py does not set them by default.

Reproduction:

  • Without env vars: NIAH fails at 32K with keep_ratio=0.05 (drafter forward 2.23s)
  • With BSA=1 ALPHA=0.85: NIAH passes (drafter forward 0.65s, ~3.4x faster)

The difference is significant: drafter compute path is fundamentally
different (BSA vs WMMA fallback), affecting both speed AND retrieval quality.

Suggested fix: either set defaults in the bench script, or expose as
CLI flags (--bsa, --alpha).

Finding 2: niah_gen.py --ctx N produces prompts of length ~N+8K

niah_gen.py --ctx 131072 generates prompts of 139875 tokens, exceeding
the model context limit. This produces a transformers warning:
"Token indices sequence length is longer than the specified maximum (139875 > 131072)"

Suggested fix: --ctx should be the total prompt length (haystack + system + question),
or expose --total-budget flag.

Finding 3: keep_ratio=0.05 does NOT pass NIAH at 128K (current main)

RESULTS.md claims "NIAH retrieved at every measured context (32K → 128K)"
with keep_ratio=0.05. On current main this is not reproducible at 128K.

Context keep_ratio NIAH Compressed tokens
32K 0.05 ✓ 1706 / 35018
64K 0.05 ✓ 3473 / 69969
128K 0.05 ✗ 6947 / 139875
128K 0.10 ✓ 13955 / 139875

At 128K with 5% retention, drafter selected 218 chunks from 4372 -
the chunk containing the needle was missed. At 10% retention (437
chunks selected), needle is reliably retrieved.

Question: is the 0.05 result on 3090 still reproducible on current
main, or has the chunking algorithm changed? If 0.10 is now the
recommended default for 128K, README/RESULTS should reflect that.

Bonus: RTX 5090 PFlash benchmarks

Since these are likely the first public PFlash numbers on Blackwell:

Qwen3.6-27B Q4_K_M, BSA=1, ALPHA=0.85, n_gen=1024, budget=16:

  • 32K context, keep=0.05: TTFT 9.7s, decode 198 tok/s
  • 64K context, keep=0.05: TTFT 7.0s, decode 178 tok/s
  • 128K context, keep=0.10: TTFT 18.0s, decode 139 tok/s

vs Lucebox 3090 reference (64K @ keep=0.05: 13.5s TTFT):

  • 5090 gives roughly 1.5x-2x TTFT improvement for the prefill+compress phase
  • Decode speedup more modest because BSA is bandwidth-limited

Happy to add these to RESULTS.md if useful.

Activity

  1. added
    bug
    enhancement
    on May 3, 2026
  2. davide221 commented on May 3, 2026

    @davide221
    Contributor

    Hi @ppsx thanks for the benchmarking! Do you want to tackle these improvements? Adding results on the .md file and fixing these bugs would be really useful.

  3. ppsx commented on May 4, 2026

    @ppsx
    ContributorAuthor

    Hi! Yes, happy to tackle these. I have a draft plan below split into a
    few PRs to keep diffs reviewable, contain blast radius, and avoid
    breaking existing 3090 reference setups.

    Before that though - I owe you a correction on something from my
    original issue. See the "Retraction" section below.


    Retraction: my earlier "keep=0.05 @ 128K does not reproduce" claim was wrong

    In my original issue I reported that I could not reproduce the
    RESULTS.md claim of NIAH passing at keep=0.05 on 128K context. That
    was incorrect
    , and I want to clarify before proposing changes.

    What actually happened: my NIAH test prompt generator had a token-count
    bug. niah_gen.py --ctx N interprets N as character count, multiplied
    by char_per_tok=4.0 to estimate target tokens. For the FILLER text
    ("The grass is green...") on Qwen tokenizer, the real ratio is ~3.75,
    so --ctx 131072 produced 139875 tokens - 6.7% overshoot, pushing
    every prompt past Qwen3.6-27B's native RoPE limit of 131072.

    Beyond RoPE limit the model's behavior is undefined - it hallucinates
    "magic number is 42" instead of the real 7-digit value. I was
    attributing this to PFlash compression failing at low keep_ratio when
    it was actually invalid test data.

    After fixing niah_gen.py and regenerating prompts at 117K (margin under
    RoPE), I re-ran a focused parameter sweep on valid prompts. Results:

    • keep=0.05 @ 117K: 20/20 NIAH across 2 runs (n=20 effective
      sample), decode avg 210.7 t/s (range 179-230), TTFT 10.0s,
      compression 20.2x
    • Your RESULTS.md claim is validated. I retract that finding.

    This means the PR I had planned around "Reproduce or update
    RESULTS.md keep=0.05" no longer makes sense. It's now subsumed into
    the long-context section (PR 5 below).


    PR 1: Expose hardcoded params as CLI flags in bench_niah_cpp

    Why: During RTX 5090 validation I needed to sweep over ddtree_budget,
    fa_window, kv_tq3, and ddtree_temp to find a working config for
    Blackwell sm_120. Currently these are hardcoded in DflashClient.__init__
    or buried as positional args, so every parameter sweep meant editing
    Python source between runs - error-prone and not reproducible across
    sessions.

    Scope: Pure ergonomics - no semantic changes. New CLI flags map 1:1
    to existing daemon CLI flags. DflashClient gains optional kwargs that
    default to current behavior, so existing callers are unaffected.

    Bonus: --auto-max-ctx flag computes max_ctx from
    src_tokens × keep_ratio × 1.15 + n_gen + 512 and rounds to next 1024.
    This addresses the awkward situation where users have to manually
    compute max_ctx for compressed prompts; getting it wrong (too small)
    silently truncates output, getting it too big wastes VRAM. Auto-sizing
    was the single biggest reduction in my "what config do I pass"
    cognitive load.


    PR 2: Make BSA opt-in via CLI in bench_niah_cpp (Finding 1)

    Why: Current state forces users to know that DFLASH_FP_USE_BSA=1
    and DFLASH_FP_ALPHA are required for valid NIAH validation. README
    mentions these but bench_niah_cpp.py doesn't enforce or default them.

    I lost ~6 hours of debugging time on this. Without env vars, drafter
    forward took 2.23s and NIAH failed at 32K with keep=0.05. With env
    vars, drafter forward dropped to 0.65s (~3.4x faster) and NIAH passed.
    The difference isn't a tunable - it's WMMA fallback path vs proper BSA
    path. A user running bench_niah_cpp with documented args but missing
    env vars gets misleading numbers and may falsely conclude the
    algorithm doesn't work for their config.

    Additional finding from my sweep: the docs default alpha=0.85
    fails 2/10 on NIAH @ 117K with Qwen3.6-27B (10/10 at alpha=0.60 and
    alpha=0.70). I don't know if this is GPU-specific (Blackwell) or
    model-specific (Qwen3.6 vs Qwen3.5) or context-specific (long-ctx
    behaves differently than short). Either way it suggests the docs
    recommendation deserves a re-check, and a --alpha CLI flag with
    clear documentation about validating per-setup is more honest than a
    hardcoded default.

    Scope: Add --bsa {0,1} and --alpha FLOAT CLI flags. They take
    priority over env vars if set. If neither CLI nor env is set, keep
    current behavior (BSA off) but log a clear warning that NIAH
    validation requires BSA enabled.

    Risk: None for existing scripts that already set env vars. New
    users get a clear signal instead of silent misconfiguration.


    PR 3: niah_gen.py target_tokens accuracy (Finding 2)

    Why: As described in the retraction above - niah_gen.py --ctx N
    overshoots target token count by up to 6.7%, which silently invalidates
    NIAH tests near RoPE limits. Cost me about a day of chasing a phantom
    PFlash failure mode. Worth fixing so the next person who runs
    NIAH validation doesn't hit the same issue.

    Scope: I see two options, would appreciate your preference:

    (a) Calibration fix: change char_per_tok from 4.0 to 3.75.
    One-line diff. Empirically validated (delta +0.05% on requested vs
    actual tokens). Risk: if anyone has scripts that depend on the old
    --ctx 131072 → ~140K tokens behavior, they break silently.

    (b) Binary search: wrap the existing function with a binary-search
    loop that adjusts char_per_tok per call to hit target_tokens within 1%.
    More code (~15 lines), but works correctly for any FILLER text or
    tokenizer in the future. No backward compatibility issue - for any
    input where 4.0 was already accurate, binary search finds the same
    result.

    I lean toward (b) since it's robust to future model/tokenizer changes,
    but happy to go with (a) if you want minimal change.


    PR 4: Long-context NIAH section in RESULTS.md (follow-up to existing 5090 PR)

    Why: I noticed there's an open PR adding RTX 5090 results for AR vs
    DFlash speedup on short-context benchmarks (HumanEval, Math500, GSM8K).
    Excellent work - those numbers are exactly what new Blackwell users
    need as a starting point.

    That PR doesn't cover long-context retrieval reliability (NIAH),
    which is the part of the stack where I did most of my validation work.
    Different layer of the architecture, different failure modes,
    different optimal config. Specifically:

    • AR vs DFlash speedup tests pure speculative decoding on short
      prompts (50-250 tokens). PFlash compression isn't engaged.
    • NIAH at 117K tests the full PFlash+DFlash pipeline: drafter chunk
      scoring, ~20x compression, then DFlash decode on compressed prompt.

    Scope: I'd like to add a complementary section ("Long-context
    PFlash+DFlash validation") to RESULTS.md after the existing 5090 PR
    merges, so we don't conflict. It would include:

    • Setup: Qwen3.6-27B Q4_K_M (vs Q5_K_XL in the headline 5090 PR), Q4
      leaves more VRAM headroom for KV cache at long context
    • Validated config: keep_ratio=0.05, alpha=0.70 (BSA), ddtree_budget=22,
      fa_window=4096, kv_tq3=0
    • NIAH: 20/20 at 117K across 2 runs of n=10 (margin under Qwen3.6's
      131K RoPE limit)
    • Decode: avg 210.7 t/s sustained over 117K context, range 179-230 t/s
    • TTFT: ~10s (4s prefill + drafter score+migrate + 117K→5800 token
      compression)
    • Compression: 20.2x

    Cross-reference with existing PR: Their DDTree budget sweep on
    HumanEval shows budget=22 as optimal (211 t/s). My long-context sweep
    also converges on budget=22 (217.4 t/s vs 210.7 t/s at budget=28 vs
    211.1 t/s at budget=30, all 10/10 reliability). So budget=22 is
    optimal across context lengths
    - not just a short-context setting.
    Worth documenting as a stable default rather than something that
    needs per-regime tuning.

    Risk: Zero - additive section, no changes to other content.

    Sequencing: Will hold this PR until the headline 5090 PR is
    merged, to avoid stepping on ongoing work.


    PR 5: Expose tokenizer reference as CLI flag in bench_he.py / bench_llm.py

    Why: bench_he.py and bench_llm.py hardcode Qwen/Qwen3.5-27B
    as the tokenizer. This makes the bench scripts unusable for anyone
    validating PFlash with Qwen3.6-27B (or any future Qwen revision)
    without forking the repo. PFlash itself is model-agnostic once the
    GGUF target is loaded - the tokenizer pin is purely a benchmarking
    convention, not an architectural requirement.

    I hit this immediately when validating on Qwen3.6-27B - the bench
    scripts silently mistokenize prompts because Qwen3.5 and Qwen3.6 share
    most of the vocabulary but not all of it. Token counts in benchmark
    output were off by ~0.3-2% depending on prompt content, which compounds
    when you're sweeping ctx limits near RoPE boundaries.

    This will become more pressing once the existing 5090 PR merges - that
    PR uses Qwen3.6-27B as target, so the repo will have an internal
    inconsistency: target = 3.6, tokenizer = 3.5. PR 5 fixes that without
    forcing the change on existing 3090 users.

    Scope: Add --target-tokenizer CLI flag to both bench_he.py and
    bench_llm.py, defaulting to Qwen/Qwen3.5-27B to preserve current
    behavior. Users running Qwen3.6 (or future versions) pass
    --target-tokenizer Qwen/Qwen3.6-27B.

    Risk: None for existing scripts - default is unchanged. New flag is
    purely additive.


    Sequencing

    I'll start with PR 1 since it's pure ergonomics and unblocks clean
    reproduction of the others. PR 2 next (BSA flag) since the missing
    docs/defaults is the highest-impact bug for new users. PR 3 (niah_gen
    fix) in parallel once we've decided option a vs b. PR 4 (long-context
    NIAH section) waits until the existing 5090 short-context PR merges,
    then lands as additive follow-up. PR 5 (tokenizer flag) is independent
    of the rest - especially useful right after the existing 5090 PR
    merges to keep target/tokenizer consistent.


    One question before I start

    Would you prefer one consolidated PR or separate smaller ones? My
    default plan above splits into 5 PRs because:

    • It contains blast radius (PR 2 risk profile is very different from
      PR 5)
    • Easier to revert any single one if needed
    • Lets you merge low-risk changes (PR 1, PR 5) quickly while we
      discuss the contested ones (PR 3 option a vs b, PR 2 alpha
      recommendation)

    But if you'd rather review one consolidated PR for fewer review cycles
    and easier context, I'm happy to do that instead. Just let me know
    your preference before I start.

    Sound good?

  4. davide221 commented on May 4, 2026

    @davide221
    Contributor

    @ppsx thanks for drafting the plan, tbh i think it make more sense to go step by step, as you were saying doing like this we can approve the easy parts faster. Happy to see that 128K PFlash got reproduced btw

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

Metadata

Metadata

Assignees

Labels

bugenhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions