-
Notifications
You must be signed in to change notification settings - Fork 664
Support MXFP4 for GPT-OSS #5409
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
Changes from all commits
f07c584
e0f9cef
6e1ab62
6c6f26f
cfaf44d
6d1dd20
885625d
260c82c
49001b3
51c53de
73527d5
cffd70e
1926c54
593b3d4
7c6d5ef
7d42a53
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -249,14 +249,20 @@ def __init__( | |||||
| ) | ||||||
|
|
||||||
| def weight_loader( | ||||||
| self, param, loaded_weight, expert_id, shard_id: Optional[str] = None, source: Optional[str] = None | ||||||
| self, | ||||||
| param, | ||||||
| loaded_weight, | ||||||
| expert_id, | ||||||
| shard_id: Optional[str] = None, | ||||||
| source: Optional[str] = None, | ||||||
| loaded_weight_name: Optional[str] = None, | ||||||
| ): | ||||||
| """ | ||||||
| source:Avoid redundant transpose of fused weights when weight_loader is called iteratively | ||||||
| """ | ||||||
| if expert_id is None and shard_id is None: | ||||||
| # MoE experts has been fused in disk | ||||||
| self._load_fused_experts_weight(param, loaded_weight) | ||||||
| self._load_fused_experts_weight(param, loaded_weight, loaded_weight_name) | ||||||
| return | ||||||
| if hasattr(param, "SHARD_ID_TO_SHARDED_DIM"): | ||||||
| SHARD_ID_TO_SHARDED_DIM = param.SHARD_ID_TO_SHARDED_DIM | ||||||
|
|
@@ -368,7 +374,7 @@ def _load_down_weight(self, param, expert_id, loaded_weight, shard_id, shard_dim | |||||
| loaded_weight = loaded_weight.cast(expert_param.dtype) | ||||||
| h2d_copy(dst=expert_param, src=loaded_weight) | ||||||
|
|
||||||
| def _load_fused_experts_weight(self, param, loaded_weight): | ||||||
| def _load_fused_experts_weight(self, param, loaded_weight, loaded_weight_name: Optional[str] = None): | ||||||
| if self.tp_size > 1: | ||||||
| dim = -1 | ||||||
| if isinstance(loaded_weight, (np.ndarray, paddle.Tensor)): | ||||||
|
|
@@ -379,10 +385,75 @@ def _load_fused_experts_weight(self, param, loaded_weight): | |||||
| shard_offset = self.tp_rank * block_size | ||||||
| shard_size = (self.tp_rank + 1) * block_size | ||||||
| loaded_weight = slice_fn(loaded_weight, dim, shard_offset, shard_size) | ||||||
| assert param.shape == loaded_weight.shape, ( | ||||||
| f"Attempted to load weight ({loaded_weight.shape}) " f"into parameter ({param.shape})" | ||||||
| ) | ||||||
| h2d_copy(dst=param, src=loaded_weight) | ||||||
|
|
||||||
| if self.moe_quant_config.name() == "mxfp4": | ||||||
|
||||||
| if self.moe_quant_config.name() == "mxfp4": | |
| if self.moe_quant_config and self.moe_quant_config.name() == "mxfp4": |
Copilot
AI
Dec 5, 2025
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.
The function _interleave_mxfp4_cutlass_sm90 is duplicated - it appears both here and in fastdeploy/model_executor/layers/quantization/mxfp4.py (lines 297-302 and 422-427). Consider extracting this as a shared utility function to avoid code duplication and improve maintainability.
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.
For consistency with other boolean environment variables in this file (e.g.,
FD_USE_DEEP_GEMM,FD_USE_HF_TOKENIZER), the value should be converted to a boolean usingbool(int(os.getenv(...)))pattern instead of returning a string "0". This ensures consistent handling of boolean environment variables throughout the codebase.