Repository navigation
[PP][2/3] DTensor-aware stage and schedule refactoring - #177728
sanketpurandare wants to merge 1 commit into
Conversation
This PR needs a
|
1b02e65 to
46b91fb
Compare
382466f to
d653abe
Compare
wconstab
left a comment
There was a problem hiding this comment.
reviewed all the changes except stage.py, coming back for that later
|
@claude carefully review this PR. pay special attention to
|
|
Claude finished @wconstab's task in 5m 41s —— View job Review: [PP][2/3] DTensor-aware stage and schedule refactoring
1. P2P Comms for Fwd/Bwd Metadata Inference — Hang Potential1a. STATIC mode skips P2P metadata entirely — hang risk if ranks disagree on modeIn STATIC mode, The Concern: The 1b. Forward metadata P2P ordering: looks correct, no hangForward inference runs stage 0 → N (
The P2P pattern is However, there's a subtle concern: Potential issue: In the V-schedule multi-stage case, the loop iterates stages on a single rank. If stage 1c. Backward metadata P2P ordering: looks correct, but tighter couplingBackward inference runs stage N → 0 (
In the Multi-schedule path ( One concern: 1d.
|
Summary: Refactors PipelineStage and schedule infrastructure for DTensor-aware Pipeline Parallelism. Key changes in stage.py: - Refactored _PipelineStageBase, _PipelineStage, PipelineStage for DTensor support with STATIC/DYNAMIC inference modes - Replaced _RootArgPlaceholder with unified _RecvInfo.is_root_arg flag - New _prepare_forward_infra/_prepare_backward_infra for metadata-driven initialization with DTensor shape/placement tracking - Replaced PipeliningShapeError with PipeliningMetadataError - Added _validate_fwd_inputs using new TensorMeta-based validation - _make_tensor_from_meta moved from stage.py to _utils.py Key changes in schedules.py: - Added _determine_and_set_global_inference_mode() for cross-stage consensus on STATIC vs DYNAMIC mode - Refactored _initialize_stage(s) with mode-change detection - Updated step() callers to extract first_target from target_mbs Key changes in _utils.py: - Replaced old validate_tensor_metadata/validate_tensors_metadata (torch.Tensor signatures) with new TensorMeta-based validation - Removed legacy PipeliningShapeError class Test fixes: - test_stage.py: PipeliningShapeError -> PipeliningMetadataError - test_schedule_multiproc.py: grad context and detach fixes Test Plan: python -m pytest test/distributed/pipelining/ -x stack-info: PR: #177728, branch: sanketpurandare/stack/2
d653abe to
cb7d43d
Compare
Summary: Refactors PipelineStage and schedule infrastructure for DTensor-aware Pipeline Parallelism. Key changes in stage.py: - Refactored _PipelineStageBase, _PipelineStage, PipelineStage for DTensor support with STATIC/DYNAMIC inference modes - Replaced _RootArgPlaceholder with unified _RecvInfo.is_root_arg flag - New _prepare_forward_infra/_prepare_backward_infra for metadata-driven initialization with DTensor shape/placement tracking - Replaced PipeliningShapeError with PipeliningMetadataError - Added _validate_fwd_inputs using new TensorMeta-based validation - _make_tensor_from_meta moved from stage.py to _utils.py Key changes in schedules.py: - Added _determine_and_set_global_inference_mode() for cross-stage consensus on STATIC vs DYNAMIC mode - Refactored _initialize_stage(s) with mode-change detection - Updated step() callers to extract first_target from target_mbs Key changes in _utils.py: - Replaced old validate_tensor_metadata/validate_tensors_metadata (torch.Tensor signatures) with new TensorMeta-based validation - Removed legacy PipeliningShapeError class Test fixes: - test_stage.py: PipeliningShapeError -> PipeliningMetadataError - test_schedule_multiproc.py: grad context and detach fixes Test Plan: python -m pytest test/distributed/pipelining/ -x stack-info: PR: #177728, branch: sanketpurandare/stack/2
99b4a45 to
1fd24af
Compare
Stacked PRs: * #177729 * #177728 * __->__#177727 --- --- --- ### [PP][1/3] DTensor metadata foundation for Pipeline Parallelism Summary: Introduces core DTensor metadata types, helper infrastructure, and utility additions for DTensor-aware Pipeline Parallelism (PP). This commit adds: - Foundational metadata dataclasses: _TensorMeta, _DTensorMeta, _StageMeta, _StageForwardMeta, _StageBackwardMeta - InferenceMode enum (STATIC/DYNAMIC) - _MeshCache for DeviceMesh caching with get_mesh() API and GetMeshCallback protocol - to_tensor(device) / to_dtensor(device, mesh) methods on metadata classes - Refactored flatten_args with optional detach parameter - DTensor-aware microbatch splitting/merging in microbatch.py - Metadata extraction helpers: extract_tensor_meta, extract_tensor_metas, to_local_if_dtensor, validate_and_normalize_to_tuple - TensorMeta-based validation: validate_metadata, validate_static_arg_grad_correspondence - _derive_grad_metas for gradient metadata derivation - _autograd_grad_for_inputs and refactored stage_backward_input in _backward.py - Grad context and detach fixes in test_schedule_multiproc.py Legacy functions (PipeliningShapeError, validate_tensor_metadata, old validate_tensors_metadata) are kept for backward compatibility — removed in the next commit. Test Plan: python -m pytest test/distributed/pipelining/ -x Pull Request resolved: #177727 Approved by: https://github.com/wconstab, https://github.com/acisseJZhong
1fd24af to
d363328
Compare
Summary: Refactors PipelineStage and schedule infrastructure for DTensor-aware Pipeline Parallelism, migrating to the new metadata utilities from [1/3]. Key changes in stage.py: - Refactored _PipelineStageBase, _PipelineStage, PipelineStage for DTensor support with STATIC/DYNAMIC inference modes - Replaced _RootArgPlaceholder with unified _RecvInfo.is_root_arg flag - New _prepare_forward_infra/_prepare_backward_infra for metadata-driven initialization with DTensor shape/placement tracking - Replaced PipeliningShapeError with PipeliningMetadataError - Added _validate_fwd_inputs using new TensorMeta-based validation - _make_tensor_from_meta moved from stage.py to _utils.py Key changes in schedules.py: - Added _determine_and_set_global_inference_mode() for cross-stage consensus on STATIC vs DYNAMIC mode - Refactored _initialize_stage(s) with mode-change detection - Updated step() callers to extract first_target from target_mbs Key changes in _utils.py: - Replaced old validate_tensors_metadata (torch.Tensor signature) with new TensorMeta-based version - Removed legacy backward-compat shims: PipeliningShapeError, validate_tensor_metadata, old validate_tensors_metadata Test fixes: - test_stage.py: PipeliningShapeError -> PipeliningMetadataError Test Plan: python -m pytest test/distributed/pipelining/ -x stack-info: PR: #177728, branch: sanketpurandare/stack/2
d363328 to
59ff000
Compare
|
@pytorchbot merge -i |
Merge startedYour change will be merged while ignoring the following 0 checks: Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
|
@pytorchbot merge -f "Unrelated failures due to broken trunk" |
Merge startedYour change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes). Please use Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Fixes a bug for non-CUDA devices introduced by #177728 due to a misused call to fork_rng * Since the call to fork_rng should specify the device type, I specify this in `schedules.py` * The design of fork_rng seems outdated since the adoption of non-CUDA devices. I change the signature so the device_type default argument is `None`, and is inferred from the passed devices. If it can't be inferred from the device list (because it's a list of ints, for example) we still fallback to the previous value of "cuda". Pull Request resolved: #180512 Approved by: https://github.com/guangyey, https://github.com/albanD Co-authored-by: Yu, Guangye <[email protected]>
…ch#177727) Stacked PRs: * pytorch#177729 * pytorch#177728 * __->__#177727 --- --- --- ### [PP][1/3] DTensor metadata foundation for Pipeline Parallelism Summary: Introduces core DTensor metadata types, helper infrastructure, and utility additions for DTensor-aware Pipeline Parallelism (PP). This commit adds: - Foundational metadata dataclasses: _TensorMeta, _DTensorMeta, _StageMeta, _StageForwardMeta, _StageBackwardMeta - InferenceMode enum (STATIC/DYNAMIC) - _MeshCache for DeviceMesh caching with get_mesh() API and GetMeshCallback protocol - to_tensor(device) / to_dtensor(device, mesh) methods on metadata classes - Refactored flatten_args with optional detach parameter - DTensor-aware microbatch splitting/merging in microbatch.py - Metadata extraction helpers: extract_tensor_meta, extract_tensor_metas, to_local_if_dtensor, validate_and_normalize_to_tuple - TensorMeta-based validation: validate_metadata, validate_static_arg_grad_correspondence - _derive_grad_metas for gradient metadata derivation - _autograd_grad_for_inputs and refactored stage_backward_input in _backward.py - Grad context and detach fixes in test_schedule_multiproc.py Legacy functions (PipeliningShapeError, validate_tensor_metadata, old validate_tensors_metadata) are kept for backward compatibility — removed in the next commit. Test Plan: python -m pytest test/distributed/pipelining/ -x Pull Request resolved: pytorch#177727 Approved by: https://github.com/wconstab, https://github.com/acisseJZhong
Stacked PRs: * pytorch#177729 * __->__#177728 Fixes pytorch#172419 --- --- --- ### [PP][2/3] DTensor-aware stage and schedule refactoring Summary: Refactors PipelineStage and schedule infrastructure for DTensor-aware Pipeline Parallelism, migrating to the new metadata utilities from [1/3]. Key changes in stage.py: - Refactored _PipelineStageBase, _PipelineStage, PipelineStage for DTensor support with STATIC/DYNAMIC inference modes - Replaced _RootArgPlaceholder with unified _RecvInfo.is_root_arg flag - New _prepare_forward_infra/_prepare_backward_infra for metadata-driven initialization with DTensor shape/placement tracking - Replaced PipeliningShapeError with PipeliningMetadataError - Added _validate_fwd_inputs using new TensorMeta-based validation - _make_tensor_from_meta moved from stage.py to _utils.py Key changes in schedules.py: - Added _determine_and_set_global_inference_mode() for cross-stage consensus on STATIC vs DYNAMIC mode - Refactored _initialize_stage(s) with mode-change detection - Updated step() callers to extract first_target from target_mbs Key changes in _utils.py: - Replaced old validate_tensors_metadata (torch.Tensor signature) with new TensorMeta-based version - Removed legacy backward-compat shims: PipeliningShapeError, validate_tensor_metadata, old validate_tensors_metadata Test fixes: - test_stage.py: PipeliningShapeError -> PipeliningMetadataError Test Plan: python -m pytest test/distributed/pipelining/ -x Pull Request resolved: pytorch#177728 Approved by: https://github.com/wconstab
Fixes a bug for non-CUDA devices introduced by pytorch#177728 due to a misused call to fork_rng * Since the call to fork_rng should specify the device type, I specify this in `schedules.py` * The design of fork_rng seems outdated since the adoption of non-CUDA devices. I change the signature so the device_type default argument is `None`, and is inferred from the passed devices. If it can't be inferred from the device list (because it's a list of ints, for example) we still fallback to the previous value of "cuda". Pull Request resolved: pytorch#180512 Approved by: https://github.com/guangyey, https://github.com/albanD Co-authored-by: Yu, Guangye <[email protected]>
…ch#177727) Stacked PRs: * pytorch#177729 * pytorch#177728 * __->__#177727 --- --- --- ### [PP][1/3] DTensor metadata foundation for Pipeline Parallelism Summary: Introduces core DTensor metadata types, helper infrastructure, and utility additions for DTensor-aware Pipeline Parallelism (PP). This commit adds: - Foundational metadata dataclasses: _TensorMeta, _DTensorMeta, _StageMeta, _StageForwardMeta, _StageBackwardMeta - InferenceMode enum (STATIC/DYNAMIC) - _MeshCache for DeviceMesh caching with get_mesh() API and GetMeshCallback protocol - to_tensor(device) / to_dtensor(device, mesh) methods on metadata classes - Refactored flatten_args with optional detach parameter - DTensor-aware microbatch splitting/merging in microbatch.py - Metadata extraction helpers: extract_tensor_meta, extract_tensor_metas, to_local_if_dtensor, validate_and_normalize_to_tuple - TensorMeta-based validation: validate_metadata, validate_static_arg_grad_correspondence - _derive_grad_metas for gradient metadata derivation - _autograd_grad_for_inputs and refactored stage_backward_input in _backward.py - Grad context and detach fixes in test_schedule_multiproc.py Legacy functions (PipeliningShapeError, validate_tensor_metadata, old validate_tensors_metadata) are kept for backward compatibility — removed in the next commit. Test Plan: python -m pytest test/distributed/pipelining/ -x Pull Request resolved: pytorch#177727 Approved by: https://github.com/wconstab, https://github.com/acisseJZhong
Stacked PRs: * pytorch#177729 * __->__#177728 Fixes pytorch#172419 --- --- --- ### [PP][2/3] DTensor-aware stage and schedule refactoring Summary: Refactors PipelineStage and schedule infrastructure for DTensor-aware Pipeline Parallelism, migrating to the new metadata utilities from [1/3]. Key changes in stage.py: - Refactored _PipelineStageBase, _PipelineStage, PipelineStage for DTensor support with STATIC/DYNAMIC inference modes - Replaced _RootArgPlaceholder with unified _RecvInfo.is_root_arg flag - New _prepare_forward_infra/_prepare_backward_infra for metadata-driven initialization with DTensor shape/placement tracking - Replaced PipeliningShapeError with PipeliningMetadataError - Added _validate_fwd_inputs using new TensorMeta-based validation - _make_tensor_from_meta moved from stage.py to _utils.py Key changes in schedules.py: - Added _determine_and_set_global_inference_mode() for cross-stage consensus on STATIC vs DYNAMIC mode - Refactored _initialize_stage(s) with mode-change detection - Updated step() callers to extract first_target from target_mbs Key changes in _utils.py: - Replaced old validate_tensors_metadata (torch.Tensor signature) with new TensorMeta-based version - Removed legacy backward-compat shims: PipeliningShapeError, validate_tensor_metadata, old validate_tensors_metadata Test fixes: - test_stage.py: PipeliningShapeError -> PipeliningMetadataError Test Plan: python -m pytest test/distributed/pipelining/ -x Pull Request resolved: pytorch#177728 Approved by: https://github.com/wconstab
Fixes a bug for non-CUDA devices introduced by pytorch#177728 due to a misused call to fork_rng * Since the call to fork_rng should specify the device type, I specify this in `schedules.py` * The design of fork_rng seems outdated since the adoption of non-CUDA devices. I change the signature so the device_type default argument is `None`, and is inferred from the passed devices. If it can't be inferred from the device list (because it's a list of ints, for example) we still fallback to the previous value of "cuda". Pull Request resolved: pytorch#180512 Approved by: https://github.com/guangyey, https://github.com/albanD Co-authored-by: Yu, Guangye <[email protected]>
Stacked PRs:
Fixes #172419
[PP][2/3] DTensor-aware stage and schedule refactoring
Summary:
Refactors PipelineStage and schedule infrastructure for DTensor-aware
Pipeline Parallelism, migrating to the new metadata utilities from [1/3].
Key changes in stage.py:
DTensor support with STATIC/DYNAMIC inference modes
initialization with DTensor shape/placement tracking
Key changes in schedules.py:
consensus on STATIC vs DYNAMIC mode
Key changes in _utils.py:
new TensorMeta-based version
validate_tensor_metadata, old validate_tensors_metadata
Test fixes:
Test Plan:
python -m pytest test/distributed/pipelining/ -x