Skip to content

Prepare BRRR-derived small-verification fusion for DeepSeek V4.1 TP4 - #259

Closed
shihanqu wants to merge 1 commit into
NVIDIA:mainfrom
shihanqu:codex/deepseek-brrr-small-verification
Closed

shihanqu wants to merge 1 commit into
NVIDIA:mainfrom
shihanqu:codex/deepseek-brrr-small-verification

Conversation

@shihanqu

Copy link
Copy Markdown

Prepare BRRR-derived small-verification fusion for DeepSeek V4.1 TP4

Why

DeepSeek V4.1's small target-verification graphs contain separate output
projections, tensor-parallel reductions, hyperconnections, routing and expert
operations. A BRRR-derived fused path can reduce this work for five through
eight physical verification rows. Historical same-depth serving tests motivate
the integration, but its activation arithmetic differs from Flare's decomposed
path and needs an explicit numerical review.

This is a draft for design and validation review against Flare
e774a468cee4ade64393ba9d856788aaef974ed7. It is not a request to merge an
unqualified arithmetic change.

What Changes

  • Add the BRRR-derived CUDA prologue and suffix under
    ignition/recipes/deepseek41/native_brrr, with their original license and
    notices. Ignition compiles and captures the kernels during preparation.
  • Replace the decomposed suffix only for single-host TP4, all-SM120 groups,
    native expert scales, BF16 inputs and five through eight physical target
    verification rows. Check the fixed routing, normalization and activation
    constants before selection. Physical rows are not concurrent requests.
  • Use the fused prologue only for compatible carried-state layers without
    Engram lookup. Flare retains rotary transforms, sparse attention, cache
    writes, speculative state management, sampling and native scheduling.
  • Preserve decomposed execution for other shapes, architectures and modes,
    explicit native-dense activations and joint projection tuning. The rank
    group makes one common hardware-admission decision.
  • Expose graph-visible tensor mutations, retain resource owners through
    export, and drain before teardown. An engine without a registered layer can
    also be closed. Reject incompatible dense scales with a runtime error rather
    than an assertion that optimized Python could remove.
  • Include CUDA sources and attribution in the Python wheel; add host and
    opt-in CUDA tests and historical numeric evidence.

No checkpoint recalibration, serving-time Python, runtime compilation, eager
serving, new graph-family contract, or Helios scheduler change is introduced.
The kernel port does change activation quantization/reduction behavior; unchanged
checkpoint bytes are not a claim of equivalent arithmetic.

Claimed Benefit

The historical comparison used four RTX PRO 6000 Blackwell Workstation cards at
395 W, Flare 18b16e170bb9eab03e2b1800107c72966c56594f, D4, the same head
precisions, RAM Engrams, balanced scheduling and 32 active slots. In the final
30-second sweep, C1 increased from 318.8 to 350.7 tok/s at 0K and 339.6 to
359.4 tok/s at 32K. C2 gains in that sweep were only 0.2% and 1.8%. Other
concurrencies include small regressions; repeat C1/C2 measurements varied.

These are historical execution-path measurements, not a statistically established
gain on this upstream revision and not an equal-arithmetic comparison.
benchmarks/deepseek41_brrr/measurements.json retains both full fused sweeps,
the intervening small-batch repeat, the unfused comparison and component diagnostics.

The separately published combined deployment reached 364.45 +/- 21.30 tok/s C1
and 2266.83 tok/s C32 at 0K/450 W. It includes other preparation upgrades, so
those rates are not attributed to this PR. Both the 395 W and 450 W full
matrices are linked from benchmarks/deepseek41_brrr/README.md.

Evidence And Limits

The source is rebased onto e774a46 and tested with its pinned FlashInfer source
85ea6e766aa8434f89e587267d044dd852b9a312, using Torch 2.14.1+cu132 and CUDA
13.2.1 in a CPU-only container. No GPU was exposed to these validation runs.
The existing preparation image supplied dependencies; this is not a rebuilt
current Helios/Heliopause environment or a current-base exported-core qualification.

The focused suite finished with 156 passed and four CUDA tests skipped.
It checks row/mode/hardware/arithmetic selection, common
rank-group admission, byte-exact packing, scale rejection, teardown and existing
DeepSeek overlap/device-selection behavior. The CUDA extension also compiled
and loaded without GPU access, and the built wheel retained all ten required
source, documentation and attribution files.

The broader host suite finished with 322 passed, one skipped and one existing
prefill-test failure
:
test_decoder_feedback_at_replay_boundary_is_rejected_before_component_construction.
Its scratch fixture lacks local_logits; the same failure reproduces on untouched
e774a46 (11 passed and the same one failure in the untouched prefill module).
It is not suppressed or modified by this PR.

The four CUDA tests are present but unrun. They isolate residual mixing,
normalization and repeated graph replay with zero projection weights. They do
not qualify nonzero projections, the distributed suffix or full-model quality.

Historical four-rank diagnostics reproduced original BRRR behavior within its
measured repeatability bound. Against decomposed Flare, the attention-output
relative RMS differences were 3.62%/3.57% at five/eight rows, with downstream
MLP differences of 23.94%/15.83%. With identical attention output fed into both
suffixes, MLP differences were 2.74%/2.59%. Both observations are retained;
the smaller aligned-input discrepancy is not a full-path error bound.

Historical Estonia 10/10 at C1/C2/C10, four concurrent vision checks, tools,
structured output and request transitions passed. Those results do not replace
operator-level numerical acceptance or validate this upstream base.

Before merge, this needs an exclusive four-GPU export/replay qualification on
base and candidate, an agreed numerical contract, and repeated C1/C2/C4/C8/C16/C32
tests at 0K and 32K. Partial/inactive rows, graph-capacity transitions, cache
boundaries, rollback and allocation/lifetime stability must be exercised.
The serving deployment was deliberately not stopped or changed for this draft.

Host checks, after installing the repository's pinned preparation/test environment:

pytest tests/recipes/test_deepseek41_brrr.py \
  tests/recipes/test_deepseek41_expert_overlap.py \
  tests/recipes/test_deepseek41_mxfp8_device_admission.py

On an explicitly assigned, idle SM120 device:

FLARE_RUN_CUDA_TESTS=1 pytest tests/recipes/test_deepseek41_brrr_cuda.py

Attribution And Review Questions

The CUDA kernels and weight-layout adaptation derive from
Fraser Price's BRRR,
not an independently authored replacement. BRRR's Apache-2.0 license and its
vLLM, Local Inference Lab, b12x and FlashInfer notices are retained. The Flare
preparation integration and its caller-owned outputs/resource handling are
identified as adaptations in the root NOTICE.

The expert-reuse tuning workload is the already-merged
FlashInfer PR #78,
not a contribution made by this PR. No dependency-pin change is included.

The principal review questions are the acceptable activation-arithmetic contract,
whether the kernels should move into FlashInfer/b12x, and whether the measured
five-to-eight-row selection should become a tuned choice. No numerical tolerance
has been relaxed to resolve those questions.

Small DeepSeek V4.1 verification graphs execute separate projections,
reductions, hyperconnections and expert work. Historical same-depth
measurements motivate a BRRR-derived fusion of this preparation path;
the activation-arithmetic differences still require numerical review.

Add attributed BRRR kernels and Ignition graph bindings for single-host
TP4 on SM120 at five through eight physical verification rows. Preserve
Flare attention, cache updates and scheduling, and the decomposed paths
for other capacities, architectures and explicit preparation modes.
Retain resource ownership through export and drain before teardown.
Include host/CUDA tests, package data, notices and historical measurements.

The historical 395 W final sweep increased C1 from 318.8 to 350.7 tok/s
at 0K and 339.6 to 359.4 tok/s at 32K, with variable repeat results and
some higher-concurrency regressions. These are not equal-arithmetic
comparisons or evidence of a speedup against this upstream base.

Validation on e774a46 with pinned FlashInfer source: 156 focused tests
passed and four CUDA cases were skipped. The broader host suite had
322 passed, one skip and one prefill-fixture failure reproduced on the
untouched base. CUDA compilation/loading without GPUs and wheel-content
checks passed. Four-rank current-base export/replay, numerical acceptance
and serving benchmarks remain unrun. Submit as a draft, not merge-ready.

Design-Signed-Off-By: Codex (gpt-6-astra); design-review=cfcf
Signed-off-by: Shihan Qu <6208982+shihanqu@users.noreply.github.com>
@shihanqu
shihanqu marked this pull request as ready for review November 10, 2026 23:24
@shihanqu
shihanqu marked this pull request as draft November 10, 2026 23:24
@shihanqu
shihanqu marked this pull request as ready for review November 10, 2026 23:26
@original-el8 original-el8 added area:kernels GPU kernels and numerical execution. area:preparation Ignition checkpoint loading, tuning, compilation, capture, and export. enhancement New feature or request model:deepseek-v4.1 Affected recipe or documented reproducer: deepseek-v4.1. Impact may be broader. performance Performance, latency, throughput, or memory-efficiency investigation or improvement. triage:design-review Needs a maintainer scope, architecture, or contract decision before implementation or integration. labels Nov 13, 2026
@original-el8

Copy link
Copy Markdown
Collaborator

Categorized as kernel design review. The proposed fusion changes activation quantization/reduction behavior, so preserved checkpoint bytes do not establish numerical equivalence. Resolve the numerical contract and operator placement before accepting the historical speed comparison as evidence for this implementation.

The submitted-base checks were CPU-only and skipped CUDA qualification. The reported C1 gains come from an older execution path and mixed comparisons, with small regressions at other concurrencies; the combined deployment's throughput is not attributable to this PR. Exact-base export, numerical checks across the admitted row shapes and native serving remain necessary. The description calls this a draft, although GitHub currently shows it as ready for review.

@shihanqu GitHub reports merge conflicts with main, confirmed locally with git merge-tree for PR head 5124eb11f84a against main 97cfeb0001f1. Conflicting paths:

  • ignition/recipes/deepseek41/attention.py
  • ignition/recipes/deepseek41/bootstrap.py
  • ignition/recipes/deepseek41/decoder.py

Please reconcile the branch with main and rerun the checks affected by the resolution.

@original-el8 original-el8 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Request changes; reject this implementation as a production change in its present form. The description candidly calls it a design/validation draft, but ordinary preparation automatically selects it, and source review identifies two routing-contract regressions in addition to the disclosed numerical uncertainty.

The inline findings cover:

  • Automatic selection of unqualified target-verification arithmetic.
  • Reversed expert-ID tie breaking.
  • Loss of nonzero routing scores for valid negative logits.

The repository rules require preserved model semantics and operator-specific bounds established from required arithmetic and measured repeatability. Historical agreement with BRRR establishes fidelity to that implementation; it does not establish equivalence to Flare. The reported attention relative RMS differences of approximately 3.6% and downstream MLP differences of 15.83%/23.94% need an accepted numerical explanation and qualification. These percentages are component discrepancies, not a measured full-model quality loss. Adding an opt-in or widening tolerances would not resolve the routing regressions or waive the semantic requirements.

Validation on head 5124eb11 with its pinned FlashInfer 85ea6e766:

pytest -q tests/recipes/test_deepseek41_brrr.py \
  tests/recipes/test_deepseek41_expert_overlap.py \
  tests/recipes/test_deepseek41_mxfp8_device_admission.py \
  tests/recipes/test_deepseek41_brrr_cuda.py

156 passed, 4 CUDA tests skipped. I also ran the pinned b12x CPU routing reference and a float32 reproduction of the score expression for the examples in the inline comments. These are source/reference checks, not execution of the fused CUDA suffix. No four-GPU export, replay, serving, or performance run was performed. The submitted CUDA tests cover a zero-projection prologue and do not exercise either routing finding or the distributed suffix.

The preparation/runtime boundary itself remains intact: the added model computation is captured in Ignition, with no new Helios policy or serving-time Python path. The blockers are the execution semantics and missing qualification of the selected path. Resolve those and operator placement against the existing FlashInfer/b12x implementations before treating the historical throughput as merge evidence.

A merge-tree check against main b0219ef2 also conflicts in attention.py, bootstrap.py, and decoder.py. Reconciliation and qualification must use the resulting tree. GitHub currently shows this PR as ready for review despite the description calling it a draft.

vision_storage = {}
from .native_brrr import group_eligible as brrr_group_eligible
use_brrr = brrr_group_eligible(coordinator, device,
enabled=not config.joint_tuning and not config.native_dense_activations)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[P1] Do not select unqualified arithmetic during ordinary exports

This enables BRRR for ordinary single-host TP4/SM120 preparation, then eligible() selects every matching five-to-eight-row target-verification graph. Those rows use different activation quantization/reduction arithmetic from the decomposed path, while other capacities and decode/draft retain that path. The description explicitly says numerical acceptance and current-base four-rank export/replay are outstanding; the retained full-path component measurements include 15.83%/23.94% MLP relative RMS differences. There is no accepted operator bound or qualifying test establishing that this automatic substitution preserves the target model contract. Under the repository's “Reject weakened guarantees” and numerical-validation rules, this is a merge blocker. Preserve the required arithmetic and qualify the nonzero projections, routing, capacity transitions, and state lifetimes before enabling this execution path. An opt-in is not a substitute for those requirements.

if (i == bi) be_local = expert[i];
const unsigned ord = float_order(best);
const unsigned top = __reduce_max_sync(0xffffffffu, ord);
const int be = int(__reduce_min_sync(0xffffffffu, ord == top ? unsigned(be_local) : 0xffffffffu));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[P2] Preserve descending expert-ID tie breaking

__reduce_min_sync selects the smallest expert ID at an equal score, and the strict local comparison above also retains the first/smaller ID. Flare's PreparedRouter explicitly promises descending-ID ties; the pinned b12x GPU router uses tl.max for equal-score IDs and its reference uses a stable sort of reversed experts. With 384 equal logits and zero correction bias, the pinned CPU reference selects [383, 382, 381, 380, 379, 378]; this two-stage selector picks [0, 1, 2, 3, 4, 5]. This changes the selected expert set for identical routing inputs, independently of reduction roundoff. Preserve the same tie rule in both local and cross-lane selection, and cover ties across warp partitions with a real suffix/routing regression.

float* a = p.s.gacc + tok * EXPERTS + expert[i];
const float v = __ldcg(a);
__stcg(a, 0.0f);
score[i] = sqrtf(v > 20.0f ? v : logf(1.0f + expf(v)));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[P2] Retain stable softplus arithmetic for negative router logits

In float32, 1.0f + expf(-20.0f) rounds to exactly 1, so this expression produces a zero score. The pinned b12x implementation uses sqrt(max(v, 0) + log1p(exp(-abs(v)))) and produces approximately 4.539993e-5 for the same input. For a row of 384 logits equal to -20 with zero correction bias, this suffix consequently writes six zero route weights at line 855, whereas the pinned reference writes approximately 0.25 per selected expert (sum 1.5). Thus valid finite inputs can lose the entire routed contribution; checking scoring_func == "sqrtsoftplus" does not establish equivalent arithmetic. Use the stable score computation and validate negative-logit rows in the actual fused path. The numbers here come from float32 expression reproduction and the pinned CPU reference, not a CUDA suffix run.

@original-el8

Copy link
Copy Markdown
Collaborator

As currently implemented, this will not be approved.

This is substantially a copy of BRRR: 2,124 of its 2,131 decoder lines remain unchanged, and the three CUDA headers differ only by attribution headers.

It does not belong in Flare in its present form. Both routing issues identified in review are inherited from BRRR: ascending expert-ID tie breaking conflicts with Flare’s contract, and the softplus calculation can turn valid negative logits into zero routing weights.

The integration automatically selects this path for eligible verification graphs despite unresolved numerical differences and no qualification of the submitted tree’s distributed suffix. Passing host tests and reproducing BRRR behavior do not establish compatibility with Flare.

Before proposing a replacement, please resolve operator placement with the maintainers, preserve Flare’s routing and arithmetic requirements, and provide nonzero-weight numerical tests plus four-rank exported-model qualification. An opt-in flag or relaxed tolerances would not address those requirements.

I do not have a lot of confidence in the upstream implementation's correctness. Evidence would have to be provided that it is worthy of incorporation into flare.

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

Labels

area:kernels GPU kernels and numerical execution. area:preparation Ignition checkpoint loading, tuning, compilation, capture, and export. enhancement New feature or request model:deepseek-v4.1 Affected recipe or documented reproducer: deepseek-v4.1. Impact may be broader. performance Performance, latency, throughput, or memory-efficiency investigation or improvement. triage:design-review Needs a maintainer scope, architecture, or contract decision before implementation or integration.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants