Skip to content

[override] Allow passing kwargs in override from both CLI and config - #3894

Merged
wwwjn merged 6 commits into
mainfrom
override-flexible
Jul 21, 2026
Merged

wwwjn merged 6 commits into
mainfrom
override-flexible

Conversation

@wwwjn

@wwwjn wwwjn commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Why

The override mechanism (override.imports) could only activate a module by name — the
factory had no way to receive parameters. The documented workaround was
"configuration is code": if you wanted different values, you wrote a second override
module.

That breaks down when two config trees that share one model_spec need the same
override configured differently. The motivating case is RL: the trainer and
generator share one model spec but need opposite HybridEP MoE dispatch modes:

  • trainer runs eagerly + backprops → needs the blocking, dropless path
    (capacity_factor=None)
  • generator captures a CUDA graph → needs the static, host-sync-free non-blocking
    path (a float capacity_factor)

With name-only overrides, the only options were (a) two near-identical modules, or
(b) a hardcoded if hybridep: capacity_factor = None branch in the trainer's
_build_model (what PR #3871 had to do). Both are avoidable if the override can just
take a parameter

What

An override.imports entry can now be either a bare module path or a (module_path,
kwargs) tuple; the kwargs are forwarded to that module's factory:

  1. Python config — same module, different value per actor:
    generator.override = OverrideConfig(imports=[(
    "torchtitan.distributed.deepep.hybridep_override", {"capacity_factor": 0.0325},
    )]) # trainer needs no override — capacity_factor=None is the shared spec's default
  2. CLI — kwargs as JSON attached to the name:
    --override.imports 'my_pkg.triton_rope={"block_size": 256}'
  • Factory declares the keyword params it accepts (or **kwargs); an unknown kwarg
    raises a normal TypeError; an entry whose kwargs activate no override raises (no
    silent no-op).
  • Ships the concrete consumer: hybridep_override (sets
    HybridEPTokenDispatcher.Config.non_blocking_capacity_factor from a capacity_factor
    kwarg) + RL recipe rl_grpo_qwen3_moe_debug_hybridep — trainer uses the default
    blocking path, generator activates the override with a float, no hardcoded per-actor
    branch.

@wwwjn
wwwjn requested review from fegin, tianyu-l and wconstab as code owners July 9, 2026 22:26
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 9, 2026
Comment thread torchtitan/config/override.py Outdated
name: str
target_cls: type[Configurable.Config]
factory: Callable[[Configurable.Config], Configurable.Config]
factory: Callable[..., Configurable.Config]

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 we improve this? At least the first arg should be 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.

We can use typing.Concatenate to specify the 1st arg type to be config

eg, Callable[Concatenate[Configurable.Config, ...], Configurable.Config]

Comment thread torchtitan/config/override.py Outdated

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.

The wrapped function itself (import path + function name) should already be "unique identifier". Can we deprecate this name field?

Comment thread torchtitan/config/override.py Resolved

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 not a good location. Maybe put in overrides folder as you are doing for deepep inference override?

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 moved both hybridEP and deepEP override to overrides folder

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 moved both hybridEP and deepEP override to overrides folder

Python module paths to import for override registration.
Override targets to activate, each optionally carrying kwargs.

A target is a ``module.function`` path -- the module plus the ``@override``

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.

Make the target pointing to a module.function (very specific target)

wwwjn added 3 commits July 20, 2026 14:25
Drop the whole-module form; each override.imports entry names exactly one
override as module.function. Simplifies _resolve_active (no module scan or
no-match-kwargs branch) and _resolve_target (split last dotted component,
no import-probing). Update recipes (fused_swiglu now lists both factories),
README/docstrings, and tests.
@wwwjn
wwwjn force-pushed the override-flexible branch from 41f2089 to 8dcd9bd Compare July 20, 2026 21:34
- @OverRide no longer takes a name; the factory's import path
  (module.function) is both the identifier and the registry key, so
  _resolve_active is a direct registry lookup and Override.name is a
  computed property.
- Update callsites, README, and tests to FQN registry keys.
- Post-rebase reconciliation with main's competing override work:
  test_helion_rope activates both helion factories; test_inference_moe
  uses deepep_override(cudagraphable=True) + a registry-pollution guard.
Comment thread tests/unit_tests/test_helion_rope.py Outdated
)

# Overrides are keyed in the registry by their factory's import path.
_HELION_KEY = "torchtitan.overrides.helion_rope.helion_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.

maybe should have cos_sin in naming to be symmetric with the complex counterpart

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.

maybe rename to overrides/moe_token_dispatcher.py, because

  • _override sounds redundant
  • token_dispatcher refers to models/common/token_dispatcher.py

return config


def rl_grpo_qwen3_moe_debug_hybridep() -> Controller.Config:

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.

not tested anywhere, shall we delete?

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 originally added it to show case how hybridEP should be used in RL, let's delete it for now

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.

Merged with HybridEP inference

CLI-settable `kwargs` dict (untyped, error-prone) or a typed override-`Config`
parsed at config-construction time (which would re-couple the config registry to
the override package, defeating the no-touch goal).
**Configuration is code.** By default the override module *is* its

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 part need to be refined

return config


def rl_grpo_qwen3_moe_debug_hybridep() -> Controller.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.

I originally added it to show case how hybridEP should be used in RL, let's delete it for now

wwwjn added 2 commits July 21, 2026 09:48
- Rename overrides/moe_dispatch_override.py -> moe_token_dispatcher.py
  (drop redundant _override; name it after the token_dispatcher it overrides).
- Rename the cos/sin helion factory helion_rope -> helion_cos_sin_rope for
  symmetry with helion_complex_rope; test constants become _HELION_COS_SIN_*.
- Delete rl_grpo_qwen3_moe_debug_hybridep (alphabet_sort) -- the only recipe
  that activated hybridep_override.
The rebase pulled a DeepSeek V3 helion-override integration test from main that
used the bare-module form (torchtitan.overrides.helion_rope); function-only
resolution rejects it. Activate both helion factories (cos_sin + complex)
explicitly.
@wwwjn wwwjn mentioned this pull request Jul 21, 2026
@wwwjn

wwwjn commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

CPU test failure start on main, not related to this PR: https://github.com/pytorch/torchtitan/actions/runs/29784692787 , @mreso could you help check why CPU test failure?

@wwwjn
wwwjn merged commit 0fb45d4 into main Jul 21, 2026
18 of 22 checks passed
@mreso

mreso commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

CPU test failure start on main, not related to this PR: https://github.com/pytorch/torchtitan/actions/runs/29784692787 , @mreso could you help check why CPU test failure?

@wwwjn failure comes from the bump in the transformers version to 5.9.0. Just surfacing now because #2679 was tested with old CI image. Will create a PR to fix it.

mreso added a commit to mreso/torchtitan that referenced this pull request Jul 21, 2026
Absorbs 4 upstream commits (checkpoint load/resume clarify pytorch#3732, override kwargs
from CLI+config pytorch#3894, [spmd_types] VarlenAttention un-hardcode pytorch#3937, VLLMGenerator
readline hang patch pytorch#3950). No conflicts; spmd_types regression verified -- GQA MoE
TP+EP+typecheck (12.48->6.82) and DSA GLM-5 TP=2 (12.53->6.82) both clean.
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