support swiglu a4w4 moe#674
Open
XiaobingSuper wants to merge 5 commits intoROCm:mainfrom
Open
Conversation
629d26c to
31b4b7a
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds an environment-variable-controlled switch in Mxfp4MoEMethod.process_weights_after_loading() to support an alternate (generic) preshuffle layout for MXFP4 (fp4x2) MoE layers using the SwiGLU activation, while preserving a legacy A16W4-style layout behind a fallback branch.
Changes:
- Add
GPTOSS_USE_GENERIC_SWIGLU_MXFP4_LAYOUTgate to choose between generic vs legacy SwiGLU shuffle paths. - Introduce
_shuffle_generic_mxfp4_weight_scale()helper to shuffle MXFP4 weight scales for the generic preshuffle layout. - Update the SwiGLU weight/scale processing to use
shuffle_weights()+ the new scale shuffler when the generic path is enabled.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+61
to
+63
| def _use_generic_swiglu_mxfp4_layout() -> bool: | ||
| return os.environ.get("GPTOSS_USE_GENERIC_SWIGLU_MXFP4_LAYOUT", "0") == "1" | ||
|
|
|
|
||
|
|
||
| def _use_generic_swiglu_mxfp4_layout() -> bool: | ||
| return os.environ.get("GPTOSS_USE_GENERIC_SWIGLU_MXFP4_LAYOUT", "0") == "1" |
Comment on lines
+894
to
+901
| if _use_generic_swiglu_mxfp4_layout(): | ||
| # New GPT-OSS A4W4 Swiglu path: use the same generic preshuffle | ||
| # layout for bf16 and fp4x2 activations. | ||
| shuffle_weights(layer.w13_weight, layer.w2_weight) | ||
| shuffled_w13_scale, shuffled_w2_scale = ( | ||
| _shuffle_generic_mxfp4_weight_scale(layer.w13_weight_scale), | ||
| _shuffle_generic_mxfp4_weight_scale(layer.w2_weight_scale), | ||
| ) |
Comment on lines
+72
to
+78
| # Generic preshuffle packs the combined [expert, row] axis, not experts alone. | ||
| rows = 1 | ||
| for dim in scale.shape[:-1]: | ||
| rows *= dim | ||
| return fp4_utils.e8m0_shuffle(scale.reshape(rows, scale.shape[-1])).reshape( | ||
| scale.shape | ||
| ) |
717a527 to
58fe8a3
Compare
|
|
||
|
|
||
| def _use_generic_swiglu_mxfp4_layout() -> bool: | ||
| return os.environ.get("GPTOSS_USE_GENERIC_SWIGLU_MXFP4_LAYOUT", "0") == "1" |
Comment on lines
+896
to
+903
| if _use_generic_swiglu_mxfp4_layout(): | ||
| # New GPT-OSS A4W4 Swiglu path: use the same generic preshuffle | ||
| # layout for bf16 and fp4x2 activations. | ||
| shuffle_weights(layer.w13_weight, layer.w2_weight) | ||
| shuffled_w13_scale, shuffled_w2_scale = ( | ||
| _shuffle_generic_mxfp4_weight_scale(layer.w13_weight_scale), | ||
| _shuffle_generic_mxfp4_weight_scale(layer.w2_weight_scale), | ||
| ) |
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
Add ATOM-side support for GPT-OSS SwiGLU A4W4/MXFP4 MoE weight layout selection.
The AITER PR for GPT-OSS SwiGLU MoE supports both the legacy A16W4-style layout and a generic MXFP4 preshuffled layout. ATOM needs to prepare GPT-OSS MoE weights/scales in the matching layout before dispatching into AITER.
Technical Details
GPTOSS_USE_GENERIC_SWIGLU_MXFP4_LAYOUTswitch in ATOM.0) to preserve the original/legacy path.1to use the new generic MXFP4 layout.[expert, row]axes beforee8m0_shuffle.shuffle_weight_a16w4/shuffle_scale_a16w4path.shuffle_weights(...)forw13/w2and the new generic scale shuffle helper.Test Plan
GPTOSS_USE_GENERIC_SWIGLU_MXFP4_LAYOUT.GPTOSS_USE_GENERIC_SWIGLU_MXFP4_LAYOUT=1.Notes
This PR only changes ATOM-side weight/scale/bias preparation. The kernel dispatch and tuned GPT-OSS FlyDSL/CK-Tile behavior are handled in the corresponding AITER PR.
Test Result
Submission Checklist