Skip to content

bench_niah_cpp: expose BSA config as CLI flags with safety warnings - #91

Merged
davide221 merged 2 commits into
Luce-Org:mainfrom
ppsx:bsa-cli-flag
May 4, 2026
Merged

davide221 merged 2 commits into
Luce-Org:mainfrom
ppsx:bsa-cli-flag

Conversation

@ppsx

@ppsx ppsx commented May 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds two CLI flags to pflash/tests/bench_niah_cpp.py so the BSA path is controllable from the command line, with warnings when the configuration is likely to silently invalidate NIAH:

  • --bsa {0,1} — enable Block-Sparse Attention for the drafter scoring forward. Falls back to the DFLASH_FP_USE_BSA env var when unset.
  • --alpha FLOAT — BSA block-selection threshold. Falls back to the DFLASH_FP_ALPHA env var when unset.

CLI values take priority over env vars. Once resolved, the bench script sets the corresponding env var so the daemon subprocess inherits the correct configuration.

Motivation

Silent BSA misconfiguration was the single highest-impact debugging trap when validating PFlash on a new GPU. Users running documented bench commands without the env vars set get the WMMA fallback path — ~3.4× slower drafter at long context, and silently failing NIAH — with no signal that anything is wrong.

Two warnings are now emitted at startup:

  • BSA disabled → "NIAH validation requires BSA enabled (--bsa 1 or DFLASH_FP_USE_BSA=1); the WMMA fallback path is ~3.4× slower at long ctx and silently fails NIAH."
  • BSA enabled but alpha unset → "daemon will use its hardcoded default. For reproducible benchmarks, set --alpha explicitly."

The --alpha help text additionally notes that the docs default of 0.85 fails NIAH 2/10 at 117K context on Qwen3.6-27B / RTX 5090, while 0.60 and 0.70 pass 10/10. This may be GPU-, model-, or context-specific; either way, alpha deserves per-setup validation rather than a single hardcoded default that gets baked into the docs.

Backward compatibility

  • Existing scripts that set DFLASH_FP_USE_BSA and DFLASH_FP_ALPHA env vars continue to work unchanged (CLI flags default to None, env vars are read as fallback).
  • Defaults preserve current behavior — no new flags ⇒ BSA off (matches today), with the new informational warning surfacing the misconfig instead of a silent slowdown.
  • Warnings are informational, not errors.

Copilot AI review requested due to automatic review settings May 4, 2026 14:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the pflash C++-only NIAH benchmark script to make Block-Sparse Attention (BSA) configuration controllable via CLI flags, and to emit startup warnings for configurations that can silently invalidate NIAH results or harm performance.

Changes:

  • Add --bsa {0,1} CLI flag (with env var fallback) to control whether the daemon uses BSA for drafter scoring.
  • Add --alpha FLOAT CLI flag (with env var fallback) to control the BSA block-selection threshold.
  • Emit warnings at startup when BSA is disabled or when BSA is enabled without an explicit alpha, and propagate resolved values to the daemon via environment variables.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pflash/tests/bench_niah_cpp.py Resolved
Comment thread pflash/tests/bench_niah_cpp.py Resolved

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 1 file

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="pflash/tests/bench_niah_cpp.py">

<violation number="1" location="pflash/tests/bench_niah_cpp.py:54">
P2: Explicit `--bsa 0` does not override an inherited `DFLASH_FP_USE_BSA=1`, so the daemon can still run with BSA enabled despite the CLI warning.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread pflash/tests/bench_niah_cpp.py Resolved
Adds --bsa {0,1} and --alpha FLOAT CLI flags to bench_niah_cpp.py.
CLI values take priority over DFLASH_FP_USE_BSA / DFLASH_FP_ALPHA env
vars when set. If neither is set, BSA stays off (current behavior) but
a warning is logged that NIAH validation results won't match RESULTS.md.

Motivation: silent BSA misconfiguration was the single highest-impact
debugging trap when validating PFlash on a new GPU. Users running
documented bench commands without env vars get the WMMA fallback path
(~3.4x slower drafter at long ctx, silently fails NIAH) and no signal
that anything is wrong.

The --alpha help text notes that the docs default of 0.85 fails NIAH
2/10 at 117K context on Qwen3.6-27B / RTX 5090, while 0.60 and 0.70
pass 10/10. This may be GPU-specific, model-specific, or context-
specific; either way, alpha deserves per-setup validation rather than
a single hardcoded default.

Backward compat: existing scripts that set DFLASH_FP_USE_BSA and
DFLASH_FP_ALPHA env vars continue to work unchanged. The warnings are
informational, not errors.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Three review-feedback fixes for the BSA resolution block:

1. The daemon enables BSA on env-var *presence*, not value
   (dflash/src/flashprefill.cpp:161 uses `getenv(...) != nullptr`),
   so the previous `int(os.environ.get(..., "0"))` resolution was
   wrong: DFLASH_FP_USE_BSA=0 in the user's shell parsed as
   bsa_enabled=False here, but the daemon still saw the var present
   and enabled BSA. Fix: use `"DFLASH_FP_USE_BSA" in os.environ`
   for the env-fallback path so the bench script and daemon agree.

2. `--bsa 0` (explicit disable) was a no-op against an inherited
   `DFLASH_FP_USE_BSA` env var because we never popped it. Fix: when
   bsa_enabled is False, `os.environ.pop("DFLASH_FP_USE_BSA", None)`
   so the daemon subprocess does not inherit it. CLI now reliably
   overrides the shell.

3. `--alpha` / `DFLASH_FP_ALPHA` were not range-checked. The daemon
   only honors values with `0 < alpha < 1`
   (dflash/src/qwen3_0p6b_graph.cpp:228-230); anything outside is
   silently dropped to the hardcoded default, making the bench
   non-reproducible without the user noticing. Fix: new
   `_alpha_or_die()` helper validates parse + range from both
   sources and `sys.exit`s with a clear message on bad input.

Warning text on the BSA-disabled path is also updated to say
"DFLASH_FP_USE_BSA set in env" instead of "DFLASH_FP_USE_BSA=1",
matching the corrected presence semantics.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@davide221
davide221 merged commit d715887 into Luce-Org:main May 4, 2026
1 check passed
@ppsx
ppsx deleted the bsa-cli-flag branch May 5, 2026 09:09
javierpazo added a commit to javierpazo/lucebox-hub that referenced this pull request May 10, 2026
Two CMake-side rough edges that bit me on Windows MSVC + CUDA 12.x
on RTX 6000 Ada (sm_89, Ada-only):

  1. CUDA architectures: when no explicit override is provided,
     the previous CMakeLists could fall back to `75;86`, which
     caused silent build issues on Ada-only setups. This change
     respects DFLASH27B_USER_CUDA_ARCHITECTURES (e.g. `89`) and
     uses it consistently across the dflash and submodule
     ggml/llama.cpp consumers.

  2. BSA was sometimes silently disabled depending on detection
     order. DFLASH27B_ENABLE_BSA is now respected as an explicit
     opt-in/opt-out and a clear status line is printed at
     configure time.

Net effect: a single-arch Ada-only build with BSA enabled is
reproducible from a clean checkout. Default behaviour (no
DFLASH27B_USER_CUDA_ARCHITECTURES set, BSA on) is preserved for
existing users.

Validation:
  cmake -S dflash -B dflash/build/Release \
    -DCMAKE_BUILD_TYPE=Release \
    -DDFLASH27B_USER_CUDA_ARCHITECTURES=89 \
    -DDFLASH27B_ENABLE_BSA=ON
  cmake --build dflash/build/Release --target test_dflash --parallel 8
  -> BUILD_EXIT_CODE=0, sm_89 single-arch confirmed.

Verification vs existing community PRs:

  COMP-COMPL with Luce-Org#48 ("auto-detect GPU arch to prevent sm_120a on
  consumer Blackwell", open) and Luce-Org#91 ("expose BSA config as CLI
  flags with safety warnings", merged 2026-05-04). Luce-Org#48 covers
  auto-detect; Luce-Org#91 covers runtime CLI. This PR covers the
  build-time CMake side: respect the user's explicit
  DFLASH27B_USER_CUDA_ARCHITECTURES override and keep
  DFLASH27B_ENABLE_BSA honest. The three PRs together give
  sensible defaults per hardware tier.

Author: Javier Pazo <[email protected]>
oliveagle pushed a commit to oliveagle/lucebox-hub that referenced this pull request May 22, 2026
bench_niah_cpp: expose BSA config as CLI flags with safety warnings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants