-
Notifications
You must be signed in to change notification settings - Fork 6.3k
[ROCm] Hotpatch aiter gluon pa_mqa_logits 3D instr_shape for GLM-5 (Triton 3.5+) #26572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ChangLiu0709
wants to merge
1
commit into
sgl-project:main
Choose a base branch
from
ChangLiu0709:chang/glm5-rocm-gluon-pa-mqa-instr-shape
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| #!/usr/bin/env python3 | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| """Idempotently patch aiter gluon pa_mqa_logits for Triton >= 3.5 MFMA instr_shape. | ||
|
|
||
| The base _gluon_deepgemm_fp8_paged_mqa_logits variant hardcoded 2D instr_shape | ||
| [16, 16] on older aiter commits. Triton 3.5+ requires 3D [16, 16, 32] when | ||
| _Use_2d_instr_shape_mfma_layout is false (GLM-5 NSA / deepgemm path). | ||
|
|
||
| Upstream fix: ROCm/aiter a1bdcec (#2575). This hotpatch remains for ROCm images | ||
| that still ship an older vendored aiter until images are rebuilt. | ||
|
|
||
| Usage: | ||
| python3 patch_aiter_gluon_pa_mqa_logits.py [AITER_REPO_ROOT] | ||
| Default AITER_REPO_ROOT: /sgl-workspace/aiter | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import os | ||
| import sys | ||
|
|
||
| _SENTINEL = "[PATCHED] 3D instr_shape for base gluon variant" | ||
|
|
||
| _OLD = """\ | ||
| mfma_layout: gl.constexpr = gl.amd.AMDMFMALayout( | ||
| version=CDNA_VERSION, | ||
| instr_shape=[16, 16], | ||
| transposed=False, | ||
| warps_per_cta=[1, NumWarps], | ||
| ) | ||
| mfma_layout_a: gl.constexpr = gl.DotOperandLayout( | ||
| operand_index=0, parent=mfma_layout, k_width=16 | ||
| ) | ||
| mfma_layout_b: gl.constexpr = gl.DotOperandLayout( | ||
| operand_index=1, parent=mfma_layout, k_width=16 | ||
| )""" | ||
|
|
||
| _NEW = """\ | ||
| # [PATCHED] 3D instr_shape for base gluon variant | ||
| if _Use_2d_instr_shape_mfma_layout: | ||
| mfma_layout: gl.constexpr = gl.amd.AMDMFMALayout( | ||
| version=CDNA_VERSION, | ||
| instr_shape=[16, 16], | ||
| transposed=False, | ||
| warps_per_cta=[1, NumWarps], | ||
| ) | ||
| else: | ||
| mfma_layout: gl.constexpr = gl.amd.AMDMFMALayout( | ||
| version=CDNA_VERSION, | ||
| instr_shape=[16, 16, 32], | ||
| transposed=False, | ||
| warps_per_cta=[1, NumWarps], | ||
| ) | ||
| mfma_layout_a: gl.constexpr = gl.DotOperandLayout( | ||
| operand_index=0, parent=mfma_layout, k_width=16 | ||
| ) | ||
| mfma_layout_b: gl.constexpr = gl.DotOperandLayout( | ||
| operand_index=1, parent=mfma_layout, k_width=16 | ||
| )""" | ||
|
|
||
|
|
||
| def patch_gluon_pa_mqa_logits(aiter_root: str) -> bool: | ||
| target = os.path.join( | ||
| aiter_root, "aiter", "ops", "triton", "gluon", "pa_mqa_logits.py" | ||
| ) | ||
| if not os.path.isfile(target): | ||
| print(f"[aiter-hotpatch] {target} not found, skipping") | ||
| return False | ||
|
|
||
| src = open(target, encoding="utf-8").read() | ||
| if _SENTINEL in src: | ||
| print("[aiter-hotpatch] gluon pa_mqa_logits 3D instr_shape already applied") | ||
| return False | ||
|
|
||
| if _OLD not in src: | ||
| print( | ||
| "[aiter-hotpatch] WARN: gluon pa_mqa_logits pattern not found " | ||
| "(aiter may already include ROCm/aiter#2575)" | ||
| ) | ||
| return False | ||
|
|
||
| new_src = src.replace(_OLD, _NEW, 1) | ||
| with open(target, "w", encoding="utf-8") as f: | ||
| f.write(new_src) | ||
| print("[aiter-hotpatch] Patched gluon pa_mqa_logits 3D instr_shape (base variant)") | ||
| return True | ||
|
|
||
|
|
||
| def main() -> int: | ||
| aiter_root = sys.argv[1] if len(sys.argv) > 1 else "/sgl-workspace/aiter" | ||
| patch_gluon_pa_mqa_logits(aiter_root) | ||
| return 0 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| sys.exit(main()) | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is recommended to use a
withstatement when opening files to ensure that file descriptors are closed properly and promptly, rather than relying on garbage collection.