Diff Coverage

Diff: origin/master...HEAD, staged and unstaged changes

Source File Diff Coverage (%) Missing Lines
hyper_parallel/core/activation_checkpoint/swap.py 100%  
hyper_parallel/core/pipeline_parallel/mpipe/schedule.py 100%  
hyper_parallel/core/pipeline_parallel/pipeline_swap.py 92.0% 68,88,93-94,262,392,397
hyper_parallel/core/pipeline_parallel/scheduler.py 85.3% 957,1010,1012,1014,1016
hyper_parallel/platform/mindspore/platform.py 100%  
hyper_parallel/platform/platform.py 66.7% 938
hyper_parallel/platform/torch/platform.py 100%  
hyper_parallel/core/pipeline_parallel/pipeline_swap.py
64
65
66
67
68
69
70
71
72

    def group_context(self, step: Any) -> ContextManager[None]:
        """Enter the run-scoped swap group for one forward leaf."""
        if not self.manages(step):
            return nullcontext()
        key = self._key(step)
        group_name = self._group_names[key]
        self._manager.ensure_group(group_name)
        self._forward_context_keys.add(key)
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
    def group_name(self, step: Any) -> str:
        """Return the physical group name for a managed step."""
        key = self._key(step)
        if key not in self._group_names:
            raise RuntimeError(f"Pipeline swap does not manage chunk {key}.")
        return self._group_names[key]

    def wait_load(self, step: Any) -> None:
        """Wait for H2D on the scheduler's current compute stream."""
        if self.manages(step):
            self._manager.wait_load(self.group_name(step))

    def protect_aliases(self, step: Any, tensors: Any) -> None:
        """Keep pipeline-owned aliases resident for a managed chunk."""
        if self.manages(step):
258
259
260
261
262
263
264
265
266
        if (
                step is not None
                and step.type == MetaStepType.FSDP_UNSHARD
                and step.stage_index == bwd_leaf.step.stage_index):
            return index
    return bwd_leaf.container_index


def inject_pipeline_swap_steps(order: List[Any]) -> List[Any]:
388
389
390
391
392
393
394
395
396
397
398
399
400
401


def swap_wait_offload(step: Any, session: PipelineSwapSession) -> None:
    """Wait for a pipeline swap group's D2H and release device storage."""
    SwapManager().wait_offload(session.group_name(step))


def swap_launch_load(step: Any, session: PipelineSwapSession) -> None:
    """Launch H2D for a pipeline swap group."""
    SwapManager().launch_load(session.group_name(step))


def swap_wait_load(step: Any, session: PipelineSwapSession) -> None:
    """Wait for a pipeline swap group's H2D before its backward container."""
hyper_parallel/core/pipeline_parallel/scheduler.py
953
954
955
956
957
958
959
960
        elif step_type == MetaStepType.FWD_RECV:
            self.recv_fwd(stage, micro_index)

        elif step_type == MetaStepType.FWD:
            self.execute_fwd_leaf(cur_step, arg_mbs, kwarg_mbs, losses)

        elif step_type == MetaStepType.FWD_SEND:
            self.send_fwd(stage, micro_index)
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020

    def _exec_pipeline_swap_step(self, cur_step, arg_mbs, kwarg_mbs):
        """Execute a pipeline activation-swap control step."""
        if self._swap_session is None:
            raise RuntimeError("Pipeline swap step executed without an active run session.")
        if cur_step.type == MetaStepType.SWAP_LAUNCH_OFFLOAD:
            swap_launch_offload(cur_step, self, arg_mbs, kwarg_mbs, self._swap_session)
        elif cur_step.type == MetaStepType.SWAP_WAIT_OFFLOAD:
            swap_wait_offload(cur_step, self._swap_session)
        elif cur_step.type == MetaStepType.SWAP_LAUNCH_LOAD:
            swap_launch_load(cur_step, self._swap_session)
        elif cur_step.type == MetaStepType.SWAP_WAIT_LOAD:
            swap_wait_load(cur_step, self._swap_session)

    def run_microbatches(self, arg_mbs: list, kwarg_mbs: list, losses: list) -> None:
hyper_parallel/platform/platform.py
934
935
936
937
938
939
940
941
942
        Returns:
            An iterable of ``(name, buffer)`` pairs, including non-persistent
            buffers and buffers registered by child modules.
        """
        raise NotImplementedError("Platform subclasses must implement buffers_dict")

    @staticmethod
    def get_model_state_dict(model: Any, *, options: Any = None) -> dict[str, Any]:
        """Get the state dictionary of a model.