Repository navigation
Bound PreparedLogprobs merge block and share kernels across speculative widths - #673
kbenkhaled wants to merge 2 commits into
Conversation
…ve widths
Why:
`PreparedLogprobs` specialized all four Triton kernels (`_statistics`,
`_normalization`, `_candidates`, and `_finish`) on `WIDTH: tl.constexpr`, and
`_finish` sorted all `TILES * 32` per-tile `uint64` candidates in a single
`tl.sort()` block. For a 262,144-token vocabulary (`TILES = 256`), `_finish`
unrolled an 8,192-element `uint64` bitonic sort network once per speculative
width (`1..6`). On an 8 GiB Jetson Orin Nano (CUDA 13.2 `ptxas`), compiling
those six specializations took ~19.5 minutes during graph catalog construction;
on a 128 GiB Jetson Thor (CUDA 13.2), cold preparation across widths `1..6`
took 65.40 s and `_finish` ran in 84.2 us at width 6.
What:
- Before: `WIDTH` was a `tl.constexpr` parameter in `_statistics`,
`_normalization`, `_candidates`, and `_finish`, causing separate Triton
compilations per speculative width, and `_finish` set
`BLOCK = next_power_of_2(tiles * 32)` (up to 8,192 at 8 warps).
- After (`ignition/components/logprobs.py`):
- Replaced `WIDTH: tl.constexpr` with runtime `width` decorated with
`@triton.jit(do_not_specialize=["width"])` across all four kernels and
promoted `pos = row.to(tl.int64) * width + col` for 64-bit addressing.
- Bounded `_finish`'s `BLOCK` at `_MERGE_BLOCK = 512` (`_MERGE_WARPS = 4`),
iteratively merging `BLOCK - CANDIDATES` (480) incoming keys into slots
`CANDIDATES..BLOCK-1` when `TILES * CANDIDATES > BLOCK`. Because each step
retains the top 32 unsigned `uint64` packed keys and `MAX_TOP_LOGPROBS` is
20, the global top 20 (including exact tie ordering, signed-zero
canonicalization, `-inf`, and `vocab < 20` sentinel padding) is bit-exact.
- Tests (`tests/components/test_logprobs.py`): added CPU merge-block bound
checks and CUDA tests covering single-specialization sharing and execution
across widths `(1, 2, 6, 16)` with multiple active rows, exact top-20 tie
ordering across chunk boundaries and vocabularies `[1, 5, 19, 64, 1025,
16384, 16385, 31744, 248320, 262144]` (BF16 and FP32), canonical `+0.0` bits
with `-inf` tails, requested-flag-only gating, requested token IDs
(including negative and out-of-range IDs), stale-epoch / `row >= live`
gating, and stream-ordered functional CUDA graph capture and replay.
Result:
- Observed on Jetson Thor (`SM110`, `V = 262,144`, widths `1..6`): cold
`PreparedLogprobs.prepare()` dropped from `65.40 s` to `4.46 s` (`14.7x`
faster), `_finish` GPU latency at width 6 dropped from `84.2 us` to `38.2 us`
(`2.2x` faster), and all tested widths share one compiled cubin per kernel.
- Observed on Jetson Orin Nano 8 GiB (`SM87`, `V = 262,144`, widths `1..6`):
cold `PreparedLogprobs.prepare()` across all six widths completed in `11.83 s`
(`_finish` compiles once in `4.25 s` vs ~3m 15s x 6 = ~19.5 min previously,
`241.3 us` GPU latency at width 6).
- Output buffers matched `main` (`1fbcc3c9`) bit-for-bit (`torch.equal` on raw
`int32` words) across `vocab in (19, 1025, 16385, 31744, 262144)` at width 6
on Jetson Thor and matched eager execution bit-for-bit through
`compile_forward()` at widths 1 and 4 (`V = 16,385`), with no core format or
ABI change.
Evidence and limitations:
- Live CUDA + CPU pytest (`FLARE_RUN_CUDA_TESTS=1 pytest -q
tests/components/test_logprobs.py tests/components/test_completion_outputs.py
tests/components/test_completion_capacity.py`): `87 passed, 0 failed` on both
Jetson Thor (`SM110`, 3.73 s warm / 66.99 s cold) and Jetson Orin Nano 8 GiB
(`SM87`, 200.8 s cold).
- Raw `int32` output word equality against `1fbcc3c9` verified on Jetson Thor
for `vocab in (19, 1025, 16385, 31744, 262144)` with >32 cutoff-straddling
ties and dominant `+0.0`/`-inf` rows.
- Verified Flare's `compile_forward()` (`wrap_triton` -> `flare::storage_call`)
lowering produces bit-exact outputs at `width=1` and `width=4` (`V = 16,385`)
on Jetson Thor.
- Limitations: SM103/SM120/SM121 hardware, full end-to-end `ignition export` /
`flare run` serving benchmarks, and SM87 baseline `BLOCK=8192` runtime
latency were not re-measured in this pass. Equivalent `tl.sort` / `WIDTH`
kernels in external recipe repositories (`vocabulary_logprobs.py`,
`prompt_logprobs.py`) are outside this repository and left for follow-up.
Design-Signed-Off-By: Gemini 4 Neon; design-review=2e5b
Signed-off-by: kbenkhaled <kbenkhaled@nvidia.com>
|
A case file has been opened for 673. Future reviews will auto-run 90 minutes after code updates are pushed.
|
Autobot ReviewFull Review · Value Proposition · Case File Recommendation: Changes RequestedThe
Walkthrough
Merge Risk: Medium · up to
|
ignition/components/logprobs.py checked two adjacent module-level integer literals (_MERGE_BLOCK = 512 and _TILE_CANDIDATES = 32) with a top-level assert, and tests/components/test_logprobs.py indexed _finish out of op._preparation by hardcoded position [3]. Changes: - ignition/components/logprobs.py: remove the module-level assert on _MERGE_BLOCK and _TILE_CANDIDATES. - tests/components/test_logprobs.py: select _finish arguments by matching `kernel is _finish` instead of hardcoded tuple index `[3]`. Result: removes dead module-import assertion and decouples the unit test from preparation tuple ordering, with zero runtime behavior change. Validation (Jetson Thor SM110, hf-thor-v2b container): - FLARE_RUN_CUDA_TESTS=1 pytest -q tests/components/test_logprobs.py tests/components/test_completion_outputs.py tests/components/test_completion_capacity.py: 87 passed, 0 failed. - Before (1fbcc3c) vs after CUDA-graph overhead (median on-minus-base across 3 alternating trials, BF16, width in {1, 6}, rows in {1, 8, 16}): - V=16,384 (8 -> 4 warps, same BLOCK=512): 1.00x-1.01x across all 6 shapes (e.g. w=1,r=1: 15.2 -> 15.0 us; w=6,r=16: 303.4 -> 303.8 us). - V=32,768: 22.4 -> 24.3 us (w=1,r=1); 50.7 -> 53.1 us (w=6,r=1); 600.7 -> 606.7 us (w=6,r=16, 0.99x). - V=131,072: 1.02x-1.25x faster across all 6 shapes (w=1,r=1: 71.8 -> 57.3 us; w=6,r=1: 190.9 -> 176.3 us; w=6,r=16: 2429 -> 2370 us). - V=248,320: 1.07x-1.49x faster across all 6 shapes (w=1,r=1: 148.9 -> 100.0 us; w=6,r=1: 374.7 -> 322.4 us; w=6,r=16: 5056 -> 4519 us). - V=262,144: 1.06x-1.47x faster across all 6 shapes (w=1,r=1: 149.1 -> 101.2 us; w=6,r=1: 388.4 -> 339.1 us; w=6,r=16: 5278 -> 4766 us). Limitations: SM103/SM120/SM121 GPUs and end-to-end served throughput were not measured on this commit. Design-Signed-Off-By: Gemini 4 Neon; design-review=2e5b Signed-off-by: kbenkhaled <kbenkhaled@nvidia.com>
Why
When preparing a model with speculative decoding,
PreparedLogprobs(ignition/components/logprobs.py) currently hits two avoidable Triton compile bottlenecks:WIDTHas a compile-time constant (tl.constexpr), even though it is only used as a stride (row * WIDTH + col). A model with widths1..6therefore compiles every kernel 6 separate times._finish: To find the top 20 tokens across the vocabulary,_finishloads every tile's top 32 candidates into one block and calls a singletl.sort(). For a 262k-token vocabulary (256tiles), that unrolls an 8,192-elementuint64bitonic sort network.On an 8 GiB Jetson Orin Nano (CUDA 13.2), compiling those 6 specializations of
_finishtook ~19.5 minutes during graph catalog construction. On a 128 GiB Jetson Thor (CUDA 13.2), cold preparation across widths1..6took65.40 s, and_finishran in84.2 usat width 6.What changed
ignition/components/logprobs.py): ChangedWIDTH: tl.constexprto a runtimewidthargument with@triton.jit(do_not_specialize=["width"])in_statistics,_normalization,_candidates, and_finish, and promoted the row offset (row.to(tl.int64) * width + col) to 64-bit indexing. All speculative widths now share a single compiled cubin per kernel (with_finishremaining specialized per vocabulary viaTILES: tl.constexpr)._finish(ignition/components/logprobs.py): Capped_finish's sort block at512elements instead of growing up to8,192, and reduced_MERGE_WARPSfrom8to4across all vocabularies. When a vocabulary has more than512tile candidates,_finishloops over the remaining candidates in 480-element chunks, keeping the top 32 packeduint64keys after each sort. BecauseMAX_TOP_LOGPROBSis 20 (≤ 32), the final top 20—including tie breaking, signed-zero canonicalization,-inf, and< 20vocabulary padding—is bit-for-bit identical.tests/components/test_logprobs.py): Added CPU merge-block checks and CUDA tests covering shared cubin reuse across widths(1, 2, 6, 16), exact top-20 tie ordering across chunk boundaries for vocabularies from1to262,144(BF16 and FP32),+0.0/-inf/< 20edge cases, requested token IDs, inactive-slot/epoch gating, and CUDA graph capture/replay.Result
V = 262,144, widths1..6)1fbcc3c9)3ac58fea)SM110) coldPreparedLogprobs.prepare()65.40 s4.46 sSM110)_finishGPU latency (width 6)84.2 us38.2 usSM87) coldPreparedLogprobs.prepare()~19.5 min11.83 sCUDA-graph replay overhead (
on - basemedian across 3 alternating trials, Jetson ThorSM110, BF16):1fbcc3c9,us)3ac58fea,us)us)int32output buffers matchedmain(1fbcc3c9) bit-for-bit on Jetson Thor acrossvocab in (19, 1025, 16385, 31744, 262144)at width 6, and matched eager execution bit-for-bit throughcompile_forward()at widths 1 and 4 (V = 16,385).Validation and limitations
FLARE_RUN_CUDA_TESTS=1 pytest -q tests/components/test_logprobs.py tests/components/test_completion_outputs.py tests/components/test_completion_capacity.py):87 passed, 0 failedon Jetson Thor (SM110) on3ac58fea(and on Jetson Orin Nano 8 GiBSM87on13372138).int32equality against1fbcc3c9(with >32 ties straddling the top-20 cutoff and chunk boundaries, plus+0.0/-infrows) and bit-exactcompile_forward()(wrap_triton->flare::storage_call) execution on Jetson Thor.SM103/SM120/SM121GPUs, end-to-endignition export/flare runserving benchmarks, and Orin Nano's oldBLOCK=8192runtime latency were not measured in this pass.Discord: no username provided