Repository navigation
preparing pipeline runtime for MTP+PP - #4486
acisseJZhong wants to merge 2 commits into
Conversation
| num_tokens_per_dp_rank * dp_degree | ||
| ) | ||
| # apply parallelisms and initialization | ||
| self.pipeline_runtime = PipelineRuntime() |
There was a problem hiding this comment.
why initing here if later it's going to be assigned to something else
|
|
||
| self.model_parts = [model] | ||
|
|
||
| self.pipeline_runtime.synchronize_parameters() |
|
|
||
| Args: | ||
| fqn: Parameter FQN shared by the canonical and replica stage modules. | ||
| stage_indices: Stage indices ordered as ``(canonical, replica)``. |
There was a problem hiding this comment.
I think this idea of one fqn can be put on multiple PP ranks is legit. But who's canonical, who's replica?
I feel we can generalize the FlexShard Owned placement here, to allow a param to be owned by multiple ranks.
- if owned by every rank, it's Replicate
- the gradient should be Partial as they are seeing different data
And the grad norm computation should be handled automatically by the placement itself. I suppose it could also properly handle DCP resharding, which seems not considered in this PR?
| return tensor._local_tensor if isinstance(tensor, DTensor) else tensor | ||
|
|
||
|
|
||
| class SharedParameterPipelineRuntime(PipelineRuntime): |
There was a problem hiding this comment.
As mentioned above, I feel this should be handled by tensor placement, rather than pipeline runtime. In particular, I'm not convinced that PipelineRuntime needs to be introduced.
713a6bb to
11a1c28
Compare
11a1c28 to
1c7578c
Compare
1c7578c to
39c4851
Compare
5a10154 to
4a6fdec
Compare
4a6fdec to
d11aabf
Compare
d11aabf to
1052bed
Compare
1052bed to
3e6f0d4
Compare
3e6f0d4 to
e8f34ce
Compare
Summary
This PR introduces model-owned lifecycle hooks for parameters replicated across
eager pipeline stages. The initial use case is MTP: the first stage owns the
input embedding weight, while the final stage keeps a replica so it can embed
shifted tokens locally. The runtime keeps the two copies synchronized, combines
their gradient contributions, and counts the shared parameter only once when
computing the gradient norm.
This PR contains only the generic infrastructure from D118152394. MTP + PP and
its model-specific stage metadata will follow in a separate stacked PR.
Design
Pipeline builders now return a
PipelineResultcontaining the schedule, localmodel parts, global virtual-stage indices, stage ownership flags, and a
PipelineRuntime.PipelineRuntimefollows the null-object pattern. The default implementationis a no-op, so the Trainer invokes the same hooks unconditionally for non-PP
and ordinary PP jobs. A model-specific pipeline builder can replace it with a
specialized runtime without adding model checks to the Trainer.
The Trainer invokes runtime hooks at four lifecycle boundaries:
Shared Parameters Across Pipeline Stages
PipelineSharedParameterSpecidentifies a parameter by FQN and records itscanonical and replica virtual stages. The canonical stage owns the authoritative
value after initialization or checkpoint load; the replica stage holds an
additional copy for its local computation.
SharedParameterPipelineRuntimethen:load;
optimization; and
applying the clipping coefficient to both copies.
Same-rank copies use local operations. Cross-rank copies communicate through
an owner-only group, reusing the full PP group when it has exactly two ranks.
DTensor communication operates on corresponding local shards.
Compatibility
structured
PipelineResultwith the no-op runtime.model-owned pipeline hooks that it does not yet execute.
Tests
The tests cover the no-op runtime, same-rank and cross-rank shared parameters,
canonical-source broadcast, gradient summation, owner-group setup, logical
grad-norm filtering, Trainer lifecycle calls, and updated pipeline providers.