Diff Coverage

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

Source File Diff Coverage (%) Missing Lines
hyper_parallel/core/optimizer/lr_scheduler.py 0.0% 48-51,74-77,79,108-111,113
hyper_parallel/platform/mindspore/platform.py 16.7% 883-886,888
hyper_parallel/platform/platform.py 66.7% 936
hyper_parallel/platform/torch/platform.py 50.0% 576
hyper_parallel/core/optimizer/lr_scheduler.py
44
45
46
47
48
49
50
51
52
53
54
55
    """

    def _lr_lambda(current_step: int):
        if current_step < num_warmup_steps:
            warmup_progress = current_step / max(1, num_warmup_steps)
            if init_lr == 0.0:
                return warmup_progress
            return (lr_start + (init_lr - lr_start) * warmup_progress) / init_lr

        return 1.0

    return LambdaLR(optimizer, _lr_lambda, last_epoch=last_epoch)
70
71
72
73
74
75
76
77
78
79
80
81
82
83
    """

    def _lr_lambda(current_step: int):
        if current_step < num_warmup_steps:
            warmup_progress = current_step / max(1, num_warmup_steps)
            if init_lr == 0.0:
                return warmup_progress
            return (lr_start + (init_lr - lr_start) * warmup_progress) / init_lr

        min_lr_ratio = min_lr / init_lr if init_lr != 0.0 else 0.0
        return max(
            min_lr_ratio,
            float(num_training_steps - current_step) / float(max(1, num_training_steps - num_warmup_steps)),
        )
104
105
106
107
108
109
110
111
112
113
114
115
116
117

    def lr_lambda(current_step: int):
        lr_decay_steps = int(num_training_steps * lr_decay_ratio)
        if current_step < num_warmup_steps:
            warmup_progress = current_step / max(1, num_warmup_steps)
            if init_lr == 0.0:
                return warmup_progress
            return (lr_start + (init_lr - lr_start) * warmup_progress) / init_lr

        min_lr_ratio = min_lr / init_lr if init_lr != 0.0 else 0.0
        if current_step > lr_decay_steps:
            return min_lr_ratio

        progress = float(current_step - num_warmup_steps) / float(max(1, lr_decay_steps - num_warmup_steps))
hyper_parallel/platform/mindspore/platform.py
879
880
881
882
883
884
885
886
887
888
889
890
891
892

        Returns:
            Tensor: A tensor filled with ones.
        """
        resolved_dtype = mstype.bool_ if dtype is bool else dtype
        tensor = mint.ones(size, dtype=resolved_dtype)
        if device in ("GPU", "Ascend"):
            return tensor.to(device)

        return tensor

    @staticmethod
    def zeros(size, dtype=None, device=None):
        """
hyper_parallel/platform/platform.py
932
933
934
935
936
937
938
939
940

        Raises:
            NotImplementedError: Must be implemented by platform subclasses.
        """
        raise NotImplementedError("Platform subclasses must implement ones")

    @staticmethod
    def zeros(size, dtype=None, device=None):
        """Create a zero-filled tensor of the given shape.
hyper_parallel/platform/torch/platform.py
572
573
574
575
576
577
578
579
580

        Returns:
            Tensor: A tensor filled with ones.
        """
        return torch.ones(size, dtype=dtype, device=device)

    @staticmethod
    def zeros(size, dtype=None, device=None):
        """