Skip to content

[RFC] a registry mechanism for in-repo / out-of-repo Module-level overrides - #3396

Merged
tianyu-l merged 1 commit into
mainfrom
registry
Jun 10, 2026
Merged

tianyu-l merged 1 commit into
mainfrom
registry

Conversation

@tianyu-l

@tianyu-l tianyu-l commented May 19, 2026 •

Copy link
Copy Markdown
Contributor

2026/06/07 update:

Addressed most comments, and aimed for landing, with latest design updated in torchtitan/config/OVERRIDE.md

In particular, I created a FusedSwiGLU override, but admitted that checkpoint incompatibility between fused and non-fused version. Issue tracked in #3569.


With the following main goals

[GOAL 1]
Provide users a way to use efficient kernels that are not "native implementations".

  • main goal is to provide decent performance on ops that don't have efficient implementations in pytorch core, e.g. RoPE with various context-length extension methods.
  • lower bar on code maintainability for kernel code; can iterate fast. Similar gist to how we look at agent tooling Debug Numerics with DebugMode #3323 (review)
  • doesn't aim to support all hardware, may start with Triton for H100 (available in CI)
  • if the torchtitan/registry folder grows too quick / becomes messy, we probably should create a separate repo to host overrides

[GOAL 2]
Provide team a way to experiment with and showcase non-trivial implementations, without making intrusive changes to the rest of repo

[GOAL 3]
Provide hardware vendors a way to override modules, without touching the main repo.

[NO GOAL]

  • op-level overrides: one should consider pytorch native ways, e.g. via torch.library
  • the proposal is orthogonal to graph capture -- it is override author's responsibility to make sure the registered module can be traced (cc @SherlockNoMad @xmfan @aditvenk)

Please read torchtitan/registry/DESIGN.md for details. Feedback is welcome.

Additional notes

@tianyu-l
tianyu-l requested review from fegin, wconstab and wwwjn as code owners May 19, 2026 07:56
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label May 19, 2026
Comment thread torchtitan/registry/__init__.py Outdated
lines: list[str] = []
for target, names in conflicts.items():
lines.append(" " + target.__qualname__ + ": " + ", ".join(sorted(names)))
raise ValueError(

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.

if you have two overrides 1 targeting a parent of another do you think ti should also warn?

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.

Great point. In that case, I'd just error out (in first version). WDYT?

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.

Yeah I think that policy makes sense

Comment thread tests/unit_tests/test_registry.py Outdated
def first(cfg):
return cfg

with self.assertRaises(ValueError, msg="already registered"):

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 think you want rasiesRegex

Comment thread torchtitan/registry/__init__.py Outdated
_check_conflicts()

replacements: list[str] = []
for override in _REGISTRY.values():

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.

nit: youare potentially applying all mods in the registry even if not requested in override config

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.

Good catch. In the current version, if a mod appears in the import chain, it'll be applied regardless if it's in override config or not. I think my intention was to strictly limit to things in the override config, to be explicit.

Comment thread torchtitan/trainer.py Outdated
if config.override.modules:
from torchtitan.registry import apply_overrides

apply_overrides(model_config, config.override)

@drisspg drisspg May 19, 2026 •

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.

had a long convo with codex about the odering of:

The intended contract is that factories receive the post-update_from_config config and are responsible for translating/preserving relevant fields into the replacement config. I agree this should be documented explicitly, especially for common Module.Config fields like param_init and sharding_config, and we can add a regression test to lock that expectation down.

And I kind of agree that if we can have some programmatic way to enforce the overrides makes a config matching copy that would be good, or maybe we just re-order?

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.

And I kind of agree that if we can have some programmtic way to enforce the overrides makes a config matchign copy that would be good, or maybe we just re-order?

By re-order I assume you mean put apply_overrides earlier, say before update_from_config? I don't think we could do that, because update_from_config will set sharding config that's specific to the pre-override module.

I deliberately put apply_overrides after update_from_config before model build, to give override a chance to do a complete replacement, including param_init and sharding_config. I feel that even if we don't add additional check, the existing code will error out at the places that consume these fields, but I agree that providing helpful error messages at proper place would be good, for both humans and agents.

Comment thread torchtitan/registry/DESIGN.md Outdated
INFO: Applied 32 module overrides
```

### External Packages

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.

Do you have a criteria for landing in-repo vs keeping as external in mind?

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.

Right now I can think of three layers, corresponding to the three goals.

  • [GOAL 1] If we don't land it, the perf will look awkward (whether it's pretrain fwd-bwd / RL generator fwd-only) and thus hurt torchtitan. Then let's land it in-repo, which also serves as an example of how to use this plug-in mechanism. It can be for specific common hardware we have access to in CI.
  • [GOAL 2] Our team may develop experimental features in torchtitan, in the experiments folder. They can choose to use existing ModelConfigConverters (more explicit), or to use this registration mechanism (less explicit, but doesn't need to create extra config_registry). Not a huge difference here.
  • [GOAL 3] For external community to showcase their advanced technologies which we are not ready to depend on in-repo (including hardware that we don't have access in CI), we recommend them being out-of-repo.

Comment thread torchtitan/registry/DESIGN.md Outdated
```

```bash
pip install torchtitan-vendor-x

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.

what's the thinking on version compatibility? should we recommendtorchtitan-vendor-x to pin against a torchtitan version? the external packages depend on titan's module signatures.

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.

There are two layers

  1. Being able to modify torchtitan config without touching torchtitan code. This is fundamental capability, unblocking development inside/outside the team, which is what I wanted to focus on in this RFC.
  2. Above that, there is this version compatibility, which can be (and I think has to be) handled in the way you suggested. I agree it's good to clarify it in the RFC itself.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

How about pytorch version? Should vendor package also walk along nightly pytorch similar to TorchTitan? Wondering how to avoid this scenario in the future and reduce maintenance burden from TorchTitan: #3390.

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.

torchtitan should publish stable versions that align with pytorch stable versions. Vendor packages probably only needs to care these versions backed by pytorch stable releases.

torchtitan could publish more frequently as we are doing active (BC-breaking) development, or working closely with vendor to unblock new features that vendor would like to showcase. But in this case, vendor package has to be OK with some pytorch nightly being pinned.

Comment thread torchtitan/registry/DESIGN.md Outdated
`apply_fn(xq, xk, cache, positions)`. In a follow-up, each attention layer will own
its own RoPE module as a submodule, making it naturally replaceable via the config tree.

## Parallelism Compatibility

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.

IIUC, CP is applied on the Attention module, and it's composability interface to consider.

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.

With recent refactor, all SPMD parallelism (other than FSDP) would be encoded in sharding config; in the near future (e.g. when FlexShard is ready), the storage placement would also be put in config.

So it's the author's responsibility to make sure correct sharding config is provided during config swapping.

A concrete example, if someone would like to implement fused ring-based CP, they can do

  • assuming inputs and outputs are sharded on sequence dimension
  • use LocalMapConfig as the contract for above
  • explicit call send/recv/all-to-all collectives in the CP Attention implementation

Comment thread torchtitan/registry/DESIGN.md Outdated

```bash
torchtitan_train --module llama3 --config llama3_8b \
--override.modules='["torchtitan.registry.triton_rope"]'

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.

For agentic hillclimb, I think we need to make the system much more pluggable and overridable, so agent can swap out any components. E.g. swap module impl, optimizer, kernels... (and more).

GraphTrainer currently have 4 open registry, see torchtitan/experiments/graph_trainer/registry.py
User can customize pass_pipeline, memory policy, some hooks to run in the trainer.step()...

I am also further extending the registry to "fusion region extractor" and "kernel generator" in this prototype
https://github.com/pytorch/torchtitan/compare/kernel-fusion-workflow?expand=1

Agent can bring its own "extractor", and try various kernel provider (e.g. KernelAgent, torch.compile, Helion codegen...) to optimize kernel.

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 we need to make the system much more pluggable and overridable, so agent can swap out any components. E.g. swap module impl, optimizer, kernels... (and more).

Totally, we can make it support any Configurable swapping in the first version. I think that'd be enough, because you can swap anything in the config tree, all the way up to trainer.

@syed-ahmed syed-ahmed left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you @tianyu-l ! Love this! Let's ship it. Soliciting more comments from colleagues.

Comment thread torchtitan/registry/DESIGN.md Outdated
compatibility. Should the registry enforce or validate this?

3. **Scope of traverse:** Currently limited to `model_config` (the model's Config tree).
Should it extend to the full `Trainer.Config` tree (optimizer, dataloader, etc.)?

@syed-ahmed syed-ahmed May 19, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Here are couple use cases for overriding optimizers:

Comment thread torchtitan/registry/DESIGN.md Outdated
Current proposal uses "override" throughout.

2. **Checkpoint compatibility:** Override authors are responsible for state_dict key
compatibility. Should the registry enforce or validate this?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could you please point to the state_dict key this referring to? Is this mainly to make sure e2e workflows like loading model into vllm after training in torchtitan has a good UX when using custom modules from registry?

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.

This is talking about the checkpoint compatibility before vs. after override.

It may or may not be necessary depending on what we want to do:

  • In pretraining, if we just want to swap to efficient implementation and train from scratch, it doesn't matter if the checkpoint from the original (slow) impl can be loaded to new (efficient) impl at all.
  • For continued training / sft when loading from a HF checkpoint, torchtitan only provides state dict adapter from HF checkpoint fqn to torchtitan native fqn. If the new impl doesn't work torchtitan native fqn, then it needs to override the state dict adapter in the config as well. It is not obvious why the new impl wouldn't follow the native fqn.
  • For RL between trainer and generator, existing effort is using the same model definition, so checkpoint would be naturally compatible. In the future, I can imagine that people do different optimizations on trainer model and generator model. In that case, it should be desired that the state dict is still compatible, to avoid any fqn remapping, which itself is error-prone (we will still need to do resharding).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If the new impl doesn't work torchtitan native fqn, then it needs to override the state dict adapter in the config as well.

Could we address this by allowing an optional state_dict_translator argument to @register? It would be propagated to the existing from_hf / to_hf functions, eventually enabling things like:

@register("fused_ffn", target=FeedForward.Config,
          state_dict_translator=ffn_translator,
          description="Fused FFN")
def fused_ffn(cfg):
    return FusedFFN.Config(
        dim=cfg.w1.in_features,
        hidden_dim=cfg.w1.out_features,
        param_init={"fused_gate_up.weight": ..., "fused_down.weight": ...},
        ...
    )

This way, override authors can freely use their own internal FQN while still loading/saving checkpoints in a compatible format. Does this approach make sense to you?

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.

How is that different from the checkpointing hook idea in #3396 (comment)?

I'm not seeing the full proposal on state_dict_translator, but it seems requiring inventing one more mechanism in the current Module class? If it can be directly covered by subclassing and overriding state_dict / load_state_dict, I tend to not introduce more mechanisms.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think there is no difference, both seek to bridge the canonical and override internal fqn, but if state_dict itself can eventually be overriden (seems it doesn't have a Config for the time being?), that would be the simplest approach.

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 seem to be wrong after playing with the idea for a bit.

Created #3569 to track the issues. Wish to land this version first.

Comment thread torchtitan/registry/DESIGN.md Outdated

4. **Filter functions:** v1 replaces ALL instances of a target Config class. Should we
support per-instance filtering (e.g., "only replace RoPE in layers 0-10") in the
`@register` API, or is that a v2 feature?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Supporting per-instance filtering is required for NVFP4 training (check layer sensitivity section here: https://arxiv.org/pdf/2509.25149). Also seems like MXFP8 training also cares about this:

- `mxfp8` applied to all linear layers except: `output`, `router.gate`, `attention.wk`, `attention.wv` (Wk and Wv too small to benefit from mxfp8)

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think fqns should be good enough for now.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'll update the NVFP4 integration to use this once it's ready. Right now it's just replacing every linear layer.

Comment thread torchtitan/registry/DESIGN.md Outdated

class TritonRoPE(Module):
"""RoPE implementation using Triton kernels."""

@xmfan xmfan May 19, 2026 •

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'm interested in adding a Fused SwiGLU module, ideally we may want to be able to also customize the __init__ parametrization so that a kernel can access w1 and w3 as a single contiguous buffer:

Unfused (current): 
x1 = x @ w1.T      # w1: [H, D]
x3 = x @ w3.T      # w3: [H, D]
out = (F.silu(x1) * x3) @ w2.T  # w2: [D, H]

Fused:
y13 = x @ w13.T    # w13: [2H, D]
x1, x3 = y13.chunk(2, dim=-1)
out = (F.silu(x1) * x3) @ w2.T

I think GroupedExperts.__init__ gets called before loading weights though, so the module needs to keep the same FQNs, unless we expose some post_init hook that can further customize parametrization? I'm not sure how it would interact with parallelization though.

There might be still a way to implement w1 and w3 as chunks of a larger contiguous allocation, and have the kernel read from them as if they were 1.

Any concerns with allowing modules to do this?

@tianyu-l tianyu-l May 20, 2026 •

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.

This is interesting case!

I think GroupedExperts.init gets called before loading weights though, so the module needs to keep the same FQNs, unless we expose some post_init hook that can further customize parametrization?

Sounds the right approach to me, if we want to load a checkpoint saved from unfused (and not introduce any more complicated state dict adapter in tree).

I'm not sure how it would interact with parallelization though.

For TP, if w13 is of shape [2*D, H], making it colwise sharded, the placement would still be Shard(1), which is expressible by spmd_types.

I was wrong: the colwise sharding should happen on D, not H, thus couldn't be expressed today.

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.

For FusedMLP, if I want to use the new registry system (take used w13, w2), I would need to do following:

  1. Set correct ShardingConfig for w13 and w2 then registry
  2. Add load_state_dict(), state_dict() function in my registry (We should use hooks for that?)

Is there anything I missed? Or current registry is not able to handle FusedMLP?

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.

Today it is not supported, issue summarized in #3569

We probably need something as @sdmyzlp mentioned in #3396 (comment)

@xmfan xmfan Jun 9, 2026 •

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 corrected the sample, the w13 would concat on H dim, not D dim

Comment thread torchtitan/registry/DESIGN.md Outdated
from torchtitan.registry import register
from torchtitan.models.common.moe import MoE

class VendorXFusedMoE(Module):

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 this design, can we in addition fuse communication? like, can i have a kernel that does allreduce + rmsnorm?

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.

Of course we can, as long as the ShardingConfig at the module boundary is set correct.

Comment thread torchtitan/registry/__init__.py Outdated
def register(
name: str,
*,
target: type,

@crcrpar crcrpar May 20, 2026 •

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.

better if it's Type[Configurable.Config] or type[Configurable.Config]?

Comment thread torchtitan/registry/DESIGN.md Outdated
Comment on lines +234 to +235
etc.) for TP/FSDP to work. Model-specific `parallelize_fn` functions may reference
specific module types.

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.

what does reference specific module types mean? right now each model's parallelize_fn have access to only model?

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.

Our direction is to remove model-specific parallelize_fn and push parallelism into config. So I wouldn't read hard into this (AI-generated) sentence.

@acisseJZhong acisseJZhong May 20, 2026 •

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.

Yeah that makes more sense. Maybe ask ai to polish this as community users might not get this if we commit this md?

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.

Yeah I'll polish everything; this is more like an RFC with real code.

Comment thread torchtitan/registry/DESIGN.md Outdated
submodule structure).

**Long-term:** Push parallelism fully into the Module protocol so `parallelize_fn`
doesn't need to know module types. This aligns with torchtitan's ongoing direction

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.

what will this look like?

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.

Like your MoE refactor, TP/CP/EP works with config-based module boundary redistribute.

For FSDP / FlexShard, we will put bucketing and storage placement into config as well.

Comment thread torchtitan/registry/DESIGN.md Outdated
Current proposal uses "override" throughout.

2. **Checkpoint compatibility:** Override authors are responsible for state_dict key
compatibility. Should the registry enforce or validate this?

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.

how could we tell if users' override will cause ckpt compatability issues? For customized kernel it probably won't change model weights, but it will for fused module?

@tianyu-l tianyu-l May 20, 2026 •

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.

It depends on user purpose when swapping modules / configs. It is possible that user may not care about ckpt compatibility at all (e.g. train from scratch with efficient impls, or experimenting with a complete new module).

When they care:

Comment thread torchtitan/registry/DESIGN.md Outdated
## Interaction with Existing Converters

Existing converters (Float8, LoRA) run inside `model_registry()` during config
construction. Overrides run later in `Trainer.__init__`. The override sees the

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.

so the order is first model config convertor, and then overrides. wondering is this better then the other way?

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 so.

In-repo config converter may not understand overrides at all. Overrides author knows everything, so if they believe a in-repo converter could work with their override, they could

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 want to patch to batch invariant kernels, so seems it might be further override by other kernel overrides. Should we consider batch-invariant mode as a converter, because it's mostly op-level override, right?

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.

We have one for flex https://github.com/pytorch/torchtitan/blob/main/torchtitan/experiments/rl/config_registry.py#L40

I think in general

Comment thread torchtitan/registry/DESIGN.md Outdated
|----------|--------|------|--------------|----------|
| Custom module file (recommended) | Yes | No (edit file) | None | Simple, fully typed, no infra. Changing params requires file edit. |
| Untyped kwargs dict | No | Yes | ~50 lines | CLI-friendly but error-prone, awkward nested dict syntax. |
| Typed override Config (like ModelConfigConverter) | Yes | Yes | ~100 lines | Couples config_registry to override package, defeating the "no-touch" goal. |

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.

seems model config convertor can be covered by Custom module file (recommended)?

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.

That's correct. The override is actually very powerful, but it doesn't mean we should use it whenever we can; in fact, I would suggest we use it as little as possible for in-repo development.

Dynamic import and dependency injection would make code less straightforward in general. Even the ModelConfigConverter makes it somewhat worse than building everything you need bottom-up from scratch (remember we had this quantization "as converter" or "from direct build" discussion). Override registration is taking a step further, but comes with its own tradeoff.

Comment thread torchtitan/registry/DESIGN.md Outdated
a clean extension mechanism.

2. **Fused module implementations.** An efficient MoE implementation may fuse the
dispatcher-compute-combine pipeline with custom routing, communication, and

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.

can't wait to see megamoe in titan!!

Comment thread torchtitan/registry/__init__.py Outdated


def _check_conflicts() -> None:
"""Raise if two overrides target the same Config class."""

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.

haven't reviewed the rest yet, but do you deal with the situation where one override targets Parent and another override targets Child? I guess there are a few scenarios

  1. new parent still has a version of child: we could expect the child in the new parent to also be overridden. but wed have to make sure to do the parent override first and then then the child override
  2. new parent doesn't even have the child anymore (it has a different structure). The child override now needs to be discarded, which I think is ok as a silent no-op?

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.

It seems this is NOT the same question as #3396 (comment), and you are talking about A owns B, and our target is A (and B).

If so, my answer would be:
it's all up to the new implementation of A

  • if new A still has child B, it can extract old A's child B and plug in new A; or it can create its new B (if B only appears in A, one doesn't need to override B)
  • if new A doesn't have B any more, that's totally fine, and the Bs which belong to old A just disappear

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.

changing the design a bit -- both scenarios are handled by an explicit error

@wwwjn wwwjn added the ciflow/h100.8 Trigger H100.8 CI label Jun 8, 2026
Comment thread torchtitan/protocols/model_spec.py Outdated
model = self.model
if model is None:
return
if isinstance(model, config_cls):

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.

So this if will only be hit when a user override the whole model?
eg, target=Decoder.Config. Is it valid? Should we directly ban this behavior?

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 ended up allowing that. E.g. a multimodal model may have Decoder as a child module -- I don't feel we have strong reasons to not allow swapping that.

Comment thread torchtitan/config/OVERRIDE.md Resolved

@fegin fegin left a comment

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.

Left some questions and nits.

Comment thread torchtitan/config/override.py Resolved
Comment thread torchtitan/protocols/model_spec.py Outdated
Comment on lines +69 to +70
if isinstance(model, config_cls):
yield "model", model, self, "model"

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.

It seems that we will be able to repalce the entire model using override. Not quite sure if my understanding is correct.

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.

Yes, I ended up allowing that. See my response to wwwjn above.

Comment thread torchtitan/config/override.py Resolved
Comment thread torchtitan/overrides/fused_swiglu.py Outdated
Comment on lines +120 to +121
if cfg.w1.param_init is not None and "weight" in cfg.w1.param_init:
param_init = {"w13": cfg.w1.param_init["weight"]}

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.

we actually make w2w3 share the same init function. You code here is not wrong. But should we consider to avoid making w2 and w3 have the same init function?

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 ended up faithfully following what's specified today, i.e. w1 and w2 having different init fns.

@drisspg

drisspg commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

@claude Please do a deep review focused on subtle correctness bugs and regressions that are easy for human reviewers to miss. Prioritize findings over summary. I dont care about anything that isnt a real bug drop all the noise but that, if you there isnt anything to report just say so with a small comment

@claude

claude Bot commented Jun 8, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @drisspg's task in 6m 19s —— View job


Deep correctness review

I read through the core override logic (override.py), the fused_swiglu example, the ModelSpec traverse bridge, and the trainer integration. One real bug found:


Bug: Ancestor conflict detection broken across the ModelSpec.traverse boundary

torchtitan/protocols/model_spec.py:60-71 — ModelSpec.traverse intentionally drops the incoming _prefix so model component FQNs are bare (e.g. "layers.0.feed_forward" not "model_spec.layers.0.feed_forward"). But when the model itself matches config_cls, it's yielded as ("model", model, self, "model") at line 70. Then at line 71, model.traverse(config_cls) yields children without any prefix.

This means the model lives at FQN "model" while its children have FQNs like "layers.0.feed_forward". The nested-node conflict check in _check_node_conflicts (line 278: b.fqn.startswith(a.fqn + ".")) will never fire because "layers.0.feed_forward".startswith("model.") is False.

Concrete scenario: Override A targets Decoder.Config (claims FQN "model"). Override B targets FeedForward.Config (claims "layers.0.feed_forward"). Both overrides are active. The conflict check passes silently. During mutation, Override A replaces ModelSpec.model with a new config. Override B then does setattr(old_layer_config, "feed_forward", ...) — writing into the old (now unreachable) tree. Override B's replacement is silently lost.

Severity: Low-to-medium. It requires someone to override the entire model config and a component inside it simultaneously, which is unusual. But the conflict detection exists precisely for this class of mistake, and it fails here. A simple fix: when isinstance(model, config_cls) matches, pass _prefix="model" to the recursive model.traverse call on line 71, or skip the recursive call entirely (the stock Configurable.Config.traverse already stops recursing into matched nodes).


Everything else I examined appears correct:

  • _collect_claims iterating per-override avoids cross-contamination.
  • derive() shallow-copy semantics are well-suited (source node is replaced and detached).
  • FQN-based mutation via stored (parent, attr) references is safe given the conflict checks pass.
  • The fused_swiglu sharding config correctly carries in_src_shardings/in_dst_shardings from the original while setting state_shardings for w13.
  • The provenance filter (_resolve_active) properly scopes activation to user-listed modules.

@tianyu-l
tianyu-l merged commit adf340d into main Jun 10, 2026
21 of 25 checks passed
@tianyu-l
tianyu-l deleted the registry branch June 10, 2026 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/h100.8 Trigger H100.8 CI 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.

[RFC] Introduce a Plugin-Mechanism for hardware-specific optimazations