Repository navigation
ignition/sampling: add <=16-SM probability-space top-k fallback - #72
Draft
FujitsuPolycom wants to merge 1 commit into
Draft
FujitsuPolycom wants to merge 1 commit into
FujitsuPolycom wants to merge 1 commit into
Conversation
FujitsuPolycom
force-pushed
the
jetson/pr-c-sm16-flashinfer-sampling
branch
from
December 4, 2026 21:57
32e7121 to
31c47f6
Compare
FlashInfer's RadixTopKMaskLogitsMultiCTA rejects multi-CTA launches with
cudaErrorNotSupported whenever multi_processor_count <= 16 and the
vocabulary exceeds one CTA's shared memory (~24K FP32 entries at 99 KiB
opt-in SMEM). That aborts native core export and graph capture on low-SM
GPUs such as the 8-SM Jetson Orin Nano even when the row group fits in
available SMs (for example, 65,536 tokens using 3 CTAs per group).
- ignition/components/flashinfer_sampling.py:
- Before: filter_probabilities_out unconditionally called
torch.ops.flashinfer.top_k_mask_logits_out before softmax.
- After: registers torch.library custom op flare::top_k_renorm_probs_out
(-> None, mutates_args=("renorm_probs", "row_states_buffer"), with
register_fake so make_fx, _lower_storage, and aot_forward
_serialized_invocations trace and serialize it cleanly), forwarding
directly to cached sampling.gen_sampling_module().build_and_load().
On <=16-SM CUDA devices, _use_prob_space_top_k computes CTA counts
from shared_memory_per_block_optin (reserving 4096 B overhead):
single-CTA logit vocabularies stay on barrier-free
top_k_mask_logits_out; multi-CTA vocabularies whose FP32 post-softmax
probabilities fit within multi_processor_count run in-place
deterministic flare::top_k_renorm_probs_out after softmax (zero extra
[rows, vocab] FP32 buffer); vocabularies whose FP32 probabilities
exceed multi_processor_count fail fast with RuntimeError instead of
deadlocking RadixTopKRenormProbMultiCTA's inter-CTA barrier. Devices
with > 16 SMs keep the unchanged top_k_mask_logits_out path.
- ignition/components/sampling.py:
- Updates PreparedSampling docstring for <=16-SM probability-space order.
- tests/components/test_flashinfer_sampling_dispatch.py:
- Verifies SM-count and CTA-budget dispatch, device forwarding on
cuda:1, fail-fast deadlock prevention for both FP32 and BF16/FP16
logits (vocab 248,320 on 8 SMs), non-CUDA handling, exact C++
argument-order forwarding in flare::top_k_renorm_probs_out, and CPU
make_fx + _lower_storage + _serialized_invocations tracing.
- Compatibility: no core format or workspace changes; > 16-SM and
single-CTA exports are identical.
Result:
- Expected to unblock native core export and graph capture on <=16-SM
GPUs for multi-CTA vocabularies up to multi_processor_count CTAs/row
without allocating an extra probability tensor or hanging on oversized
vocabularies.
Evidence:
- Verified on clean git archive via ruff==0.12.8 check and
CUDA_VISIBLE_DEVICES="" pytest
tests/components/test_flashinfer_sampling_dispatch.py
tests/preparation/test_core_boundary.py (including custom-op argument
forwarding and real make_fx, _lower_storage, and
_serialized_invocations checks).
- Limitations: live CUDA execution (FLARE_RUN_CUDA_TESTS=1 pytest
tests/components/test_sampling_flashinfer.py) and numerical parity on
both >16-SM and <=16-SM (SM87) GPUs remain unrun on this revision.
Discord: Dooner
Design-Signed-Off-By: Antigravity (Gemini 4 Neon); design-review=2e5b
Signed-off-by: Dooner <dooner@users.noreply.github.com>
FujitsuPolycom
force-pushed
the
jetson/pr-c-sm16-flashinfer-sampling
branch
from
December 4, 2026 22:04
31c47f6 to
8bd243e
Compare
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.
Why
ignition.components.flashinfer_sampling.filter_probabilities_outcallstorch.ops.flashinfer.top_k_mask_logits_outbeforesoftmaxandtop_p_renorm_probs_out. In FlashInfer (include/flashinfer/topk.cuhandcsrc/renorm.cu),RadixTopKMaskLogitsMultiCTArejects multi-CTA launches withcudaErrorNotSupportedwhenevermulti_processor_count <= 16and the vocabulary exceeds one CTA's shared memory (~24K FP32 entries at 99 KiB opt-in shared memory). That aborts native core export and CUDA-graph capture on low-SM GPUs such as the 8-SM Jetson Orin Nano even when the required CTAs per row fit within the available SMs (for example,65,536tokens requiring 3 CTAs per row on 8 SMs).Conversely,
RadixTopKRenormProbMultiCTAhas noctas_per_group <= multi_processor_countlaunch guard, so unconditionally calling it for vocabularies that require more CTAs per row than SMs (such as248,320tokens on 8 SMs) would deadlock its inter-CTA software barrier (AdvanceRadixGroupBarrier). Routing only multi-CTA vocabularies whose FP32 post-softmax probabilities fit withinmulti_processor_countto an in-place,torch.library.custom_op-registered deterministictop_k_renorm_probs_outaftersoftmax—keeping single-CTA vocabularies ontop_k_mask_logits_outand failing fast when FP32prob_ctas > multi_processor_count—unblocks low-SM GPUs cleanly while preservingcompile_forward/aot_forwardtracing and leaving> 16-SM GPUs unchanged.What changed
Before this change,
filter_probabilities_outunconditionally calledtorch.ops.flashinfer.top_k_mask_logits_outon every CUDA device.ignition/components/flashinfer_sampling.py:top_k_mask_logits_out -> softmax -> top_p_renorm_probs_out.torch.library.custom_op("flare::top_k_renorm_probs_out", mutates_args=("renorm_probs", "row_states_buffer"))with aregister_fakekernel, forwarding directly to cachedsampling.gen_sampling_module().build_and_load().top_k_renorm_probs(...)in FlashInfer's exact C++ argument order(probs, renorm_probs, maybe_top_k_arr, top_k_val, is_deterministic, row_states_buffer). ReturningNonewith a fake kernel allowsmake_fx(..., tracing_mode="fake"),_lower_storage, andaot_forward's_serialized_invocationsto trace, lower, and serialize the op cleanly._use_prob_space_top_k(logits). For> 16-SM CUDA devices and non-CUDA tensors, it returnsFalse(unchangedtop_k_mask_logits_outpath). For<= 16-SM CUDA devices, it computes CTA counts fromshared_memory_per_block_optin(falling back toshared_memory_per_block, reserving4096bytes for fixed dynamic and static CUB shared-memory overhead):logit_ctas <= 1, usinglogits.element_size()) returnFalseand stay on barrier-freetop_k_mask_logits_out.module.softmaxunconditionally widens logits to FP32, the multi-CTA residency check computesprob_ctasusing 4-byte FP32 elements: whenprob_ctas <= multi_processor_count,filter_probabilities_outrunsmodule.softmax(...) -> torch.ops.flare.top_k_renorm_probs_out(probabilities, probabilities, top_k, 0, row_states, True) -> torch.ops.flashinfer.top_p_renorm_probs_out(...)in place (zero extra[rows, vocab]FP32 intermediate buffer, using deterministic fixed-point renormalization in existingrow_states).prob_ctas > multi_processor_count,_use_prob_space_top_kraisesRuntimeErrorimmediately instead of launching a deadlocking multi-CTA barrier.ignition/components/sampling.py:PreparedSampling's docstring to note that multi-CTA top-k runs in probability space after softmax on<= 16-SM GPUs.tests/components/test_flashinfer_sampling_dispatch.py:8/16SMs with65,536and154,880vocabularies; single-CTA16,384on 8 SMs;17/170SMs), exact non-zerocuda:1device forwarding, fail-fastRuntimeErrorwhenvocab_size = 248,320exceeds 8 SMs for both FP32 and BF16/FP16 logits, non-CUDA handling, exact C++ argument-order forwarding intorch.ops.flare.top_k_renorm_probs_out(tensor andNonemaybe_top_k_arr), and realmake_fx(..., tracing_mode="fake")+_lower_storage+_serialized_invocationstracing.> 16-SM (SM120,SM121,SM103) or single-CTA exports are identical. No new workspace buffers orPreparedSamplingABI changes are introduced.Claimed benefit and result
<= 16-SM GPUs (not yet GPU-verified on8bd243e6): Unblocks native export,compile_forward/aot_forwardtracing, and CUDA-graph capture on low-SM GPUs for multi-CTA vocabularies whose FP32 probabilities satisfyprob_ctas <= multi_processor_count(such as65,536and154,880tokens on an 8-SM Jetson Orin Nano) without allocating a duplicate[rows, vocab]FP32 buffer, while failing fast instead of deadlocking whenprob_ctas > multi_processor_count.softmax -> top_k_renorm_probs(..., is_deterministic=True)is monotone with logit-space top-k up to FP32 softmax underflow/rounding ties on extreme negative logits and FlashInfer's2^44fixed-point probability renormalization.> 16-SM GPUs: Zero code-path or performance change (SM120,SM121,SM103remain ontop_k_mask_logits_out).Supporting evidence and limitations
Tested on clean
git archive 8bd243e6f82e614c2d7494197bddf33a8ac258a6atopNVIDIA/hyperflare-inferencemain(7bbc6707792aa1cb8633794ee189b7592091cc45):8bd243e6f82e614c2d7494197bddf33a8ac258a6):ruff==0.12.8 check ignition/components/flashinfer_sampling.py ignition/components/sampling.py tests/components/test_flashinfer_sampling_dispatch.py:All checks passed!.CUDA_VISIBLE_DEVICES="" pytest tests/components/test_flashinfer_sampling_dispatch.py tests/preparation/test_core_boundary.py -v:16 passed(12/12dispatch, FP32/BF16 residency-guard, C++ argument-order forwarding, and realmake_fx+_lower_storage+_serialized_invocationstracing tests;4/4core boundary checks).FLARE_RUN_CUDA_TESTS=1 pytest tests/components/test_sampling_flashinfer.pycovering eager,compile_forward=True, andcompile_forward='aot', CUDA-graph capture/replay, in-placeprobs == renorm_probsaliasing verification,row_statesworkspace reset across replays, and numerical parity comparison againsttop_k_mask_logits_out -> softmax) has not yet been run on8bd243e6f82e614c2d7494197bddf33a8ac258a6on either> 16-SM (SM120/SM121) or<= 16-SM (SM87) hardware.prob_ctas > multi_processor_count(such as248,320tokens on an 8-SM GPU with 99 KiB opt-in shared memory) intentionally raiseRuntimeErrorrather than deadlockingRadixTopKRenormProbMultiCTA.Discord: Dooner