Diff Coverage

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

Source File Diff Coverage (%) Missing Lines
hyper_parallel/components/checkpoint/base.py 100%  
hyper_parallel/components/checkpoint/dcp_checkpointer.py 100%  
hyper_parallel/core/activation_memory/wrapper.py 12.5% 336-340,344-345
hyper_parallel/core/distributed_checkpoint/standard_planner.py 6.7% 113,115,118-123,125-126,129,131,137,231
hyper_parallel/core/fully_shard/state_dict_utils.py 0.0% 933
hyper_parallel/platform/torch/activation_checkpoint/activation_swap.py 0.0% 326,334-338,342-343
hyper_parallel/trainer/callbacks/checkpoint_callback.py 0.0% 17,40
hyper_parallel/core/activation_memory/wrapper.py
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
        therefore cannot infer that this wrapper removes its internal module
        prefix. Map every direct child state name to the wrapped module so
        optimizer save and restore use the same canonical FQNs.
        """
        wrapped_module = self._swap_wrapped_module
        exposed_names = set(wrapped_module._modules)  # pylint: disable=protected-access
        exposed_names.update(wrapped_module._parameters)  # pylint: disable=protected-access
        exposed_names.update(wrapped_module._buffers)  # pylint: disable=protected-access
        if (
                getattr(wrapped_module.__class__, "get_extra_state", nn.Module.get_extra_state)
                != nn.Module.get_extra_state
        ):
            exposed_names.add(nn.modules.module._EXTRA_STATE_KEY_SUFFIX)
        return {name: _SWAP_WRAPPED_MODULE for name in exposed_names}

    @staticmethod
    def _post_state_dict_hook(
        module: nn.Module,  # pylint: disable=W0613
hyper_parallel/core/distributed_checkpoint/standard_planner.py
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135

    Returns:
        tuple[int, ...]: Tuple of offsets for each dimension.
    """
    if dtensor_layout is None:
        # If layout is None, return all zeros (no sharding)
        return tuple(0 for _ in global_shape)

    # Validate layout attributes
    if not hasattr(dtensor_layout, 'mesh_shape') or dtensor_layout.mesh_shape is None:
        raise ValueError("Layout must have mesh_shape attribute")
    if not hasattr(dtensor_layout, 'tensor_map') or dtensor_layout.tensor_map is None:
        raise ValueError("Layout must have tensor_map attribute")
    if not hasattr(dtensor_layout, 'rank_list') or dtensor_layout.rank_list is None:
        raise ValueError("Layout must have rank_list attribute")

    if current_rank not in dtensor_layout.rank_list:
        raise ValueError(
            f"Current rank {current_rank} not found in layout's rank_list {dtensor_layout.rank_list}")

    inner_rank_id = dtensor_layout.rank_list.index(current_rank)
    # Calculate slice area using infer_slice_area_by_rank
    slice_area = infer_slice_area_by_layout(
        dtensor_layout,
        inner_rank_id,
        global_shape,
    )
133
134
135
136
137
138
139
140
141
        inner_rank_id,
        global_shape,
    )
    # Extract offsets (start values) from slice_area
    return tuple(start for start, _ in slice_area)


@dataclass(frozen=True)
class CachedSaveResult:
227
228
229
230
231
232
233
234
235
                layout = obj.layout

                # Get chunk metadata with offsets
                if layout:
                    offsets = _compute_global_offsets(obj.shape, layout, self.rank)
                else:
                    offsets = (0,) * len(local_tensor.shape)

                sizes = local_tensor.shape
hyper_parallel/core/fully_shard/state_dict_utils.py
929
930
931
932
933
934
935
936
937
        if cpu_offload and result.device != target_device:
            result = result.to(target_device)
        return result

    mesh, _ = dtensor_info
    target_device = param.to_local().device

    scalar_placements = [Replicate()] * mesh.ndim
    if cpu_offload and tensor.device != target_device:
hyper_parallel/platform/torch/activation_checkpoint/activation_swap.py
322
323
324
325
326
327
328
329
330
        """
        for param_name, param in super().named_parameters(*args, **kwargs):
            yield param_name.replace(_SWAP_PREFIX, ""), param

    def _fqn_modifiers(self) -> dict[str, str]:
        """Describe the wrapper's state-dict FQN rewrite to PyTorch DCP.

        Distributed state-dict traversal does not use ``named_modules()`` and
        therefore cannot infer that this wrapper removes its internal module
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
        therefore cannot infer that this wrapper removes its internal module
        prefix. Map every direct child state name to the wrapped module so
        optimizer save and restore use the same canonical FQNs.
        """
        wrapped_module = self._swap_wrapped_module
        exposed_names = set(wrapped_module._modules)  # pylint: disable=protected-access
        exposed_names.update(wrapped_module._parameters)  # pylint: disable=protected-access
        exposed_names.update(wrapped_module._buffers)  # pylint: disable=protected-access
        if (
                getattr(wrapped_module.__class__, "get_extra_state", nn.Module.get_extra_state)
                != nn.Module.get_extra_state
        ):
            exposed_names.add(nn.modules.module._EXTRA_STATE_KEY_SUFFIX)
        return {name: _SWAP_WRAPPED_MODULE for name in exposed_names}

    @staticmethod
    def _post_state_dict_hook(
        module: nn.Module,  # pylint: disable=W0613
hyper_parallel/trainer/callbacks/checkpoint_callback.py
13
14
15
16
17
18
19
20
21
# See the License for the specific language governing permissions and
# limitations under the License.
"""CheckpointerCallback --- save/restore policy on top of a Checkpointer."""

__all__ = ["CheckpointerCallback"]

import os
import random
from typing import TYPE_CHECKING, Any, Dict, List, Optional
36
37
38
39
40
41
42
43
44
    get_device_rng_state,
    set_device_rng_state,
)
from hyper_parallel.models._transformers.model_builder import apply_model_init_dtype
from .base import Callback, TrainerState


if TYPE_CHECKING:
    from hyper_parallel.trainer.base import BaseTrainer