Repository navigation
[Perf] logits: Cast bf16 logits into the fp32 buffer with a Triton kernel - #46167
Merged
Merged
Conversation
hnyls2002
requested review from
BBuf,
DarkSharpness,
Edwardf0t1,
Fridge003,
HaiShaw,
HydraQYH,
Ying1123,
celve,
ch-wan,
ispobock,
merrymercy and
yuan-luo
as code owners
October 23, 2026 21:56
Collaborator
Author
|
/rerun-test registered/rl/test_fp32_lm_head.py registered/unit/kernels/test_kernels_namespace.py |
Collaborator
Author
|
/tag-and-rerun-ci |
Contributor
|
🚀 🚀 |
detain
pushed a commit
to detain/sglang
that referenced
this pull request
Oct 29, 2026
…fer (sgl-project#45631) Port of merged upstream f1e26dc. Deviation: the muse_spark.py hunk was dropped (modify/delete conflict). python/sglang/srt/models/muse_spark.py entered upstream main via sgl-project#44666, which our stack never merged; the file is absent here and nothing in-tree subclasses _compute_lm_head, so the drop is trivially disjoint. If the muse-spark runtime is ever ported, its _compute_lm_head override must gain the out= kwarg from the PR head. logits_processor.py merged clean against our drifted copy: the missing upstream gathered-softcap/defer_verify_gather region sits between the hunks and the local pcie_ipc=True kwarg (entry 162) is elsewhere in the file; zero conflict markers. Part 1 of 3 of the logits trilogy (do not take without sgl-project#45855 and sgl-project#46167: this commit alone can round FP32 output differently than the unbuffered path, fixed by sgl-project#45855, and the plain copy is slow, fixed by sgl-project#46167). (cherry picked from commit f1e26dc) (cherry picked from commit d60560f25ae068d209f885f6639fdba2f6c9cda5)
detain
pushed a commit
to detain/sglang
that referenced
this pull request
Oct 29, 2026
…rnel (sgl-project#46167) Port of merged upstream f05ad5e. Closes the logits trilogy with sgl-project#45631 + sgl-project#45855 (take all three). Union resolutions / deviations: 1. logits_processor.py import block: took cast_to_float32_logits as a standalone import (our per-name import idiom) and DROPPED the gathered_softcap_logits import line from the conflict's incoming side -- that symbol belongs to the upstream gather-fused/deferred- verify region our stack never merged (same as at sgl-project#45631's base drift; not in our kernels copy). 2. kernels/ops/activation/softcap.py: conflict carried the PR's new cast_to_float32_logits wrapper welded to the upstream-only _gathered_softcap_logits_kernel/gathered_softcap_logits block; kept only the wrapper, dropped the gather block (same reason as 1). The APPLY_SOFTCAP constexpr hunks applied clean around our local softcap_out autotune surface (untouched). 3. kernels/ops/activation/__init__.py: SILENT auto-merge danger -- git applied the registration verbatim with capabilities=CUDA_ONLY, but our refactor removed that import (file uses local _CUDA = frozenset({CapabilityRequirement.CUDA})). Changed to capabilities=_CUDA; value-identical to upstream CUDA_ONLY (python/sglang/kernels/spec.py:181), verified by import + test_kernels_namespace 76P. (cherry picked from commit f05ad5e) (cherry picked from commit 6cec0a80a49d18822eeea8bcca9ae9004aea37ed)
detain
added a commit
to detain/sglang
that referenced
this pull request
Oct 29, 2026
…5631/sgl-project#45855/sgl-project#46167 (entries 271-274) ONE docs commit: the logits trilogy is a CONTRACT UNIT -- recorded as 'never take 45631/45855 without 46167' per entry 274. Also on record: sgl-project#44124's STRING_PARAM_TYPES union + entry-159/160 retention + the streaming-fast-path call-site adaptation (141F before amend); sgl-project#45631's muse_spark hunk DROP with the sgl-project#44666-then re-check note; sgl-project#46167's wrapper-only softcap keep and the SILENT-AUTO-MERGE hazard fix (CUDA_ONLY -> local _CUDA, value-identical, kernels_namespace 76P proves). Battery EXACT: function_call 652P/1964sub on top of batch-1+2, numeric 4P/156sub, kernels_namespace 76P, spec dir 335P/11S/180sub (batch-1 pin survives all 14 picks). FLAGGED: sampling 223P/2S/43sub measured vs 263P predicted -- predicted number irreproducible on the worker's OWN tip with diff-0 across waves (prediction-vs-method gap, not landed code); logits 56P/7S unverifiable (pre-existing module-level get_device() CPU collect failure + all 4 GPUs busy with the live prod server) -- folded into the trilogy's GPU-debt block.
This was referenced Oct 29, 2026
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.
Motivation
When a model's lm_head returns bf16 logits and the forward has a shared fp32 logits buffer (CUDA graph decode, speculative verify),
_copy_logits_to_bufferfills the buffer withlogits_buffer.copy_(logits). On Blackwell this dtype-casting copy runs well below memory bandwidth, and at speculative-verify batch sizes (many rows x a full vocabulary) it shows up as one of the larger single kernels of a decode step.Modifications
softcap.py:softcap_inplace_logits_kernelgains anAPPLY_SOFTCAPconstexpr; the newcast_to_float32_logits(logits, output)uses the same launcher without the softcap.activation/__init__.py: registeractivation.cast_to_float32_logitsnext tosoftcap_to_float32_logits.logits_processor.py: in the buffered branch of_copy_logits_to_buffer, CUDA fp16/bf16 logits are written by the new kernel; fp32 logits and the unbuffered path are unchanged.No numerical change: the fp16/bf16 to fp32 conversion is exact, and the buffer contents are byte-identical to the
copy_result.Verification
copy_for bf16 and fp16 inputs, contiguous and vocab-padded (sliced) layouts, at several row counts, with inf, NaN, -0.0 and tied maxima in the inputs; argmax of the buffer unchanged.test/registered/rl/test_fp32_lm_head.pypasses on GB300 (covers the buffered path, vocab slicing, softcap and CUDA graph replay)._copy_logits_to_bufferat speculative-verify shapes on GB300 under CUDA graphs: faster at every size tested.CI States
Latest PR Test (Base): 🚫 Run #40030308997
Latest PR Test (Extra): ❌ Run #40030309098
Latest PR Test (AMD ROCm 10): 🚫 Run #40030309145