Repository navigation
[Module] Replace from_nn_module with native Module subclasses - #3398
Merged
Merged
Conversation
[ghstack-poisoned]
fegin
added a commit
that referenced
this pull request
May 19, 2026
…ses; LocalMapConfig None-per-arg Replace Module.from_nn_module dynamic class generation with explicit diamond-inheritance classes in nn_modules.py, following the same pattern as Linear, RMSNorm, and Embedding. - Add Conv2d, GroupNorm, LayerNorm (parameterized, with typed Config fields and _init_self_parameters override delegating to reset_parameters) - Add GELU, SiLU, Identity (lightweight, Config with minimal or no extra fields) - Delete from_nn_module classmethod and _created_classes cache from module.py (~80 lines removed) - Update all flux callsites (layers.py, autoencoder.py) from direct construction to Config-based construction - Rewrite TestFromNnModule as TestNnModuleWrappers testing native classes - Allow None entries in LocalMapConfig.in_grad_placements and ShardingConfig.out_src_shardings for non-tensor forward args ghstack-source-id: 2a21f21 Pull-Request: #3398
fegin
added a commit
that referenced
this pull request
May 19, 2026
…ses; LocalMapConfig None-per-arg Replace Module.from_nn_module dynamic class generation with explicit diamond-inheritance classes in nn_modules.py, following the same pattern as Linear, RMSNorm, and Embedding. - Add Conv2d, GroupNorm, LayerNorm (parameterized, with typed Config fields and _init_self_parameters override delegating to reset_parameters) - Add GELU, SiLU, Identity (lightweight, Config with minimal or no extra fields) - Delete from_nn_module classmethod and _created_classes cache from module.py (~80 lines removed) - Update all flux callsites (layers.py, autoencoder.py) from direct construction to Config-based construction - Rewrite TestFromNnModule as TestNnModuleWrappers testing native classes - Allow None entries in LocalMapConfig.in_grad_placements and ShardingConfig.out_src_shardings for non-tensor forward args ghstack-source-id: 2a21f21 Pull-Request: #3398
[ghstack-poisoned]
fegin
marked this pull request as ready for review
May 20, 2026 22:10
tianyu-l
approved these changes
May 20, 2026
fegin
requested review from
SherlockNoMad,
aditvenk,
sanketpurandare,
xmfan and
yiming0416
as code owners
May 21, 2026 19:25
tianyu-l
reviewed
May 21, 2026
Contributor
There was a problem hiding this comment.
lol maybe we can also have some gitignored agent scratch space folder
Contributor
Author
There was a problem hiding this comment.
wow, the agent went crazy to add too many things that I locally own. That's interesting.
xmfan
approved these changes
May 22, 2026
[ghstack-poisoned]
[ghstack-poisoned]
saforem2
added a commit
to saforem2/torchtitan
that referenced
this pull request
May 27, 2026
…ules Upstream PR pytorch#3398 (40th sync) replaced from_nn_module with native Module subclasses; common/{linear,rmsnorm,embedding}.py were deleted and consolidated into common/nn_modules.py. Update the 3 broken imports in ezpz to the new path: - agpt/__init__.py: import Linear from nn_modules - moe/model.py: import Linear, RMSNorm from nn_modules API is identical (same Config dataclass, same constructor signature), so this is a pure import-path swap. Smoke-tested import path locally.
saforem2
added a commit
to saforem2/torchtitan
that referenced
this pull request
May 27, 2026
… routing Merged 7 upstream commits (19c567f..af33f76). Documents which ones needed ezpz replays: - PR pytorch#3398 (Module subclass refactor): 3 import paths replayed in b052f29 — pure import-path swap, class API unchanged. - PR pytorch#3146 (deterministic MoE routing): inherits transitively; this is the upstream fix for the _histc_xpu non-determinism blocker we hit on 2026-05-21. --debug.deterministic on MoE+XPU should now work. - PR pytorch#3423 (MoE [7/n] 3D tensors): inherits transitively; doesn't touch deepseek_v3 callsites. - PR pytorch#3105 (FSDP symm_mem): skipped — ezpz has its own apply_fsdp and symm_mem is an optional optimization XPU CCL likely doesn't support. - PRs pytorch#3331/pytorch#3369/pytorch#3361: graph_trainer-only no-ops. Captures two action items: smoke-test before next production push, and re-try --debug.deterministic on MoE+XPU.
saforem2
added a commit
to saforem2/torchtitan
that referenced
this pull request
May 27, 2026
… fix is incomplete Three smokes on my own 2N alloc (12467455): - agpt_2b clean (24.34 GiB, ~5,900 TPS, ~22% MFU) — matches the 2026-05-22 baseline exactly. PR pytorch#3398 nn_modules import-path replay (b052f29) didn't perturb agpt. - moe_2b_ep at the new LBS=2 default clean (27.09 GiB, ~3,200 TPS, 9.4% MFU, loss 12.93→6.12) — numerically identical to the 2026-05-22 baseline (27.08 GiB, ~3,200 TPS, 9.4% MFU, loss 6.15). PR pytorch#3423 (MoE [7/n] 3D tensors) inherits cleanly via the dispatcher path. - moe_2b_ep with --debug.deterministic STILL FAILS with the same _histc_xpu error from 2026-05-21. PR pytorch#3146 was advertised to fix this but the merged diff only contains the aten.topk.default save -list addition — the promised histc → bincount swap in common/moe.py:262 is missing from the commit. Verified via GitHub API. Adds smoke report at docs/experiments/moe/sunspot/20260527-smoke-n2-40th-sync.md, links from the moe experiments README, updates the 40th-sync entry in upstream-sync.md, and the journal. Open action item: file upstream issue on pytorch/torchtitan for the incomplete PR pytorch#3146.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stack from ghstack (oldest at bottom):
Motivation
from_nn_moduleis designed to be a drop-in replacement of nn.Module. However it causes several issues including not easy to do sharding and may violate thebuild()constraint. So instead of continuing hacking it, this PR replaces the usage in TorchTitan with the explicit class definitions.Summary
Replace
Module.from_nn_moduledynamic class generation with explicit diamond-inheritance classes in nn_modules.py, following the same pattern as Linear, RMSNorm, and Embedding.Detail