Repository navigation
[config] Centralize built-in transform relations - #5007
Conversation
| @dataclass(kw_only=True, slots=True) | ||
| class MyTransform(ModelConfigTransform): | ||
| run_after = (QuantizationTransform,) | ||
| run_after = (ExternalPrerequisiteTransform,) |
There was a problem hiding this comment.
oh I didn't think of external transform before.
while I don't know if people outside repo would use transform, or if they use do we have to maintain this mechanism
- I think having two different ways to check run_after / conflicts_with sounds confusing.
- Does it make sense to have an API to let people register edges in the two graphs?
|
I agree @tianyu-l 's point. We don't need to preserve the per-class |
6571b64 to
d48c7b9
Compare
| default_relations.add_precedence( | ||
| before=ExternalPrerequisiteTransform, | ||
| after=MyTransform, | ||
| ) |
There was a problem hiding this comment.
I don't think we need this default_relations at all
There was a problem hiding this comment.
I agree. No one really needs to use it.
| transforms: list[ModelConfigTransform], | ||
| *, | ||
| context: ModelConfigTransformContext, | ||
| relations: TransformRelations = default_relations, |
There was a problem hiding this comment.
default can just be
| relations: TransformRelations = default_relations, | |
| relations: TransformRelations = TransformRelations(), |
or
| relations: TransformRelations = default_relations, | |
| relations: TransformRelations = None, |
d48c7b9 to
684d1f9
Compare
684d1f9 to
b94e114
Compare
b94e114 to
8922583
Compare
733a84e to
adcc65b
Compare
|
@fegin @tianyu-l I made some change for the modules to be able to declare their own relations because
|
|
@jinsooihm I feel there must be a way that we could define the graph relation with |
|
Manual lazy init is ugly and easy to forget. Let's create a mechanism in TorchTitan to handle this. One way to work is |
The Dist-MoE integration imported the standalone backend while defining its module and config types. This made otherwise generic TorchTitan imports fail once another feature referenced the integration classes. Especially problematic for defining relations for transforms #4995, #5007. Route backend symbol access through a cached lazy module. Postponed annotations and deferred MXFP8 defaults keep the integration importable, while selecting Dist-MoE still reports the focused installation error and preserves failures from dependencies inside an installed backend. Test Plan: taskset -c 0-7 pytest tests/unit_tests/cpu/test_optional_imports.py tests/unit_tests/cpu/test_transforms.py tests/unit_tests/cpu/test_dist_moe.py -q -k 'not runtime_passes_per_slot_capacity_to_annex and not dist_moe_671b_recipe_topology' Test Plan: env SKIP=pyrefly-check pre-commit run --files tests/unit_tests/cpu/test_optional_imports.py torchtitan/models/common/dist_moe/_optional.py torchtitan/models/common/dist_moe/mxfp8.py torchtitan/models/common/dist_moe/routed_experts.py torchtitan/models/common/dist_moe/runtime.py torchtitan/config/transform/dist_moe.py
Adds support for LoRA BF16 DistMoE.
`DistMoeRoutedExperts._weight_operands` returns the weights matrices
`w13_EFD, w2_EDF` used to make the DistMoE kernel call.
LoRA overrides `_weight_operands` to add the LoRA matrices to `w13_EFD,
w2_EDF` before returning.
This does not support MXFP8 DistMoE. It would be quite tricky to
implement.
## Some caveats
- `DistMoeTransform -> LoRATransform (for GroupedLinear w13, w2)` would
not error but result in no op. Would it be worth to error out by
checking the parent? It wouldn't be too clean.
- In `transform/lora.py`, `LoRATransform.run_after` registers
`DistMoeRoutedExpert` which requires importing `dist_moe` which is an
optional package dependency. Similar for `common/lora.py`
- Should we just set `LoRATransform.run_after` inside
`transform/dist_moe.py` and move the DistMoE LoRA to DistMoE files?
- This also raises a question on how to do #5007 nicely.
## Test Plan
One node, 4 GB300 GPU DP shard 4, EP 2, LoRA rank 8, alpha 16
Deepseek v3 debug model on DistMoE LoRA compared to LoRA on
`GroupedLinear` on `w13, w2` with all to all backend.
| Metric | Step 1 | Step 100 | Mean absolute difference | RMSE | Maximum
absolute difference |
|---|---:|---:|---:|---:|---:|
| Loss, all-to-all | 8.217248 | 4.354145 | — | — | — |
| Loss, DistMoE | 8.217256 | 4.347911 | 0.002922 | 0.005632 | 0.030035 |
| Grad norm, all-to-all | 0.00892750 | 0.12869738 | — | — | — |
| Grad norm, DistMoE | 0.00892772 | 0.12781706 | 0.005116 | 0.013849 |
0.098999 |
<img width="1120" height="409" alt="Screenshot 2026-10-03 at 3 46 52 PM"
src="https://github.com/user-attachments/assets/3aa077ce-f666-424e-ba3e-6ef818aa8459"
/>
Summary: Consolidate built-in transform ordering and conflict policy in a central relation graph while retaining additive class-local hooks for external transforms. Test Plan: Relevant CPU tests passed (100 tests); exact 8-GPU loss and grad-norm parity matched for 10 steps.
adcc65b to
942af5b
Compare
Summary
Consolidate
run_afterandconflicts_withrelation into one file, rather than scattered for each transform.This makes the import logic simpler and also less brain power to reason about composability.
run_afteris modeled by a direct graphPRECEDESwith an edge(a, b)meaningamust be applied beforeb.conflicts_withis modeled by an undirected graphCONFLICTSwith an edge{a, b}meaningaandbcannot be applied together.PRECEDESdoes not necessarily have to be a DAG (although I would believe a set of reasonable transforms would keep it a DAG), but only the induced subgraph on the user chosen valid set of transforms without conflict should be a DAG.Not sure about this part but Codex insists
External users who implement their own transform outside of torchtitan library should still be able to specify these relations,
so the class owned
run_afterandconflicts_withshould be preserved?