Repository navigation
[MoE] Make routed expert projections first-class grouped linears - #4539
Conversation
Summary: Add the single TorchTitan-owned guide for the standalone Dist-MoE backend. It documents conversion, checkpoint compatibility, the shared MXFP8/FSDP lifecycle, memory and VMM ownership, pipeline slot planning, configuration, and cleanup. Kernel and allocator internals remain in the package documentation. It distinguishes the direct ordinary-eager entry from the registered ordered-effect entry used under dispatch and tracing. This change defines no independent runtime contract and does not duplicate kernel derivations. Examples must continue to match the registered config schema and the released package API. Dependencies and risks: - Documentation follows #4539-#4542/#4559 and the released annex API. - Broken links or stale examples are release-blocking documentation drift. Test Plan: - `pre-commit run --files README.md docs/dist_moe.md` - Markdown link check and executable validation of copied configuration examples. ghstack-source-id: cc45371 Pull-Request: #4543
Summary: Add the single TorchTitan-owned guide for the standalone Dist-MoE backend. It documents conversion, checkpoint compatibility, the shared MXFP8/FSDP lifecycle, memory and VMM ownership, pipeline slot planning, configuration, and cleanup. Kernel and allocator internals remain in the package documentation. It distinguishes the direct ordinary-eager entry from the registered ordered-effect entry used under dispatch and tracing. This change defines no independent runtime contract and does not duplicate kernel derivations. Examples must continue to match the registered config schema and the released package API. Dependencies and risks: - Documentation follows #4539-#4542/#4559 and the released annex API. - Broken links or stale examples are release-blocking documentation drift. Test Plan: - `pre-commit run --files README.md docs/dist_moe.md` - Markdown link check and executable validation of copied configuration examples. ghstack-source-id: cc45371 Pull-Request: #4543
Summary: Add the single TorchTitan-owned guide for the standalone Dist-MoE backend. It documents conversion, checkpoint compatibility, the shared MXFP8/FSDP lifecycle, memory and VMM ownership, pipeline slot planning, configuration, and cleanup. Kernel and allocator internals remain in the package documentation. It distinguishes the direct ordinary-eager entry from the registered ordered-effect entry used under dispatch and tracing. This change defines no independent runtime contract and does not duplicate kernel derivations. Examples must continue to match the registered config schema and the released package API. Dependencies and risks: - Documentation follows #4539-#4542/#4559 and the released annex API. - Broken links or stale examples are release-blocking documentation drift. Test Plan: - `pre-commit run --files README.md docs/dist_moe.md` - Markdown link check and executable validation of copied configuration examples. ghstack-source-id: ec33322 Pull-Request: #4543
Summary: Add the single TorchTitan-owned guide for the standalone Dist-MoE backend. It documents conversion, checkpoint compatibility, the shared MXFP8/FSDP lifecycle, memory and VMM ownership, pipeline slot planning, configuration, and cleanup. Kernel and allocator internals remain in the package documentation. It distinguishes the direct ordinary-eager entry from the registered ordered-effect entry used under dispatch and tracing. This change defines no independent runtime contract and does not duplicate kernel derivations. Examples must continue to match the registered config schema and the released package API. Dependencies and risks: - Documentation follows #4539-#4542/#4559 and the released annex API. - Broken links or stale examples are release-blocking documentation drift. Test Plan: - `pre-commit run --files README.md docs/dist_moe.md` - Markdown link check and executable validation of copied configuration examples. ghstack-source-id: a2aec19 Pull-Request: #4543
Summary: Add the single TorchTitan-owned guide for the standalone Dist-MoE backend. It documents conversion, checkpoint compatibility, the shared MXFP8/FSDP lifecycle, memory and VMM ownership, pipeline slot planning, configuration, and cleanup. Kernel and allocator internals remain in the package documentation. It distinguishes the direct ordinary-eager entry from the registered ordered-effect entry used under dispatch and tracing. This change defines no independent runtime contract and does not duplicate kernel derivations. Examples must continue to match the registered config schema and the released package API. Dependencies and risks: - Documentation follows #4539-#4542/#4559 and the released annex API. - Broken links or stale examples are release-blocking documentation drift. Test Plan: - `pre-commit run --files README.md docs/dist_moe.md` - Markdown link check and executable validation of copied configuration examples. ghstack-source-id: a2aec19 Pull-Request: #4543
Summary: Add the single TorchTitan-owned guide for the standalone Dist-MoE backend. It documents conversion, checkpoint compatibility, the shared MXFP8/FSDP lifecycle, memory and VMM ownership, pipeline slot planning, configuration, and cleanup. Kernel and allocator internals remain in the package documentation. It distinguishes the direct ordinary-eager entry from the registered ordered-effect entry used under dispatch and tracing. This change defines no independent runtime contract and does not duplicate kernel derivations. Examples must continue to match the registered config schema and the released package API. Dependencies and risks: - Documentation follows #4539-#4542/#4559 and the released annex API. - Broken links or stale examples are release-blocking documentation drift. Test Plan: - `pre-commit run --files README.md docs/dist_moe.md` - Markdown link check and executable validation of copied configuration examples. ghstack-source-id: d0a1e01 Pull-Request: #4543
Summary: Add the single TorchTitan-owned guide for the standalone Dist-MoE backend. It documents conversion, checkpoint compatibility, the shared MXFP8/FSDP lifecycle, memory and VMM ownership, pipeline slot planning, configuration, and cleanup. Kernel and allocator internals remain in the package documentation. It distinguishes the direct ordinary-eager entry from the registered ordered-effect entry used under dispatch and tracing. This change defines no independent runtime contract and does not duplicate kernel derivations. Examples must continue to match the registered config schema and the released package API. Dependencies and risks: - Documentation follows #4539-#4542/#4559 and the released annex API. - Broken links or stale examples are release-blocking documentation drift. Test Plan: - `pre-commit run --files README.md docs/dist_moe.md` - Markdown link check and executable validation of copied configuration examples. ghstack-source-id: 8b8aaed Pull-Request: #4543
| "num_shared_experts": ( | ||
| moe.shared_experts.w13.out_features | ||
| // 2 | ||
| // moe.routed_experts.inner_experts.hidden_dim |
There was a problem hiding this comment.
This is confusing, and sounds buggy? cc @shuhuayu
There was a problem hiding this comment.
the existing script needs a refactor to adapt to inner_experts change, so it should be fine.
| return _quantize_then_scaled_grouped_mm( | ||
| A, | ||
| input_RI, | ||
| weight_EOI.bfloat16().transpose(-2, -1), | ||
| config=self._mxfp8_op_config, | ||
| offs=offs, | ||
| offs=offsets_E, | ||
| ) |
There was a problem hiding this comment.
Does this work with fused layout out of box? cc @anijain2305
There was a problem hiding this comment.
yes, it works.
Although there are pre-existing problems here that we should tackle separately
- MxFP8GroupedLinear only supports 1x32 scales (not 32x32 as we do for MxFP8Linear and very soon for DistMoE). We have paused mxfp8 work for experts for dist_moe.
- Again this is pre-existing, on the backward colwise quantization, there is no check that a block should only contain values from either gate or up logical tensors. So, it is possible that we end up with few blocks spanning the two matrices.
We should treat this as a followup (if we decide to do this).
| w13=GroupedLinear.Config( | ||
| group_size=num_experts, | ||
| in_features=dim, | ||
| out_features=(2, hidden_dim), |
There was a problem hiding this comment.
API different from your stacked linear, better to align (to either) @anijain2305
There was a problem hiding this comment.
I am not using stacked linear anymore, its folded into Linear - #4676 (still wip though).
| from torchtitan.models.common.moe import MoE | ||
|
|
||
|
|
||
| class ScaleBiasForward(torch.autograd.Function): |
There was a problem hiding this comment.
we should delete this, in favor of style in https://github.com/pytorch/torchtitan/blob/main/torchtitan/models/common/linear.py#L146
| return output_RO + bias_RO.to(output_RO.dtype) | ||
|
|
||
|
|
||
| class GptOssDownGroupedLinear(GptOssGroupedLinear): |
There was a problem hiding this comment.
|
@claude review this PR and check my latest comments. In particular, focus on
|
|
Claude finished @tianyu-l's task in 21m 17s —— View job Review — focus: quantization multi-dim
|
|
|
||
| if TYPE_CHECKING: | ||
| from torchtitan.models.kimi_k3.model import KimiK3Model | ||
| from torchtitan.models.kimi_k3.vision_encoder import KimiK3VisionEncoder |
There was a problem hiding this comment.
Are the removals in this file intended?
| @@ -61,105 +62,110 @@ def backward(ctx, grad_output): | |||
|
|
|||
| def swiglu(x, alpha: float = 1.702, limit: float = 7.0): | |||
There was a problem hiding this comment.
is anyone using this function now? If not then move swiglu_components inside the GptOssSwiGLU __call__?
| super().__init__(config) | ||
| self.tp_degree = 1 | ||
|
|
||
| def parallelize(self, parallel_dims) -> None: |
There was a problem hiding this comment.
I have been asked to not override parallelize method in the past. I have not yet fully understood why. Just pointing out.
There was a problem hiding this comment.
parallelize is more like Module-internal, which is used for recursively apply sharding, rather than plugging in attributes -- I had been wanting to make it private.
To get TP degree, use spmd_types.py context
There was a problem hiding this comment.
Use
tp_group = spmd_mesh_group(MeshAxisName.TP)
if tp_group is None:
....
| missing = {"w1_EFD", "w3_EFD"} - param_init.keys() | ||
| if missing: | ||
| raise ValueError(f"Missing routed-expert initializers: {sorted(missing)}") | ||
| return {"weight": _fused_grouped_gate_up_init(param_init)} |
There was a problem hiding this comment.
NIt - inline _fused_grouped_gate_up_init - codex insane error checking just keeps adding helper indirections.
| for layer in config.layers: | ||
| if layer.delta_attention is not None: | ||
| _set_inner_kda_sharding(layer.delta_attention.inner_kda) | ||
| if layer.moe is not None: |
There was a problem hiding this comment.
It seems like you have accidentally removed the kda sharding. This seems to be unintentional.
| ) | ||
|
|
||
|
|
||
| def _set_vision_buffer_sharding(config: "KimiK3VisionEncoder.Config") -> None: |
There was a problem hiding this comment.
same here - seems unintentional.
|
Overall looks great. Left a few comments. The changes in kimi3 seems wrong, and gpt-oss as others have pointed out might use a refactors. |
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
tianyu-l
left a comment
There was a problem hiding this comment.
I'd say it might be easier to review if you merged the two PRs together.
| **{param: Shard(2) for param in routed_experts.w13.parameters()}, | ||
| **{param: Shard(1) for param in routed_experts.w2.parameters()}, |
There was a problem hiding this comment.
instead of hardcoding w13, do something similar or in _linear_param_shard_placements
| group_size: Number of independently selected linear weights. | ||
| in_features: Input features for each linear. | ||
| out_features: Output features for each linear. | ||
| num_linears: Number of projections stored per group. Values greater |
There was a problem hiding this comment.
"Number of projections stored per group" is not correct -- the entire GroupedLinear is a single group.
Maybe something like "number of stacked linears per element in the group"
| @@ -55,37 +55,47 @@ def __init__( | |||
| def _to_logical_expert_state( | |||
| # if no EP, convert to V for grouped_mm, which would otherwise see | ||
| # x:R, w1:V, offsets:P in local SPMD typechecking. | ||
| # spmd.P is not currently allowed to mix with spmd.V. | ||
| # TODO(pianpwk): likely relax this in spmd_types. |
There was a problem hiding this comment.
comments and todos are gone
There was a problem hiding this comment.
Restored the local-SPMD comment and TODO at the new ownership boundary. It now explains why offsets are retyped from P to V when EP is absent and records the existing spmd_types restriction that should eventually be relaxed.
[ghstack-poisoned]
tianyu-l
left a comment
There was a problem hiding this comment.
please address final nits
| return output_RO + bias_RO.to(output_RO.dtype) | ||
|
|
||
|
|
||
| class GptOssMoE(MoE): |
There was a problem hiding this comment.
seems useless, can remove
| experts = transformer_block.moe.routed_experts.inner_experts | ||
| num_experts = experts.num_experts | ||
| routed_experts = transformer_block.moe.routed_experts | ||
| num_experts = routed_experts.w13.group_size |
There was a problem hiding this comment.
seems we can directly get from moe.num_experts, which sounds more robust than getting from "w13"
https://github.com/pytorch/torchtitan/blob/main/torchtitan/models/common/moe.py#L655
|
@claude
|
|
Claude finished @tianyu-l's task in 3m 30s —— View job GPT-OSS MoE review
Q1: Is correctness preserved under the different parallelisms?Yes, as far as I can tell from reading the code. With fixed weights, the new forward does the same work as the old one. Only the storage layout changed: the old interleaved
Some smaller points:
Q2: Where exactly does the numerics change come from?Only the parameter initialization changes the forward. The compute graph does not. The backward also differs, but only at the rounding level. 1. Main cause: the same RNG stream now lands in a different logical layout.
The random values are the same, but the new gate/up pairs are 2. Secondary, rounding-level: the order of reduction in the backward. 3. What does not contribute: the GEMM count and shape (still one The PR description is inaccurate for GPT-OSS. It says the move "changes its from-seed RNG order from W1, W2, W3 to W1, W3, W2 and replaces two BF16 grouped GEMMs with one wider W13 grouped GEMM". That describes the DeepSeek/Qwen path in #4643. GPT-OSS on base already had a single fused One way to prove this is to regenerate a golden with a one-off init hook: initialize an Summary: I found no correctness issue in the GPT-OSS changes under EP, EFSDP (both the expert-dim and row-shard paths), TP-without-EP, CP, PP, MXFP8/Float8, or the HF round-trip. The golden shift comes from the init-layout change, plus rounding-level backward differences. The PR description's explanation of it is wrong for GPT-OSS and should be fixed. It would also be worth adding a fixed-weight old-vs-new test for GPT-OSS. |
[ghstack-poisoned]
…inears" Summary: Replace the opaque `RoutedExperts.inner_experts` owner with explicit `w13`, `w2`, `activation_fn`, and `token_dispatcher` children. Add a reusable, bias-free `GroupedLinear` whose structured W13 storage is `[E, 2, F, D]`; grouped GEMM consumes a zero-copy `[E, 2F, D]` view. Its public configuration matches `Linear`: `out_features` names one projection's output width and `num_linears=2` retains the gate/up axis. This removes the temporary expert-owner, replacement, and sharding APIs raised in review. Eager FSDP, GraphTrainer, quantization converters, model-specific activations, and checkpoint adapters now share one explicit parameter hierarchy. Logical initializer names retain their shape suffixes (`w1_EFD`, `w2_EDF`, and `w3_EFD`), while runtime parameters use standard module keys (`w13.weight` and `w2.weight`). HF checkpoint schemas remain compatible through adapter-boundary conversion. DeepSeek V4 now performs the same native-to-logical expert conversion as the other adapters, preventing native W13 keys from leaking into exported HF checkpoints. FSDP derives matrix-row shard placements through the shared linear helper for both stacked `Linear` and `GroupedLinear` modules; no W13/W2 FQN special case remains. `MoE.num_experts` is the canonical runtime expert count, and GPT-OSS uses the shared `MoE.Config` without an empty model-specific subclass. The existing fused-linear state adapter helpers also own the optional routed W13 split/merge for HF schemas with separate expert projections, while GPT-OSS and Qwen3.5 retain their fused HF layouts. The standard MXFP8 and Float8 converters specialize each grouped linear at the grouped-MM seam. Kimi retains SiTU and its optimizer metadata addresses the native W13/W2 parameters. GPT-OSS keeps its grouped bias in a model-specific `GroupedLinear` subclass and otherwise follows current main: routed expert matrices are complete locally unless EP shards the expert axis. MXFP8 grouped linears retain their existing 1x32 weight-scale format. Structured W13 is flattened without a copy before quantization. Square 32x32 grouped weights and preventing a columnwise block from spanning an unaligned gate/up boundary remain a separate follow-up rather than expanding this ownership refactor. The parent W13 layout change already resets DeepSeek V3 and Qwen3 deterministic goldens. GPT-OSS already used one fused W13 grouped GEMM and initialized W13 before W2. Its numerical reset instead comes from changing W13 storage from HF-interleaved `[E, 2F, D]` to blocked `[E, 2, F, D]`: the same random values now initialize different gate/up rows. A local fixed-weight comparison converts the interleaved weight and bias into the blocked layout and produces bitwise equal forward output; only backward reduction ordering may introduce secondary rounding differences. GPT-OSS A10G fake-PG and real-PG goldens are regenerated from full-precision TensorBoard metrics. Test Plan: - `python -m pytest tests/unit_tests/cpu -q --deselect tests/unit_tests/cpu/test_lora.py::test_lora_forward` (1245 passed, 23 skipped, 1 deselected) - Focused GraphTrainer scheduling and chunk tests (108 passed, 120 deselected) - `python -m pytest -q tests/unit_tests/gpu/test_fsdp_moe_sharding.py tests/unit_tests/gpu/flex_shard/test_dist_muon.py tests/unit_tests/gpu/test_fused_swiglu_override.py tests/unit_tests/gpu/test_compile_moe.py` (25 passed) - Focused Kimi native-FQN/checkpoint tests (2 passed) and grouped-quantization CPU tests (10 passed) - Float8 structured-wrapper tests (2 passed); all 12 Float8 GPU tests collect. The local SM103 TorchAO grouped backward kernel is unsupported, so execution remains a B200 CI gate rather than a local workaround. - FSDP expert-placement tests cover expert-axis and matrix-row sharding through the generic linear placement helper. - State-dict adapter tests cover separate and fused HF expert schemas, including DTensor placement round-trips and DeepSeek V4 key validation. - A local old-interleaved versus new-blocked GPT-OSS fixed-weight forward comparison reports `torch_equal=True` and `max_abs_diff=0.0`. - A10G GPT-OSS fake-PG and real-PG numerics were exported from the exact CI configurations using full-precision TensorBoard metrics. - Scoped formatting, flake8, pydoclint, codespell, link, and targeted Pyrefly checks passed. Project-wide Pyrefly retains one unrelated nullable-video-duration baseline error. CI notes: - The B200 run https://github.com/pytorch/torchtitan/actions/runs/35924519733 failed while extracting the repository checkout (`gzip: unexpected end of file`) before tests executed. - The GraphTrainer failures in https://github.com/pytorch/torchtitan/actions/runs/35924514118 and https://github.com/pytorch/torchtitan/actions/runs/35924514111 reproduce in scheduled upstream-main runs https://github.com/pytorch/torchtitan/actions/runs/35860469802 and https://github.com/pytorch/torchtitan/actions/runs/35859018087, respectively. [ghstack-poisoned]
|
Kept these as two PRs because they have separate ownership and review surfaces: #4643 introduces the structured physical W13 layout, while this PR introduces first-class |
|
Addressed the final nits and reconciled the older displaced comments: GPT-OSS now uses the shared |
|
The GPT-OSS description now states the precise source of the deterministic reset: GPT-OSS already had one fused W13 grouped GEMM and initialized W13 before W2; changing storage from HF-interleaved |
…inears" Summary: Replace the opaque `RoutedExperts.inner_experts` owner with explicit `w13`, `w2`, `activation_fn`, and `token_dispatcher` children. Add a reusable, bias-free `GroupedLinear` whose structured W13 storage is `[E, 2, F, D]`; grouped GEMM consumes a zero-copy `[E, 2F, D]` view. Its public configuration matches `Linear`: `out_features` names one projection's output width and `num_linears=2` retains the gate/up axis. This removes the temporary expert-owner, replacement, and sharding APIs raised in review. Eager FSDP, GraphTrainer, quantization converters, model-specific activations, and checkpoint adapters now share one explicit parameter hierarchy. Logical initializer names retain their shape suffixes (`w1_EFD`, `w2_EDF`, and `w3_EFD`), while runtime parameters use standard module keys (`w13.weight` and `w2.weight`). HF checkpoint schemas remain compatible through adapter-boundary conversion. DeepSeek V4 now performs the same native-to-logical expert conversion as the other adapters, preventing native W13 keys from leaking into exported HF checkpoints. FSDP derives matrix-row shard placements through the shared linear helper for both stacked `Linear` and `GroupedLinear` modules; no W13/W2 FQN special case remains. `MoE.num_experts` is the canonical runtime expert count, and GPT-OSS uses the shared `MoE.Config` without an empty model-specific subclass. The existing fused-linear state adapter helpers also own the optional routed W13 split/merge for HF schemas with separate expert projections, while GPT-OSS and Qwen3.5 retain their fused HF layouts. The standard MXFP8 and Float8 converters specialize each grouped linear at the grouped-MM seam. Kimi retains SiTU and its optimizer metadata addresses the native W13/W2 parameters. GPT-OSS keeps its grouped bias in a model-specific `GroupedLinear` subclass and otherwise follows current main: routed expert matrices are complete locally unless EP shards the expert axis. MXFP8 grouped linears retain their existing 1x32 weight-scale format. Structured W13 is flattened without a copy before quantization. Square 32x32 grouped weights and preventing a columnwise block from spanning an unaligned gate/up boundary remain a separate follow-up rather than expanding this ownership refactor. The parent W13 layout change already resets DeepSeek V3 and Qwen3 deterministic goldens. GPT-OSS already used one fused W13 grouped GEMM and initialized W13 before W2. Its numerical reset instead comes from changing W13 storage from HF-interleaved `[E, 2F, D]` to blocked `[E, 2, F, D]`: the same random values now initialize different gate/up rows. A local fixed-weight comparison converts the interleaved weight and bias into the blocked layout and produces bitwise equal forward output; only backward reduction ordering may introduce secondary rounding differences. GPT-OSS A10G fake-PG and real-PG goldens are regenerated from full-precision TensorBoard metrics. Test Plan: - `python -m pytest tests/unit_tests/cpu -q --deselect tests/unit_tests/cpu/test_lora.py::test_lora_forward` (1245 passed, 23 skipped, 1 deselected) - Focused GraphTrainer scheduling and chunk tests (108 passed, 120 deselected) - `python -m pytest -q tests/unit_tests/gpu/test_fsdp_moe_sharding.py tests/unit_tests/gpu/flex_shard/test_dist_muon.py tests/unit_tests/gpu/test_fused_swiglu_override.py tests/unit_tests/gpu/test_compile_moe.py` (25 passed) - Focused Kimi native-FQN/checkpoint tests (2 passed) and grouped-quantization CPU tests (10 passed) - Float8 structured-wrapper tests (2 passed); all 12 Float8 GPU tests collect. The local SM103 TorchAO grouped backward kernel is unsupported, so execution remains a B200 CI gate rather than a local workaround. - FSDP expert-placement tests cover expert-axis and matrix-row sharding through the generic linear placement helper. - State-dict adapter tests cover separate and fused HF expert schemas, including DTensor placement round-trips and DeepSeek V4 key validation. - A local old-interleaved versus new-blocked GPT-OSS fixed-weight forward comparison reports `torch_equal=True` and `max_abs_diff=0.0`. - A10G GPT-OSS fake-PG and real-PG numerics were exported from the exact CI configurations using full-precision TensorBoard metrics. - Scoped formatting, flake8, pydoclint, codespell, link, and targeted Pyrefly checks passed. Project-wide Pyrefly retains one unrelated nullable-video-duration baseline error. CI notes: - The B200 run https://github.com/pytorch/torchtitan/actions/runs/35924519733 failed while extracting the repository checkout (`gzip: unexpected end of file`) before tests executed. - The GraphTrainer failures in https://github.com/pytorch/torchtitan/actions/runs/35924514118 and https://github.com/pytorch/torchtitan/actions/runs/35924514111 reproduce in scheduled upstream-main runs https://github.com/pytorch/torchtitan/actions/runs/35860469802 and https://github.com/pytorch/torchtitan/actions/runs/35859018087, respectively. [ghstack-poisoned]
Stack from ghstack (oldest at bottom):
Summary:
Replace the opaque
RoutedExperts.inner_expertsowner with explicitw13,w2,activation_fn, andtoken_dispatcherchildren. Add a reusable,bias-free
GroupedLinearwhose structured W13 storage is[E, 2, F, D];grouped GEMM consumes a zero-copy
[E, 2F, D]view. Its public configurationmatches
Linear:out_featuresnames one projection's output width andnum_linears=2retains the gate/up axis.This removes the temporary expert-owner, replacement, and sharding APIs raised
in review. Eager FSDP, GraphTrainer, quantization converters, model-specific
activations, and checkpoint adapters now share one explicit parameter
hierarchy. Logical initializer names retain their shape suffixes (
w1_EFD,w2_EDF, andw3_EFD), while runtime parameters use standard module keys(
w13.weightandw2.weight). HF checkpoint schemas remain compatible throughadapter-boundary conversion. DeepSeek V4 now performs the same native-to-logical
expert conversion as the other adapters, preventing native W13 keys from
leaking into exported HF checkpoints.
FSDP derives matrix-row shard placements through the shared linear helper for
both stacked
LinearandGroupedLinearmodules; no W13/W2 FQN special caseremains.
MoE.num_expertsis the canonical runtime expert count, and GPT-OSSuses the shared
MoE.Configwithout an empty model-specific subclass. Theexisting fused-linear state adapter helpers also own the optional
routed W13 split/merge for HF schemas with separate expert projections, while
GPT-OSS and Qwen3.5 retain their fused HF layouts.
The standard MXFP8 and Float8 converters specialize each grouped linear at the
grouped-MM seam. Kimi retains SiTU and its optimizer metadata addresses the
native W13/W2 parameters. GPT-OSS keeps its grouped bias in a model-specific
GroupedLinearsubclass and otherwise follows current main: routed expertmatrices are complete locally unless EP shards the expert axis.
MXFP8 grouped linears retain their existing 1x32 weight-scale format. Structured
W13 is flattened without a copy before quantization. Square 32x32 grouped
weights and preventing a columnwise block from spanning an unaligned gate/up
boundary remain a separate follow-up rather than expanding this ownership
refactor.
The parent W13 layout change already resets DeepSeek V3 and Qwen3 deterministic
goldens. GPT-OSS already used one fused W13 grouped GEMM and initialized W13
before W2. Its numerical reset instead comes from changing W13 storage from
HF-interleaved
[E, 2F, D]to blocked[E, 2, F, D]: the same random valuesnow initialize different gate/up rows. A local fixed-weight comparison converts
the interleaved weight and bias into the blocked layout and produces bitwise
equal forward output; only backward reduction ordering may introduce secondary
rounding differences. GPT-OSS A10G fake-PG and real-PG goldens are regenerated
from full-precision TensorBoard metrics.
Test Plan:
python -m pytest tests/unit_tests/cpu -q --deselect tests/unit_tests/cpu/test_lora.py::test_lora_forward(1245 passed, 23 skipped, 1 deselected)python -m pytest -q tests/unit_tests/gpu/test_fsdp_moe_sharding.py tests/unit_tests/gpu/flex_shard/test_dist_muon.py tests/unit_tests/gpu/test_fused_swiglu_override.py tests/unit_tests/gpu/test_compile_moe.py(25 passed)torch_equal=Trueandmax_abs_diff=0.0.CI notes:
gzip: unexpected end of file) before tests executed.