Diff Coverage

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

Source File Diff Coverage (%) Missing Lines
hyper_parallel/auto_parallel/sapp_nd/nd/common/cost_model_preprocess.py 0.0% 316,318
hyper_parallel/auto_parallel/sapp_nd/nd/common/framework_parsers/cost_model_parser_hyper.py 33.3% 748-749,772-773
hyper_parallel/auto_parallel/sapp_nd/nd/common/framework_parsers/cost_model_parser_mindformers.py 0.0% 16,27,204,210-211
hyper_parallel/compile/trainer.py 0.0% 119-120
hyper_parallel/components/checkpoint/registry.py 28.6% 70-73,86
hyper_parallel/trainer/base.py 2.7% 693-696,698,703-706,709,714-718,721,723,725-731,736,738-739,741,743-744,747-752
hyper_parallel/trainer/callbacks/base.py 50.0% 32
hyper_parallel/auto_parallel/sapp_nd/nd/common/cost_model_preprocess.py
312
313
314
315
316
317
318
319
320
321
322
            target_ccfg.b,
            target_ccfg.vp,
        )
        if hasattr(target_ccfg.parser, "config_shard_emb"):
            target_ccfg.parser.config_shard_emb(target_ccfg)
        if hasattr(target_ccfg.parser, "config_shard_recompute"):
            target_ccfg.parser.config_shard_recompute(target_ccfg)
        target_ccfg.parser.config_dp_tp_exp(target_ccfg)
        target_ccfg.parser.config_optimizer_shard(target_ccfg)
        target_ccfg.parser.config_comm_flag(target_ccfg)
        if fr is not None:
hyper_parallel/auto_parallel/sapp_nd/nd/common/framework_parsers/cost_model_parser_hyper.py
744
745
746
747
748
749
750
751
752
753
        ``config_shard_emb`` call (guarded by ``hasattr``) and the initial
        ``shard_embed`` value computed in ``_init_shard`` is never refreshed,
        producing an embedding-memory mismatch versus the MF parser.
        """
        target_ccfg = self.ccfg if ccfg is None else ccfg
        target_ccfg.shard_embed = (
            target_ccfg.d
            if (target_ccfg.vocab_emb_dp and target_ccfg.p == 1)
            else (target_ccfg.t * target_ccfg.d)
        )
768
769
770
771
772
773
774
775
776
777
        computed at initial parse time (using the default ``t`` from the
        YAML), causing memory-estimation errors when the search explores
        strategies with different ``t`` values.
        """
        target_ccfg = self.ccfg if ccfg is None else ccfg
        target_ccfg.shard_recompute_input = (
            target_ccfg.t if self._recompute_slice_activation else 1
        )

    def _init_shard(self):
hyper_parallel/auto_parallel/sapp_nd/nd/common/framework_parsers/cost_model_parser_mindformers.py
12
13
14
15
16
17
18
19
20
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
"""parser child class"""
from typing import Any

from hyper_parallel.auto_parallel.sapp_nd.nd.common.config import Config
from hyper_parallel.auto_parallel.sapp_nd.nd.common.framework_parsers._cost_model_parser import _CostModelParser
from hyper_parallel.auto_parallel.sapp_nd.memory_estimation.size import Memory
23
24
25
26
27
28
29
30
31

class CostModelParserMindformers(_CostModelParser):
    """parser class for MindFormers format"""

    def parse(self) -> None:
        """Parse the configured MindFormers YAML fields."""
        self.__config_parse_yaml()

    def __config_parse_yaml_parallelism(self):
200
201
202
203
204
205
206
207
208
        self.ccfg.rec_op.ffAct = int(
            not (self.config.recompute_config.select_recompute and self.ccfg.sp > 1)
        )

    def config_shard_emb(self, ccfg: Any = None) -> None:
        """Configure embedding and output activation sharding.

        Args:
            ccfg: Cost-model config to update. Defaults to the parser's config.
206
207
208
209
210
211
212
213
214
215

        Args:
            ccfg: Cost-model config to update. Defaults to the parser's config.
        """
        target_ccfg = self.ccfg if ccfg is None else ccfg
        target_ccfg.shard_embed = (
            target_ccfg.d
            if (target_ccfg.vocab_emb_dp and target_ccfg.p == 1)
            else (target_ccfg.t * target_ccfg.d)
        )
hyper_parallel/compile/trainer.py
115
116
117
118
119
120
121
122
123
124

        Returns:
            loss: Loss value
        """
        if self.optimizer is None:
            self.compile(input_batch, label_batch)
        return self._compiler.forward_backward(input_batch, label_batch)

    def to(self, device: torch.device) -> "GraphTrainer":
        """Move the model to ``device`` and remember it for batch placement.
hyper_parallel/components/checkpoint/registry.py
66
67
68
69
70
71
72
73
74
75
76
77
        self._local_mapping.update({key: value})

    def __delitem__(self, key: str) -> None:
        """Delete every registration for ``key`` from this registry."""
        if key not in self._local_mapping and key not in self._global_mapping:
            raise KeyError(key)
        self._local_mapping.pop(key, None)
        self._global_mapping.pop(key, None)

    def __iter__(self) -> Iterator[str]:
        """Iterate over all valid keys, local overrides taking precedence."""
        # Ensure we use all keys, with the overwritten ones on top
82
83
84
85
86
87
88
89
90
        return len(self._global_mapping.keys() | self._local_mapping.keys())

    def __contains__(self, key: object) -> bool:
        """Return whether ``key`` has a local or global registration."""
        return key in self._local_mapping or key in self._global_mapping

    def register(
        self,
        key: str,
hyper_parallel/trainer/base.py
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
        """Synchronize all ranks and tear down the distributed process group."""
        if not dist.is_available() or not dist.is_initialized():
            return

        try:
            empty_cache()
            dist.barrier()
            synchronize()
        finally:
            destroy_process_group()

    def train(self) -> None:
        """Run the configured training loop."""
        config: TrainerConfig = self.config
        self.data_iterator = None
        try:
            self.on_train_begin()
            self.data_iterator = HyperIter(
                self.train_dataloader, use_background_prefetcher=config.dataloader.use_background_prefetcher
            )
            logger.info(
                "Rank%s Start training. Global step: %s. Train iters: %s. Start epoch: %s. Train epochs: %s.",
                self.local_rank, self.state.global_step, self.train_iters, self.state.epoch, self.train_epochs,
            )

            start_epoch = self.state.epoch
            for epoch in range(start_epoch, self.train_epochs):
                if epoch != start_epoch:
                    self.train_dataloader.set_epoch(epoch)
                    self.data_iterator = HyperIter(
                        self.train_dataloader, use_background_prefetcher=config.dataloader.use_background_prefetcher
                    )
                self.state.epoch = epoch

                self.on_epoch_begin()

                start_step = self.state.global_step - epoch * self.train_steps
                train_steps = min(self.train_steps, self.train_iters - epoch * self.train_steps)
                for _ in range(start_step, train_steps):
                    try:
                        self.train_step(self.data_iterator)
                    except StopIteration:
                        logger.info(
                            "epoch:%s Dataloader finished with drop_last %s",
                            epoch,
                            config.dataloader.drop_last,
                        )
                        break

                self.on_epoch_end()
                self.state.epoch = epoch + 1

                print_device_mem_info(f"VRAM usage after epoch {epoch + 1}")

                self.data_iterator.stop()
                self.data_iterator = None
        finally:
            # ExitStack runs every callback even when an earlier cleanup raises.
            with ExitStack() as cleanup:
                cleanup.callback(self.destroy_distributed)
                cleanup.callback(synchronize)
                cleanup.callback(self.on_train_end)
                if self.data_iterator is not None:
                    cleanup.callback(self.data_iterator.stop)
hyper_parallel/trainer/callbacks/base.py
28
29
30
31
32
33
34
35
36
    """Base callback bound to a Trainer through a weak reference."""

    def __init__(self, trainer: "BaseTrainer") -> None:
        """Bind the callback to its owning trainer."""
        self.trainer = weakref.proxy(trainer)
        self.mesh = trainer.mesh

    def on_step_begin(self, state: TrainerState, micro_batches: List[Dict[str, Any]] = None, **kwargs: Any) -> None:
        """Hook invoked at the start of each training step.