-
-
Notifications
You must be signed in to change notification settings - Fork 16.7k
[ROCm] Enable dual-stream MoE shared experts, AITER sparse MLA workaround, and GLM-5-FP8 weight loading fix #38665
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
ChuanLi1101
wants to merge
4
commits into
vllm-project:main
Choose a base branch
from
ChuanLi1101:fix/rocm-glm5-mxfp4-optimizations
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
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2b2028a
[ROCm] Enable dual-stream MoE shared experts and GLM-5 MXFP4 Quark su…
ChuanLi1101 ba2e2f2
[ROCm] Work around AITER sparse MLA ZeroDivisionError for < 16 heads
ChuanLi1101 2ad2f33
Fix ruff format in rocm_aiter_mla_sparse.py
ChuanLi1101 e40e395
[ROCm] Fix GLM-5-FP8 weight loading for fused indexer wk_weights_proj
ChuanLi1101 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -644,36 +644,20 @@ def __init__( | |
| quant_config=quant_config, | ||
| prefix=f"{prefix}.wq_b", | ||
| ) | ||
| if self.is_fp4_ckpt: | ||
| # Fused wk + weights_proj: single GEMM producing [head_dim + n_head]. | ||
| # weights_proj does not get quantized, | ||
| # so we run both with quant_config=None | ||
| # wk may be upcasted from the default quant; | ||
| # experiments show fusion is always faster unless WK proj is in FP4, | ||
| # which is not the case for all known quants. | ||
| self.wk_weights_proj = MergedColumnParallelLinear( | ||
| hidden_size, | ||
| [self.head_dim, self.n_head], | ||
| bias=False, | ||
| quant_config=None, | ||
| disable_tp=True, | ||
| prefix=f"{prefix}.wk_weights_proj", | ||
| ) | ||
| else: | ||
| self.wk = ReplicatedLinear( | ||
| hidden_size, | ||
| self.head_dim, | ||
| bias=False, | ||
| quant_config=quant_config, | ||
| prefix=f"{prefix}.wk", | ||
| ) | ||
| self.weights_proj = ReplicatedLinear( | ||
| hidden_size, | ||
| self.n_head, | ||
| bias=False, | ||
| quant_config=None, | ||
| prefix=f"{prefix}.weights_proj", | ||
| ) | ||
| # Fused wk + weights_proj: single GEMM producing [head_dim + n_head]. | ||
| # FP4 checkpoints don't quantize weights_proj, so use quant_config=None. | ||
| # Other quantized checkpoints (e.g. GLM-5-FP8) may quantize the fused | ||
| # tensor, so pass quant_config to create weight_scale_inv parameters. | ||
| # Checkpoints with separate wk/weights_proj tensors are handled by the | ||
| # stacked_params_mapping in load_weights. | ||
| self.wk_weights_proj = MergedColumnParallelLinear( | ||
| hidden_size, | ||
| [self.head_dim, self.n_head], | ||
| bias=False, | ||
| quant_config=None if self.is_fp4_ckpt else quant_config, | ||
| disable_tp=True, | ||
| prefix=f"{prefix}.wk_weights_proj", | ||
| ) | ||
| self.k_norm = LayerNorm(self.head_dim, eps=1e-6) | ||
| self.softmax_scale = self.head_dim**-0.5 | ||
|
|
||
|
|
@@ -714,14 +698,9 @@ def forward( | |
| q_pe, q_nope = torch.split( | ||
| q, [self.rope_dim, self.head_dim - self.rope_dim], dim=-1 | ||
| ) | ||
| if self.is_fp4_ckpt: | ||
| # Fused wk + weights_proj: one GEMM, then split | ||
| kw, _ = self.wk_weights_proj(hidden_states) | ||
| k = kw[:, : self.head_dim] | ||
| weights = kw[:, self.head_dim :] | ||
| else: | ||
| k, _ = self.wk(hidden_states) | ||
| weights, _ = self.weights_proj(hidden_states) | ||
| kw, _ = self.wk_weights_proj(hidden_states) | ||
| k = kw[:, : self.head_dim] | ||
| weights = kw[:, self.head_dim :] | ||
|
|
||
| k = self.k_norm(k) | ||
| k_pe, k_nope = torch.split( | ||
|
|
@@ -1469,8 +1448,13 @@ def load_weights(self, weights: Iterable[tuple[str, torch.Tensor]]) -> set[str]: | |
| ("qkv_proj", "k_proj", "k"), | ||
| ("qkv_proj", "v_proj", "v"), | ||
| ] | ||
| if self.is_fp4_ckpt: | ||
| # Fused indexer wk + weights_proj (shard 0 = wk, shard 1 = weights_proj) | ||
| if self.is_v32: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like |
||
| # Fused indexer wk + weights_proj (shard 0 = wk, shard 1 = weights_proj). | ||
| # For checkpoints with separate wk/weights_proj tensors, this mapping | ||
| # loads them into the fused MergedColumnParallelLinear shards. | ||
| # For checkpoints that already have fused wk_weights_proj (e.g. | ||
| # GLM-5-FP8), the substring match is a false positive and the | ||
| # fallback check in the loading loop skips it gracefully. | ||
| indexer_fused_mapping = [ | ||
| ("wk_weights_proj", "wk", 0), | ||
| ("wk_weights_proj", "weights_proj", 1), | ||
|
|
@@ -1528,11 +1512,12 @@ def load_weights(self, weights: Iterable[tuple[str, torch.Tensor]]) -> set[str]: | |
| continue | ||
| name_mapped = name.replace(weight_name, param_name) | ||
|
|
||
| # QKV fusion is optional, fall back to normal | ||
| # weight loading if it's not enabled | ||
| # if go with fusion option, then update name | ||
| # QKV fusion and indexer fusion are optional — fall back to | ||
| # direct weight loading when the mapped name doesn't exist | ||
| # (e.g. fused checkpoints where "wk" falsely matches | ||
| # "wk_weights_proj", or when QKV fusion is disabled). | ||
| if ( | ||
| param_name == "fused_qkv_a_proj" | ||
| param_name in ("fused_qkv_a_proj", "wk_weights_proj") | ||
| ) and name_mapped not in params_dict: | ||
| continue | ||
| else: | ||
|
|
||
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
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.
I think this will break the main checkpoint which has different dtypes for these