Conversation
The `flydsl.expr.buffer_ops` import broke in FlyDSL 7dac082, and the module also reached into `flydsl._mlir`, `CompilationContext`, and raw MLIR dialect builders -- none of which are in the shipped wheel or the stability contract. Rewrite both kernels on the stable surface (`fx.rocdl.make_buffer_tensor`, `SharedAllocator` + `@fx.struct`, `fx.gpu.*`, `fx.math.rsqrt`) and add an import-time capability guard that raises ImportError so the existing native fallback still engages. Custom-op ABI, launch geometry, and the hardcoded eps are unchanged. Outputs are bit-exact vs the pre-change kernel on gfx942 and gfx950; latency within 3%, VGPR 38->32. Tests 8 -> 22 cases.
Contributor
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
This was referenced Aug 8, 2026
yctseng0211
added a commit
to yctseng0211/sglang
that referenced
this pull request
Aug 25, 2026
Rebase of sgl-project#33144 onto the post-sgl-project#35114 layout: the kernel now lives at norm/fused_residual_norm_flydsl.py and sgl-project#34536's import fallback is dropped, since the capability guard supersedes it. Co-authored-by: Phil Li <haicli@amd.com>
5 tasks
This branch has not been deployed
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
Fixes #33142.
fused_residual_norm.pydoes not import against FlyDSL 0.3.0:flydsl.expr.buffer_opsmoved to
kernels.common.buffer_opsin FlyDSL7dac082(FlyDSL #880), and that packageis in the FlyDSL source tree rather than the wheel. Because both call sites in
multimodal_gen/runtime/layers/layernorm.pyguard the import withexcept ImportError,the ROCm fused-norm path is silently disabled and every call falls back to native, even
with
SGLANG_USE_ROCM_FLYDSL=1.Restoring that one import would not hold for long. 278 of the module's 902 lines
reference something outside FlyDSL's public surface (158 raw upstream MLIR dialect
builders, 122 unstable FlyDSL paths, 2 deprecated with a removal release already
announced). None of those carry a compatibility statement, so the same thing can happen
again at any FlyDSL minor release. Details and the full audit table are in #33142.
Modifications
Both kernel builders are rewritten against the FlyDSL 0.3.0 stable public API only:
fx.rocdl.make_buffer_tensor+fx.slice+fx.logical_divide+fx.make_copy_atom/fx.copy_atom_calloverfx.make_rmem_tensor, replacingbuffer_opsresources andflat element-offset arithmetic
fx.SharedAllocatorover an@fx.structlayout, replacing the hand-built dynamic LDSmemref and the explicit
smem=launch argumentfx.gpu.shuffle_xor/fx.gpu.barrier,fx.math.rsqrt,fx.memref_load/fx.memref_store, typed values and Python control flow, replacing thearith/gpu/memref/scf/vector/mathdialect builders andflydsl._mlir.irImportError(notAttributeError) when arequired stable symbol is missing, so the existing native fallback still engages against
an older FlyDSL
Deliberately unchanged: both
torch.library.custom_opnames, signatures and return arity;WARP_SIZE/_NUM_WAVES/_VEC/FLYDSL_NORM_MIN_ALIGNED_DIM; one block per row at 640threads; the two-stage reduction order; the phase-2 register cache;
_prep_slices; thecompile-cache key; and the hardcoded
eps = 1e-6.layernorm.pyis untouched.Broadcast operands previously addressed via a runtime
row * stride; they now select row 0through
(stride != 0).select(row, 0), which is equivalent because a broadcast operand isalways passed as a dense
(1, C)tensor.Tests go from 8 to 22 cases, adding the gate-free and no-affine specializations (both
previously untested), per-row scale/shift, a 4D frame-gate layout,
D=10240for a secondregister-cached iteration, a cross-
L/layout compile-cache reuse guard, and a wheel-onlyimport check that fails if the module ever depends on the FlyDSL source tree.
Accuracy Tests
Baseline captured by running the unmodified module under the same FlyDSL 0.3.0 build
via a validation-only
buffer_opsalias, so this is a same-compiler comparison.61 cases covering every specialization (
is_rmsxhas_gatexhas_weight), bothscale/shift layouts,
Din {5120, 10240},Lin {16, 90000}, and the 4D frame-gate layout:torch.equal)test_flydsl_fused_norm.pySpeed Tests and Profiling
Median over 300 iterations after 200 warmup, baseline and candidate alternated across 3
independent process pairs.
Final ISA is unchanged in every invariant that matters: 7
buffer_load_dwordx4,2
buffer_store_dwordx4, zero non-128-bit orglobal_*/flat_*accesses, 2ds_read/2
ds_write, 2s_barrier, and 12 cross-lane shuffles confirming the two-stage x six-stepreduction tree is preserved. Total instruction count 377 to 389.
Resources improve slightly: VGPR 38 to 32, no spills or scratch in either version, and LDS
goes from 88 B dynamic to 56 B static for RMSNorm (the unused accumulator is dead-code
eliminated) or 104 B for LayerNorm.
Known gaps
Two things a reviewer should know rather than discover:
.github/workflows/orscripts/, and the AMD runner image is resolved dynamically, soI cannot tell whether it ships FlyDSL 0.3.0. If it ships an older FlyDSL or none, these
tests fail rather than skip. That is not a regression (they fail on
maintoday for thesame underlying reason), but it likely needs a maintainer to confirm the image.
sglang.multimodal_genpulls insglang.srt, which does not import in a plainrocm/pytorchcontainer at this revision:transformers==5.12.1(thepyprojectpin)lacks
PreTrainedConfigrequired bysrt/configs/cohere2_moe.py, while5.14.1failson a duplicate
qwen3_asrregistration. This reproduces on both GPUs and is unrelated tothis change. I substituted a check on exactly what
layernorm.pydepends on (exportednames, both custom ops registered, the guard raising
ImportErrorverified by deletingfx.SharedAllocator, both call sites intact, and numerics at the dispatch shape), whichpasses on gfx942 and gfx950 — but the real
layernorm.pypath itself was never run.Out of scope, preserved exactly as-is and worth separate fixes:
epsis ignored, FP32affine weights are cast to BF16, 2D
[B, C]broadcasting is incorrect, there is noempty-tensor guard, and fused vs norm-only output dtype handling differs.
Checklist
CI States
Latest PR Test (Base): ❌ Run #30682896481
Latest PR Test (Extra): ❌ Run #30682896419