Skip to content

[bugfix] make fp8 scale_inv contiguous before TP/PP collectives - #197

Merged
tastelikefeet merged 1 commit into
modelscope:mainfrom
tastelikefeet:fix/fp8-scale-inv-contiguous
Sep 15, 2026
Merged

tastelikefeet merged 1 commit into
modelscope:mainfrom
tastelikefeet:fix/fp8-scale-inv-contiguous

Conversation

@tastelikefeet

Copy link
Copy Markdown
Collaborator

_get_weight trims the padding that TE adds to _rowwise_scale_inv, and slicing the last dim returns a non-contiguous view. Grouped MoE experts keep the weight as a single 3D tensor, so mg_scale_inv[0] preserves that view and hands it straight to _all_gather_tp, where ProcessGroupNCCL raises ValueError: Tensors must be contiguous. This breaks megatron export --fp8_recipe blockwise --fp8_param_gather true whenever TP > 1, and would break dist.broadcast in _broadcast_ep_pp for TP == 1 with PP > 1.

Call .contiguous() at the slice site so both collectives are covered. It is a no-op when TE did not pad the last dim, so the common path keeps the same storage and adds no copy; when it does copy, the tensor is 1/128 of the fp8 data. Values are unchanged.

Multi-shard weights were unaffected because torch.concat already returns a contiguous tensor, which is why only grouped-GEMM MoE hit this.

Fixes modelscope/ms-swift#10136

`_get_weight` trims the padding that TE adds to `_rowwise_scale_inv`, and
slicing the last dim returns a non-contiguous view. Grouped MoE experts keep
the weight as a single 3D tensor, so `mg_scale_inv[0]` preserves that view and
hands it straight to `_all_gather_tp`, where ProcessGroupNCCL raises
`ValueError: Tensors must be contiguous`. This breaks
`megatron export --fp8_recipe blockwise --fp8_param_gather true` whenever
TP > 1, and would break `dist.broadcast` in `_broadcast_ep_pp` for TP == 1
with PP > 1.

Call `.contiguous()` at the slice site so both collectives are covered. It is
a no-op when TE did not pad the last dim, so the common path keeps the same
storage and adds no copy; when it does copy, the tensor is 1/128 of the fp8
data. Values are unchanged.

Multi-shard weights were unaffected because `torch.concat` already returns a
contiguous tensor, which is why only grouped-GEMM MoE hit this.

Fixes modelscope/ms-swift#10136
@tastelikefeet
tastelikefeet merged commit 2650bc0 into modelscope:main Sep 15, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

qwen3.6 moe 35a3 megatron fp8 导出失败

2 participants