Skip to content

Add RegionAC feed-forward regions - #4526

Merged
anijain2305 merged 48 commits into
mainfrom
gh/anijain2305/11/head
Sep 13, 2026
Merged

anijain2305 merged 48 commits into
mainfrom
gh/anijain2305/11/head

Conversation

[ghstack-poisoned]
[ghstack-poisoned]
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Sep 8, 2026
[ghstack-poisoned]
anijain2305 added a commit that referenced this pull request Sep 8, 2026
ghstack-source-id: 0fff09d
Pull-Request: #4526
Comment on lines +65 to +66
remat.recompute_needs_tensor(w1_out)
remat.recompute_needs_tensor(w3_out)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the dist_gemm.py file, you have

remat.recompute_needs_tensor(h1, h3)

what's the rule here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both are same but we should be consistent. I will choose one and stick with it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a proposal, which could be done in separate PR, but would like to run idea by you:

  • we make a fused mlp implementation where (1) we fuse w1w3 during matmul, but (2) leave silu and mul torch-native (slow)
  • It should be default for every model. The unfused w1 w3 version might be kept? Or should we delete it? Similar reasoning for the fused QKV linear in attention. I prefer to remove the unfused versions to reduce maintenance overhead (like in this PR).
  • Regardless, every advanced feature should only integrate with this fused w1w3 impl, including dist_gemm, LoRA, quantization, etc. (But it's not clear to me what's the dist_gemm + quantization story)
  • In override/, we keep the additional impl which fuses silu_and_mul using a triton kernel, which all previous optimizations should work with it out-of-box.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think making the fused version the default makes sense. This will reduce maintenance burden.

I will do a quick investigation if the unfused version has any benefit, and if not, I can send the fused version PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The suggested unfused removals are in the PRs stacked under this PR.

[ghstack-poisoned]
[ghstack-poisoned]
anijain2305 added a commit that referenced this pull request Sep 9, 2026
ghstack-source-id: 1631337
Pull-Request: #4526
# Optional QK normalization (before RoPE, per Qwen3)
if self.q_norm is not None or self.k_norm is not None:
assert self.q_norm is not None and self.k_norm is not None
remat.recompute_needs_tensor(xq_THK)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code motion to follow the rule - "place the recompute_needs_tensor just before the consumer" - This rule is added in remat.md now.

[ghstack-poisoned]
anijain2305 added a commit that referenced this pull request Sep 9, 2026
ghstack-source-id: 36a320d
Pull-Request: #4526
[ghstack-poisoned]
[ghstack-poisoned]
submartingales pushed a commit to botcanlearn/torchtitan-upstream that referenced this pull request Sep 10, 2026
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
submartingales pushed a commit to botcanlearn/torchtitan-upstream that referenced this pull request Sep 13, 2026
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
anijain2305 added a commit that referenced this pull request Sep 13, 2026
Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.18.0)
(oldest at bottom):
* #4543
* #4542
* #4541
* #4623
* #4559
* #4591
* #4592
* #4540
* #4539
* #4643
* #4526
* #4546
* __->__ #4535

Use one physical w13 Linear config and parameter for dense feed-forward
gate and up projections. Compose their initialization before module
construction, configure activation implementations directly, and
translate external gate/up checkpoint keys in model state-dict adapters.
[ghstack-poisoned]
[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Sep 13, 2026

Copy link
Copy Markdown

Warning: Unknown label ciflow/8gpu.
Currently recognized labels are

  • ciflow/b200
  • ciflow/h100.8
  • ciflow/rl

Please add the new label to .github/pytorch-probot.yml

@anijain2305
anijain2305 merged commit 1c7ab80 into main Sep 13, 2026
16 checks passed
submartingales pushed a commit to botcanlearn/torchtitan-upstream that referenced this pull request Sep 13, 2026
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.
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.

2 participants