Repository navigation
[override] Allow passing kwargs in override from both CLI and config - #3894
Conversation
| name: str | ||
| target_cls: type[Configurable.Config] | ||
| factory: Callable[[Configurable.Config], Configurable.Config] | ||
| factory: Callable[..., Configurable.Config] |
There was a problem hiding this comment.
can we improve this? At least the first arg should be config
There was a problem hiding this comment.
We can use typing.Concatenate to specify the 1st arg type to be config
eg, Callable[Concatenate[Configurable.Config, ...], Configurable.Config]
There was a problem hiding this comment.
The wrapped function itself (import path + function name) should already be "unique identifier". Can we deprecate this name field?
There was a problem hiding this comment.
seems not a good location. Maybe put in overrides folder as you are doing for deepep inference override?
There was a problem hiding this comment.
I moved both hybridEP and deepEP override to overrides folder
There was a problem hiding this comment.
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`` |
There was a problem hiding this comment.
Make the target pointing to a module.function (very specific target)
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.
- @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.
| ) | ||
|
|
||
| # Overrides are keyed in the registry by their factory's import path. | ||
| _HELION_KEY = "torchtitan.overrides.helion_rope.helion_rope" |
There was a problem hiding this comment.
maybe should have cos_sin in naming to be symmetric with the complex counterpart
There was a problem hiding this comment.
maybe rename to overrides/moe_token_dispatcher.py, because
_overridesounds redundanttoken_dispatcherrefers to models/common/token_dispatcher.py
| return config | ||
|
|
||
|
|
||
| def rl_grpo_qwen3_moe_debug_hybridep() -> Controller.Config: |
There was a problem hiding this comment.
not tested anywhere, shall we delete?
There was a problem hiding this comment.
I originally added it to show case how hybridEP should be used in RL, let's delete it for now
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
This part need to be refined
| return config | ||
|
|
||
|
|
||
| def rl_grpo_qwen3_moe_debug_hybridep() -> Controller.Config: |
There was a problem hiding this comment.
I originally added it to show case how hybridEP should be used in RL, let's delete it for now
- 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.
|
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. |
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.
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:
(capacity_factor=None)
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:
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
--override.imports 'my_pkg.triton_rope={"block_size": 256}'
raises a normal TypeError; an entry whose kwargs activate no override raises (no
silent no-op).
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.