Skip to content

Make fused gate-up projection the default - #4535

Merged
anijain2305 merged 33 commits into
mainfrom
gh/anijain2305/12/head
Sep 13, 2026
Merged

anijain2305 merged 33 commits into
mainfrom
gh/anijain2305/12/head

Conversation

[ghstack-poisoned]
[ghstack-poisoned]
@pytorch-bot pytorch-bot Bot added the ciflow/rl label Sep 9, 2026
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Sep 9, 2026
[ghstack-poisoned]
anijain2305 added a commit that referenced this pull request Sep 9, 2026
Use one physical w13 linear for dense feed-forward gate and up projections while preserving logical w1 and w3 configs and checkpoint keys. Integrate the layout with DistGEMM, LoRA, quantization, Kimi, and serving consumers, and keep the Triton override focused on the activation fusion.

ghstack-source-id: 9f06cad
Pull-Request: #4535
[ghstack-poisoned]
anijain2305 added a commit that referenced this pull request Sep 9, 2026
Use one physical w13 linear for dense feed-forward gate and up projections while preserving logical w1 and w3 configs and checkpoint keys. Integrate the layout with DistGEMM, LoRA, quantization, Kimi, and serving consumers, and keep the Triton override focused on the activation fusion.

ghstack-source-id: da98279
Pull-Request: #4535
[ghstack-poisoned]
anijain2305 added a commit that referenced this pull request Sep 9, 2026
Use one physical w13 linear for dense feed-forward gate and up projections while preserving logical w1 and w3 configs and checkpoint keys. Integrate the layout with DistGEMM, LoRA, quantization, Kimi, and serving consumers, and keep the Triton override focused on the activation fusion.

ghstack-source-id: 73866be
Pull-Request: #4535
[ghstack-poisoned]
anijain2305 added a commit that referenced this pull request Sep 9, 2026
Use one physical w13 linear for dense feed-forward gate and up projections while preserving logical w1 and w3 configs and checkpoint keys. Integrate the layout with DistGEMM, LoRA, quantization, Kimi, and serving consumers, and keep the Triton override focused on the activation fusion.

ghstack-source-id: 7c7ec0c
Pull-Request: #4535
[ghstack-poisoned]
anijain2305 added a commit that referenced this pull request Sep 9, 2026
Use one physical w13 linear for dense feed-forward gate and up projections while preserving logical w1 and w3 configs and checkpoint keys. Integrate the layout with DistGEMM, LoRA, quantization, Kimi, and serving consumers, and keep the Triton override focused on the activation fusion.

ghstack-source-id: af364a8
Pull-Request: #4535
[ghstack-poisoned]
anijain2305 added a commit that referenced this pull request Sep 9, 2026
Use one physical w13 linear for dense feed-forward gate and up projections while preserving logical w1 and w3 configs and checkpoint keys. Integrate the layout with DistGEMM, LoRA, quantization, Kimi, and serving consumers, and keep the Triton override focused on the activation fusion.

ghstack-source-id: b53af9f
Pull-Request: #4535
[ghstack-poisoned]
anijain2305 added a commit that referenced this pull request Sep 9, 2026
Use one physical w13 linear for dense feed-forward gate and up projections while preserving logical w1 and w3 configs and checkpoint keys. Integrate the layout with DistGEMM, LoRA, quantization, Kimi, and serving consumers, and keep the Triton override focused on the activation fusion.

ghstack-source-id: b69fd50
Pull-Request: #4535
[ghstack-poisoned]
anijain2305 added a commit that referenced this pull request Sep 9, 2026
Use one physical w13 linear for dense feed-forward gate and up projections while preserving logical w1 and w3 configs and checkpoint keys. Integrate the layout with DistGEMM, LoRA, quantization, Kimi, and serving consumers, and keep the Triton override focused on the activation fusion.

ghstack-source-id: a2726ab
Pull-Request: #4535
@anijain2305
anijain2305 marked this pull request as ready for review September 9, 2026 17:22
[ghstack-poisoned]
anijain2305 added a commit that referenced this pull request Sep 15, 2026
Followup from #4535.

W13 currently stores W1 and W3 as interleaved rows in a [2F, D] tensor, logically [F, 2, D]. This works well for TP, but block-quantization tiles can span both projections and force them to share scales.

Generalize Linear with num_linears and store W13 as [2, F, D], keeping each projection contiguous. The GEMM still uses a flattened [2F, D] view, and logical w1/w3 checkpoint keys remain unchanged.

Quantization
------------

Teach the Float8, MXFP8, and NVFP4 Linear implementations to preserve the stacked layout. Generalize quantized FSDP gathering to support weights sharded on dimension 1.

Tensor parallelism
------------------

Shard dimension 1 so every TP rank receives matching feature slices of W1 and W3.

LoRA
----

Use a shared A weight [r, D] and a stacked B weight [2, F, r]. Carry the stacked layout through rematerialization, dist-GEMM, fused SwiGLU, and vLLM state-dict handling.

ghstack-source-id: 4dfbbbe

Pull-Request: #4676
anijain2305 added a commit that referenced this pull request Sep 15, 2026
Followup from #4535.

W13 currently stores W1 and W3 as interleaved rows in a [2F, D] tensor, logically [F, 2, D]. This works well for TP, but block-quantization tiles can span both projections and force them to share scales.

Generalize Linear with num_linears and store W13 as [2, F, D], keeping each projection contiguous. The GEMM still uses a flattened [2F, D] view, and logical w1/w3 checkpoint keys remain unchanged.

Quantization
------------

Teach the Float8, MXFP8, and NVFP4 Linear implementations to preserve the stacked layout. Generalize quantized FSDP gathering to support weights sharded on dimension 1.

Tensor parallelism
------------------

Shard dimension 1 so every TP rank receives matching feature slices of W1 and W3.

LoRA
----

Use a shared A weight [r, D] and a stacked B weight [2, F, r]. Carry the stacked layout through rematerialization, dist-GEMM, fused SwiGLU, and vLLM state-dict handling.

ghstack-source-id: 4dfbbbe

Pull-Request: #4676
anijain2305 added a commit that referenced this pull request Sep 15, 2026
Followup from #4535.

W13 currently stores W1 and W3 as interleaved rows in a [2F, D] tensor, logically [F, 2, D]. This works well for TP, but block-quantization tiles can span both projections and force them to share scales.

Generalize Linear with num_linears and store W13 as [2, F, D], keeping each projection contiguous. The GEMM still uses a flattened [2F, D] view, and logical w1/w3 checkpoint keys remain unchanged.

Quantization
------------

Teach the Float8, MXFP8, and NVFP4 Linear implementations to preserve the stacked layout. Generalize quantized FSDP gathering to support weights sharded on dimension 1.

Tensor parallelism
------------------

Shard dimension 1 so every TP rank receives matching feature slices of W1 and W3.

LoRA
----

Use a shared A weight [r, D] and a stacked B weight [2, F, r]. Carry the stacked layout through rematerialization, dist-GEMM, fused SwiGLU, and vLLM state-dict handling.

ghstack-source-id: d93d5f1

Pull-Request: #4676
anijain2305 added a commit that referenced this pull request Sep 15, 2026
Followup from #4535.

W13 currently stores W1 and W3 as interleaved rows in a [2F, D] tensor, logically [F, 2, D]. This works well for TP, but block-quantization tiles can span both projections and force them to share scales.

Generalize Linear with num_linears and store W13 as [2, F, D], keeping each projection contiguous. The GEMM still uses a flattened [2F, D] view, and logical w1/w3 checkpoint keys remain unchanged.

Quantization
------------

Teach the Float8, MXFP8, and NVFP4 Linear implementations to preserve the stacked layout. Generalize quantized FSDP gathering to support weights sharded on dimension 1.

Tensor parallelism
------------------

Shard dimension 1 so every TP rank receives matching feature slices of W1 and W3.

LoRA
----

Use a shared A weight [r, D] and a stacked B weight [2, F, r]. Carry the stacked layout through rematerialization, dist-GEMM, fused SwiGLU, and vLLM state-dict handling.

ghstack-source-id: d93d5f1

Pull-Request: #4676
anijain2305 added a commit that referenced this pull request Sep 15, 2026
Followup from #4535.

W13 currently stores W1 and W3 as interleaved rows in a [2F, D] tensor, logically [F, 2, D]. This works well for TP, but block-quantization tiles can span both projections and force them to share scales.

Generalize Linear with num_linears and store W13 as [2, F, D], keeping each projection contiguous. The GEMM still uses a flattened [2F, D] view, and logical w1/w3 checkpoint keys remain unchanged.

Quantization
------------

Teach the Float8, MXFP8, and NVFP4 Linear implementations to preserve the stacked layout. Generalize quantized FSDP gathering to support weights sharded on dimension 1.

Tensor parallelism
------------------

Shard dimension 1 so every TP rank receives matching feature slices of W1 and W3.

LoRA
----

Use a shared A weight [r, D] and a stacked B weight [2, F, r]. Carry the stacked layout through rematerialization, dist-GEMM, fused SwiGLU, and vLLM state-dict handling.

ghstack-source-id: 646cc44

Pull-Request: #4676
anijain2305 added a commit that referenced this pull request Sep 15, 2026
Followup from #4535.

W13 currently stores W1 and W3 as interleaved rows in a [2F, D] tensor, logically [F, 2, D]. This works well for TP, but block-quantization tiles can span both projections and force them to share scales.

Generalize Linear with num_linears and store W13 as [2, F, D], keeping each projection contiguous. The GEMM still uses a flattened [2F, D] view, and logical w1/w3 checkpoint keys remain unchanged.

Quantization
------------

Teach the Float8, MXFP8, and NVFP4 Linear implementations to preserve the stacked layout. Generalize quantized FSDP gathering to support weights sharded on dimension 1.

Tensor parallelism
------------------

Shard dimension 1 so every TP rank receives matching feature slices of W1 and W3.

LoRA
----

Use a shared A weight [r, D] and a stacked B weight [2, F, r]. Carry the stacked layout through rematerialization, dist-GEMM, fused SwiGLU, and vLLM state-dict handling.

ghstack-source-id: c5975a8

Pull-Request: #4676
saforem2 added a commit to saforem2/torchtitan that referenced this pull request Sep 15, 2026
… regrouping only

pytorch#4526 (mandatory fused QKV) and pytorch#4535 (fused gate-up by default) change the
arithmetic GROUPING, not the arithmetic. Verified on Perlmutter A100 against
torch 2.13.0+cu130, the version HEAD requires.

The naive seeded A/B is misleading and the writeup leads with why: building a
model on each tree gives logits_sum -3716 vs +1090, not even the same sign.
That is an INIT-ORDER difference, not a numerics one -- the fused w13 consumes
the RNG stream differently than separate w1/w3. Proof: tok_embeddings,
initialized before the first fused layer, is bit-identical across the merge,
while everything after it differs in value but matches in std.

The decisive test loads ONE state dict into both trees:
  missing: [], unexpected: []        hooks preserve logical w1/w3
  max |delta|   1.907e-06            float32 eps = 1.192e-07
  max rel err   1.275e-06 at |a|>1.0, falling monotonically with magnitude
  argmax        100.00% agreement
  top-5         100.00% agreement

Monotone-decreasing relative error is the signature of float regrouping; a
wrong layout would be large and magnitude-independent.

Does NOT clear the XPU smoke. Recorded there: Perlmutter's torch has
_fsdp_param.py at 1095 lines with zero _resolve_spmd_types_for_storage -- the
SAME gap as the ALCF build -- so spmd_types is a torch version floor, not an
XPU bug, and no NERSC run can answer it.
anijain2305 added a commit that referenced this pull request Sep 15, 2026
Followup from #4535.

W13 currently stores W1 and W3 as interleaved rows in a [2F, D] tensor, logically [F, 2, D]. This works well for TP, but block-quantization tiles can span both projections and force them to share scales.

Generalize Linear with num_linears and store W13 as [2, F, D], keeping each projection contiguous. The GEMM still uses a flattened [2F, D] view, and logical w1/w3 checkpoint keys remain unchanged.

Quantization
------------

Teach the Float8, MXFP8, and NVFP4 Linear implementations to preserve the stacked layout. Generalize quantized FSDP gathering to support weights sharded on dimension 1.

Tensor parallelism
------------------

Shard dimension 1 so every TP rank receives matching feature slices of W1 and W3.

LoRA
----

Use a shared A weight [r, D] and a stacked B weight [2, F, r]. Carry the stacked layout through rematerialization, dist-GEMM, fused SwiGLU, and vLLM state-dict handling.

ghstack-source-id: 2152776

Pull-Request: #4676
anijain2305 added a commit that referenced this pull request Sep 15, 2026
Followup from #4535.

W13 currently stores W1 and W3 as interleaved rows in a [2F, D] tensor, logically [F, 2, D]. This works well for TP, but block-quantization tiles can span both projections and force them to share scales.

Generalize Linear with num_linears and store W13 as [2, F, D], keeping each projection contiguous. The GEMM still uses a flattened [2F, D] view, and logical w1/w3 checkpoint keys remain unchanged.

Quantization
------------

Teach the Float8, MXFP8, and NVFP4 Linear implementations to preserve the stacked layout. Generalize quantized FSDP gathering to support weights sharded on dimension 1.

Tensor parallelism
------------------

Shard dimension 1 so every TP rank receives matching feature slices of W1 and W3.

LoRA
----

Use a shared A weight [r, D] and a stacked B weight [2, F, r]. Carry the stacked layout through rematerialization, dist-GEMM, fused SwiGLU, and vLLM state-dict handling.

ghstack-source-id: 2152776

Pull-Request: #4676
anijain2305 added a commit that referenced this pull request Sep 15, 2026
Followup from #4535.

W13 currently stores W1 and W3 as interleaved rows in a [2F, D] tensor, logically [F, 2, D]. This works well for TP, but block-quantization tiles can span both projections and force them to share scales.

Generalize Linear with num_linears and store W13 as [2, F, D], keeping each projection contiguous. The GEMM still uses a flattened [2F, D] view, and logical w1/w3 checkpoint keys remain unchanged.

Quantization
------------

Teach the Float8, MXFP8, and NVFP4 Linear implementations to preserve the stacked layout. Generalize quantized FSDP gathering to support weights sharded on dimension 1.

Tensor parallelism
------------------

Shard dimension 1 so every TP rank receives matching feature slices of W1 and W3.

LoRA
----

Use a shared A weight [r, D] and a stacked B weight [2, F, r]. Carry the stacked layout through rematerialization, dist-GEMM, fused SwiGLU, and vLLM state-dict handling.

ghstack-source-id: 2152776

Pull-Request: #4676
saforem2 added a commit to saforem2/torchtitan that referenced this pull request Sep 16, 2026
pytorch#4535 made the fused gate/up projection the default, and core's
_make_fused_linear_init (models/common/config_utils.py:58) does

    gate_up = t.unflatten(0, (-1, 2))

which requires dim 0 to divide evenly by the mesh when t is a DTensor sharded
on dim 0. parallelize_moe calls fully_shard with Shard(0) over the whole
transformer block, so shared_experts.w13 is exactly that, and init_states dies:

    RuntimeError: Cannot unflatten unevenly sharded tensor: output dimension 0
    (size 1024) is not evenly divisible by mesh dimension 0 (size 24)

Job 12477656: 52 ranks, always size 1024 (shared_experts), never the dense
2048 -- the dense FFN is wrapped on a different path. Confirmed
merge-introduced: _make_fused_linear_init has 0 occurrences pre-merge, 1 after.

The interleaved gate/up layout is per-row, so each rank can initialize its own
shard independently. _dtensor_safe_fused_ffn_config wraps make_ffn_config and
unflattens the LOCAL tensor rather than the global DTensor -- same values, no
cross-rank divisibility requirement.

Wrapped rather than patching core, per the experiments-folder rule. 6/6 moe
configs still build on meta device; the real test is the 2N smoke.
anijain2305 added a commit that referenced this pull request Sep 19, 2026
Followup from #4535.

W13 currently stores W1 and W3 as interleaved rows in a [2F, D] tensor, logically [F, 2, D]. This works well for TP, but block-quantization tiles can span both projections and force them to share scales.

Generalize Linear with num_linears and store W13 as [2, F, D], keeping each projection contiguous. The GEMM still uses a flattened [2F, D] view.

State dicts
-----------

Keep native DCP checkpoints and RL weight synchronization in the physical w13 layout. Split w13 into gate/up projections, and merge them on load, only at the Hugging Face adapter boundary. This avoids materializing FFN-sized hook outputs on every state_dict() call.

Quantization
------------

Teach the Float8, MXFP8, and NVFP4 Linear implementations to preserve the stacked layout. Generalize quantized FSDP gathering to support weights sharded on dimension 1.

Tensor parallelism
------------------

Shard dimension 1 so every TP rank receives matching feature slices of W1 and W3.

LoRA
----

Use a shared A weight [r, D] and a stacked B weight [2, F, r]. Carry the stacked layout through rematerialization, dist-GEMM, fused SwiGLU, and vLLM state-dict handling.

ghstack-source-id: 9c73d23

Pull-Request: #4676
anijain2305 added a commit that referenced this pull request Sep 19, 2026
Followup from #4535.

W13 currently stores W1 and W3 as interleaved rows in a [2F, D] tensor, logically [F, 2, D]. This works well for TP, but block-quantization tiles can span both projections and force them to share scales.

Generalize Linear with num_linears and store W13 as [2, F, D], keeping each projection contiguous. The GEMM still uses a flattened [2F, D] view.

State dicts
-----------

Keep native DCP checkpoints and RL weight synchronization in the physical w13 layout. Split w13 into gate/up projections, and merge them on load, only at the Hugging Face adapter boundary. This avoids materializing FFN-sized hook outputs on every state_dict() call.

Quantization
------------

Teach the Float8, MXFP8, and NVFP4 Linear implementations to preserve the stacked layout. Generalize quantized FSDP gathering to support weights sharded on dimension 1.

Tensor parallelism
------------------

Shard dimension 1 so every TP rank receives matching feature slices of W1 and W3.

LoRA
----

Use a shared A weight [r, D] and a stacked B weight [2, F, r]. Carry the stacked layout through rematerialization, dist-GEMM, fused SwiGLU, and vLLM state-dict handling.

ghstack-source-id: 9c73d23

Pull-Request: #4676
anijain2305 added a commit that referenced this pull request Sep 19, 2026
Followup from #4535.

Generalize Linear with num_linears while keeping ordinary projections in their standard 2D layout. Store fused W13 as [2, F, D], keeping gate and up projections contiguous without changing the flattened GEMM.

Keep native DCP checkpoints and RL weight synchronization in the physical w13 layout. Split and merge gate/up projections only at the Hugging Face adapter boundary, avoiding FFN-sized state_dict hook copies on every RL weight sync.

Shard stacked W13 on its matrix-row dimension for TP and FSDP, propagate the layout through LoRA, dist-GEMM, rematerialization, fused SwiGLU, vLLM, and quantized Linear implementations, and allow DistMuon Owned compute for native batches of matrices.

Update numerical goldens and add coverage for native/HF state-dict round trips, tied Qwen FSDP loads, DeepSeek V4 TP, Kimi DistMuon, stacked initialization, and quantized FSDP gathering.

ghstack-source-id: 0df121f

Pull-Request: #4676
anijain2305 added a commit that referenced this pull request Sep 19, 2026
Followup from #4535.

Generalize Linear with num_linears while keeping ordinary projections in their standard 2D layout. Store fused W13 as [2, F, D], keeping gate and up projections contiguous without changing the flattened GEMM.

Keep native DCP checkpoints and RL weight synchronization in the physical w13 layout. Split and merge gate/up projections only at the Hugging Face adapter boundary, avoiding FFN-sized state_dict hook copies on every RL weight sync.

Shard stacked W13 on its matrix-row dimension for TP and FSDP, propagate the layout through LoRA, dist-GEMM, rematerialization, fused SwiGLU, vLLM, and quantized Linear implementations, and allow DistMuon Owned compute for native batches of matrices.

Update numerical goldens and add coverage for native/HF state-dict round trips, tied Qwen FSDP loads, DeepSeek V4 TP, Kimi DistMuon, stacked initialization, and quantized FSDP gathering.

ghstack-source-id: 1242ebb

Pull-Request: #4676
anijain2305 added a commit that referenced this pull request Sep 19, 2026
Followup from #4535.

Generalize Linear with num_linears while keeping ordinary projections in their standard 2D layout. Store fused W13 as [2, F, D], keeping gate and up projections contiguous without changing the flattened GEMM.

Keep native DCP checkpoints and RL weight synchronization in the physical w13 layout. Split and merge gate/up projections only at the Hugging Face adapter boundary, avoiding FFN-sized state_dict hook copies on every RL weight sync.

Shard stacked W13 on its matrix-row dimension for TP and FSDP, propagate the layout through LoRA, dist-GEMM, rematerialization, fused SwiGLU, vLLM, and quantized Linear implementations, and allow DistMuon Owned compute for native batches of matrices.

Update numerical goldens and add coverage for native/HF state-dict round trips, tied Qwen FSDP loads, DeepSeek V4 TP, Kimi DistMuon, stacked initialization, and quantized FSDP gathering.

ghstack-source-id: c3b1478

Pull-Request: #4676
anijain2305 added a commit that referenced this pull request Sep 19, 2026
Followup from #4535.

Generalize Linear with num_linears while keeping ordinary projections in their standard 2D layout. Store fused W13 as [2, F, D], keeping gate and up projections contiguous without changing the flattened GEMM.

Keep native DCP checkpoints and RL weight synchronization in the physical w13 layout. Split and merge gate/up projections only at the Hugging Face adapter boundary, avoiding FFN-sized state_dict hook copies on every RL weight sync.

Shard stacked W13 on its matrix-row dimension for TP and FSDP, propagate the layout through LoRA, dist-GEMM, rematerialization, fused SwiGLU, vLLM, and quantized Linear implementations, and allow DistMuon Owned compute for native batches of matrices.

Update numerical goldens and add coverage for native/HF state-dict round trips, tied Qwen FSDP loads, DeepSeek V4 TP, Kimi DistMuon, stacked initialization, and quantized FSDP gathering.

ghstack-source-id: c3b1478

Pull-Request: #4676
anijain2305 added a commit that referenced this pull request Sep 20, 2026
Followup from #4535.

Generalize Linear with num_linears while keeping ordinary projections in their standard 2D layout. Store fused W13 as [2, F, D], keeping gate and up projections contiguous without changing the flattened GEMM.

Keep native DCP checkpoints and RL weight synchronization in the physical w13 layout. Split and merge gate/up projections only at the Hugging Face adapter boundary, avoiding FFN-sized state_dict hook copies on every RL weight sync.

Shard stacked W13 on its matrix-row dimension for TP and FSDP, propagate the layout through LoRA, dist-GEMM, rematerialization, fused SwiGLU, vLLM, and quantized Linear implementations, and allow DistMuon Owned compute for native batches of matrices.

Update numerical goldens and add coverage for native/HF state-dict round trips, tied Qwen FSDP loads, DeepSeek V4 TP, Kimi DistMuon, stacked initialization, and quantized FSDP gathering.

ghstack-source-id: c1be08b

Pull-Request: #4676
anijain2305 added a commit that referenced this pull request Sep 20, 2026
Followup from #4535.

Generalize Linear with num_linears while keeping ordinary projections in their standard 2D layout. Store fused W13 as [2, F, D], keeping gate and up projections contiguous without changing the flattened GEMM.

Keep native DCP checkpoints and RL weight synchronization in the physical w13 layout. Split and merge gate/up projections only at the Hugging Face adapter boundary, avoiding FFN-sized state_dict hook copies on every RL weight sync.

Shard stacked W13 on its matrix-row dimension for TP and FSDP, propagate the layout through LoRA, dist-GEMM, rematerialization, fused SwiGLU, vLLM, and quantized Linear implementations, and allow DistMuon Owned compute for native batches of matrices.

Update numerical goldens and add coverage for native/HF state-dict round trips, tied Qwen FSDP loads, DeepSeek V4 TP, Kimi DistMuon, stacked initialization, and quantized FSDP gathering.

ghstack-source-id: a90409c

Pull-Request: #4676
anijain2305 added a commit that referenced this pull request Sep 20, 2026
Followup from #4535.

Generalize Linear with num_linears while keeping ordinary projections in their standard 2D layout. Store fused W13 as [2, F, D], keeping gate and up projections contiguous without changing the flattened GEMM.

Keep native DCP checkpoints and RL weight synchronization in the physical w13 layout. Split and merge gate/up projections only at the Hugging Face adapter boundary, avoiding FFN-sized state_dict hook copies on every RL weight sync.

Shard stacked W13 on its matrix-row dimension for TP and FSDP, propagate the layout through LoRA, dist-GEMM, rematerialization, fused SwiGLU, vLLM, and quantized Linear implementations, and allow DistMuon Owned compute for native batches of matrices.

Update numerical goldens and add coverage for native/HF state-dict round trips, tied Qwen FSDP loads, DeepSeek V4 TP, Kimi DistMuon, stacked initialization, and quantized FSDP gathering.

ghstack-source-id: ab41ed0

Pull-Request: #4676
anijain2305 added a commit that referenced this pull request Sep 20, 2026
Followup from #4535.

Generalize Linear with num_linears while keeping ordinary projections in their standard 2D layout. Store fused W13 as [2, F, D], keeping gate and up projections contiguous without changing the flattened GEMM.

Keep native DCP checkpoints and RL weight synchronization in the physical w13 layout. Split and merge gate/up projections only at the Hugging Face adapter boundary, avoiding FFN-sized state_dict hook copies on every RL weight sync.

Shard stacked W13 on its matrix-row dimension for TP and FSDP, propagate the layout through LoRA, dist-GEMM, rematerialization, fused SwiGLU, vLLM, and quantized Linear implementations, and allow DistMuon Owned compute for native batches of matrices.

Update numerical goldens and add coverage for native/HF state-dict round trips, tied Qwen FSDP loads, DeepSeek V4 TP, Kimi DistMuon, stacked initialization, and quantized FSDP gathering.

ghstack-source-id: f9eda5c

Pull-Request: #4676
tianyu-l pushed a commit that referenced this pull request Sep 20, 2026
Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.15.0)
(oldest at bottom):
* __->__ #4676

Followup from #4535.

W13 currently stores W1 and W3 as interleaved rows in a [2F, D] tensor,
logically [F, 2, D]. This works well for TP, but block-quantization
tiles can span both projections and force them to share scales.

Generalize Linear with num_linears and store W13 as [2, F, D], keeping
each projection contiguous. The GEMM still uses a flattened [2F, D]
view.

State dicts
-----------

Keep native DCP checkpoints and RL weight synchronization in the
physical w13 layout. Split w13 into gate/up projections, and merge them
on load, only at the Hugging Face adapter boundary. This avoids
materializing FFN-sized hook outputs on every state_dict() call.

Quantization
------------

Teach the Float8, MXFP8, and NVFP4 Linear implementations to preserve
the stacked layout. Generalize quantized FSDP gathering to support
weights sharded on dimension 1.

Tensor parallelism
------------------

Shard dimension 1 so every TP rank receives matching feature slices of
W1 and W3.

LoRA
----

Use a shared A weight [r, D] and a stacked B weight [2, F, r]. Carry the
stacked layout through rematerialization, dist-GEMM, fused SwiGLU, and
vLLM state-dict handling.
anijain2305 added a commit that referenced this pull request Sep 20, 2026
Followup from #4535.

Generalize Linear with num_linears while keeping ordinary projections in their standard 2D layout. Store fused W13 as [2, F, D], keeping gate and up projections contiguous without changing the flattened GEMM.

Keep native DCP checkpoints and RL weight synchronization in the physical w13 layout. Split and merge gate/up projections only at the Hugging Face adapter boundary, avoiding FFN-sized state_dict hook copies on every RL weight sync.

Shard stacked W13 on its matrix-row dimension for TP and FSDP, propagate the layout through LoRA, dist-GEMM, rematerialization, fused SwiGLU, vLLM, and quantized Linear implementations, and allow DistMuon Owned compute for native batches of matrices.

Update numerical goldens and add coverage for native/HF state-dict round trips, tied Qwen FSDP loads, DeepSeek V4 TP, Kimi DistMuon, stacked initialization, and quantized FSDP gathering.
anijain2305 added a commit that referenced this pull request Sep 20, 2026
Followup from #4535.

Generalize Linear with num_linears while keeping ordinary projections in their standard 2D layout. Store fused W13 as [2, F, D], keeping gate and up projections contiguous without changing the flattened GEMM.

Keep native DCP checkpoints and RL weight synchronization in the physical w13 layout. Split and merge gate/up projections only at the Hugging Face adapter boundary, avoiding FFN-sized state_dict hook copies on every RL weight sync.

Shard stacked W13 on its matrix-row dimension for TP and FSDP, propagate the layout through LoRA, dist-GEMM, rematerialization, fused SwiGLU, vLLM, and quantized Linear implementations, and allow DistMuon Owned compute for native batches of matrices.

Update numerical goldens and add coverage for native/HF state-dict round trips, tied Qwen FSDP loads, DeepSeek V4 TP, Kimi DistMuon, stacked initialization, and quantized FSDP gathering.
anijain2305 added a commit that referenced this pull request Sep 20, 2026
Relands #4676 against `main`. #4676 was accidentally merged into its
ghstack base branch and never landed on `main`. This PR contains the
same reviewed change, rebased onto current `main`.

Followup from #4535.

W13 currently stores W1 and W3 as interleaved rows in a [2F, D] tensor,
logically [F, 2, D]. This works well for TP, but block-quantization
tiles can span both projections and force them to share scales.

Generalize Linear with num_linears and store W13 as [2, F, D], keeping
each projection contiguous. The GEMM still uses a flattened [2F, D]
view.

State dicts
-----------

Keep native DCP checkpoints and RL weight synchronization in the
physical w13 layout. Split w13 into gate/up projections, and merge them
on load, only at the Hugging Face adapter boundary. This avoids
materializing FFN-sized hook outputs on every state_dict() call.

Quantization
------------

Teach the Float8, MXFP8, and NVFP4 Linear implementations to preserve
the stacked layout. Generalize quantized FSDP gathering to support
weights sharded on dimension 1.

Tensor parallelism
------------------

Shard dimension 1 so every TP rank receives matching feature slices of
W1 and W3.

LoRA
----

Use a shared A weight [r, D] and a stacked B weight [2, F, r]. Carry the
stacked layout through rematerialization, dist-GEMM, fused SwiGLU, and
vLLM state-dict handling.
weifengpy added a commit that referenced this pull request Sep 21, 2026
…#4811)

w13 didn't get any fqn match after splitting w123 into w13 and w2. this
PR fixes it:
  * #4535
  * https://github.com/pytorch/torchtitan/pull/4676/changes#r4058499709
* same problem first raised in
#4531 by @WhoisZihan

the next follow up is adding validation prevent future cases like above
in optimizer init: #4816


Co-authored-by: Zihan Yang <[email protected]>

Co-authored-by: Zihan Yang <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/rl ciflow/8gpu CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants