Ejemplo n.º 1
0
    def __init__(
            self,
            params,
            lr=1e-3,
            bias_correction=True,
            betas=(0.9, 0.999),
            eps=1e-8,
            weight_decay=0,
            use_fp16_stats=False,
    ):
        defaults = {
            "lr": lr,
            "bias_correction": bias_correction,
            "betas": betas,
            "eps": eps,
            "weight_decay": weight_decay,
        }
        super().__init__(params, defaults)

        self.use_fp16_stats = use_fp16_stats
        self.FLOAT16_MAX = 65504.0

        if not has_deepspeed_cpu_adam:
            raise ImportError(
                "Please install DeepSpeed: pip install deepspeed")

        self.opt_id = CPUAdam.optimizer_id
        CPUAdam.optimizer_id = CPUAdam.optimizer_id + 1

        self.ds_opt_adam = CPUAdamBuilder().load()
        adamw_mode = True
        self.ds_opt_adam.create_adam(self.opt_id, lr, betas[0], betas[1], eps,
                                     weight_decay, adamw_mode)
Ejemplo n.º 2
0
def _get_cpu_adam():
    try:
        from deepspeed.ops.op_builder import CPUAdamBuilder
        return CPUAdamBuilder().load()
    except ImportError:
        # fbcode
        from deepspeed.ops.adam import DeepSpeedCPUAdam as ds_opt_adam
        return ds_opt_adam