Repository navigation
bench_niah_cpp: expose BSA config as CLI flags with safety warnings - #91
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
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 FLOATCLI 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.
Contributor
There was a problem hiding this comment.
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.
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]>
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds two CLI flags to
pflash/tests/bench_niah_cpp.pyso 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 theDFLASH_FP_USE_BSAenv var when unset.--alpha FLOAT— BSA block-selection threshold. Falls back to theDFLASH_FP_ALPHAenv 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 1orDFLASH_FP_USE_BSA=1); the WMMA fallback path is ~3.4× slower at long ctx and silently fails NIAH."alphaunset → "daemon will use its hardcoded default. For reproducible benchmarks, set--alphaexplicitly."The
--alphahelp text additionally notes that the docs default of0.85fails NIAH 2/10 at 117K context on Qwen3.6-27B / RTX 5090, while0.60and0.70pass 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
DFLASH_FP_USE_BSAandDFLASH_FP_ALPHAenv vars continue to work unchanged (CLI flags default toNone, env vars are read as fallback).