Repository navigation
[common] Move Linear and ScaledBiasRowwiseLinear into common/linear.py - #3923
Conversation
Introduce torchtitan/models/common/linear.py as the home for configurable linear modules. Move the Linear wrapper out of nn_modules.py and ScaledBiasRowwiseLinear out of gpt_oss/model.py into this new module, and repoint all import sites accordingly. - nn_modules.py no longer defines Linear (removed from __all__). - gpt_oss/model.py drops the now-unused torch.nn.functional import. - common/__init__.py re-exports Linear and ScaledBiasRowwiseLinear. - gpt_oss/__init__.py imports ScaledBiasRowwiseLinear from common.linear. Pure move with no behavior change. Test Plan: pre-commit run on all changed files: passed (flake8, ufmt, pyrefly, etc.). Ran affected unit tests, all green: test_linear, test_module, test_train_spec, test_lora, test_fused_qkv, test_rope, test_quantization, test_activation_checkpoint, test_fused_swiglu, test_compile_moe, test_compile_regional_inductor.
|
|
|
The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:
Once a maintainer approves the workflows (scroll to the bottom of the PR page), the corresponding CI jobs will be triggered automatically. Please ping one of the reviewers if you do not have access to approve and run workflows. |
…ytorch#3923) 69th upstream sync (upstream/main 8c92de8 merge) moved Linear + ScaledBiasRowwiseLinear out of models/common/nn_modules.py into a new models/common/linear.py (upstream pytorch#3923). Our agpt/moe import the deep path common.nn_modules (not the package re-export), so the move breaks them with ImportError: cannot import name Linear. Repoint both callsites: - agpt/__init__.py: Linear from common.linear - moe/model.py: split -- Linear from common.linear, RMSNorm stays in common.nn_modules Import smoke: agpt + moe registries import clean. Train smoke via sync_smoke.sh pending (GPU).
- upstream-sync.md: 69th sync entry (9 commits, merge 8c92de8) with the pytorch#3923 Linear-move breaking-change analysis + fix + sync_smoke VERDICT ok - journal.md: 2026-07-16 session (SFT epoch 1.0 complete, 69th sync, disk, compile root-cause) - refresh recently-updated docs table
Absorbs pytorch#3923 ([common] Move Linear and ScaledBiasRowwiseLinear into common/linear.py). - Resolved common/__init__.py: keep our SharedExperts export from feed_forward and add main's `from .linear import Linear, ScaledBiasRowwiseLinear`. - moe_replacement.py: Linear moved out of common/nn_modules into common/linear, so update the import (was `from ...nn_modules import Linear`). Verified: MoE EP=2 trains (12.36 -> 7.16); experiment module + all flavors import cleanly; lint passes.
tianyu-l
left a comment
There was a problem hiding this comment.
New file torchtitan/models/common/linear.py to store variants of Linear in case some other model needs ScaledBiasRowwiseLinear from gpt_oss (some internal models).
I could understand you need ScaledBiasRowwiseLinear, so it'd better be put in common. But why would you need to move Linear? nn_modules.py has all the modules where we just put a thin wrapper over pytorch modules, so Linear clearly belongs to that category.
I would rather have something like scaled_bias_linear.py which is temporary anyway (remove after we support spmd.P bias).
This is my suggestion.
Yes, I considered this case. But I also feel linear modules are better put together. But I also feel that linear modules should be better put together.
I didn't consider this :/ We can move it back to nn_module.py after it is removed. Sorry about the wrong suggestion. |
|
Thanks for explaining. My goal is still to kill this weird scaled bias linear class, and instead use spmd.P for bias. |
New file
torchtitan/models/common/linear.pyto store variants ofLinearin case some other model needsScaledBiasRowwiseLinearfrom gpt_oss (some internal models).Moved
Linearfromnn_modules.py,ScaledBiasRowwiseLinearfromgpt_oss/model.py.Repointed all import sites accordingly.
Pure move with no behavior change.
Test Plan:
pre-commit run on all changed files: passed (flake8, ufmt, pyrefly, etc.). Ran affected unit tests, all green: test_linear, test_module, test_train_spec, test_lora, test_fused_qkv, test_rope, test_quantization, test_activation_checkpoint, test_fused_swiglu, test_compile_moe, test_compile_regional_inductor.