optimizer that implements the adamw algorithm adamw optimization is a stochastic gradient descent method that is based on adaptive estimation of firstorder and secondorder moments with an added method to decay weights per the techniques discussed in the paper decoupled weight decay regularization by loshchilov hutter et al 2019https arxiv orgabs1711 05101 according to kingma et al 2014http arxiv orgabs1412 6980 the underying adam method is computationally efficient has little memory requirement invariant to diagonal rescaling of gradients and is well suited for problems that are large in terms of dataparameters args learningrate a float a keras optimizers schedules learningrateschedule instance or a callable that takes no arguments and returns the actual value to use the learning rate defaults to 0 001 beta1 a float value or a constant float tensor or a callable that takes no arguments and returns the actual value to use the exponential decay rate for the 1st moment estimates defaults to 0 9 beta2 a float value or a constant float tensor or a callable that takes no arguments and returns the actual value to use the exponential decay rate for the 2nd moment estimates defaults to 0 999 epsilon a small constant for numerical stability this epsilon is epsilon hat in the kingma and ba paper in the formula just before section 2 1 not the epsilon in algorithm 1 of the paper defaults to 1e7 amsgrad boolean whether to apply amsgrad variant of this algorithm from the paper on the convergence of adam and beyond defaults to false baseoptimizerkeywordargs references loshchilov et al 2019https arxiv orgabs1711 05101 kingma et al 2014http arxiv orgabs1412 6980 for adam reddi et al 2018 https openreview netpdf idryqu7frz for amsgrad optimizer that implements the adamw algorithm adamw optimization is a stochastic gradient descent method that is based on adaptive estimation of first order and second order moments with an added method to decay weights per the techniques discussed in the paper decoupled weight decay regularization by loshchilov hutter et al 2019 https arxiv org abs 1711 05101 according to kingma et al 2014 http arxiv org abs 1412 6980 the underying adam method is computationally efficient has little memory requirement invariant to diagonal rescaling of gradients and is well suited for problems that are large in terms of data parameters args learning_rate a float a keras optimizers schedules learningrateschedule instance or a callable that takes no arguments and returns the actual value to use the learning rate defaults to 0 001 beta_1 a float value or a constant float tensor or a callable that takes no arguments and returns the actual value to use the exponential decay rate for the 1st moment estimates defaults to 0 9 beta_2 a float value or a constant float tensor or a callable that takes no arguments and returns the actual value to use the exponential decay rate for the 2nd moment estimates defaults to 0 999 epsilon a small constant for numerical stability this epsilon is epsilon hat in the kingma and ba paper in the formula just before section 2 1 not the epsilon in algorithm 1 of the paper defaults to 1e 7 amsgrad boolean whether to apply amsgrad variant of this algorithm from the paper on the convergence of adam and beyond defaults to false base_optimizer_keyword_args references loshchilov et al 2019 https arxiv org abs 1711 05101 kingma et al 2014 http arxiv org abs 1412 6980 for adam reddi et al 2018 https openreview net pdf id ryqu7f rz for amsgrad
from keras.api_export import keras_export
from keras.optimizers import adam
from keras.optimizers import optimizer


@keras_export(["keras.optimizers.AdamW"])
class AdamW(adam.Adam):
    

    def __init__(
        self,
        learning_rate=0.001,
        weight_decay=0.004,
        beta_1=0.9,
        beta_2=0.999,
        epsilon=1e-7,
        amsgrad=False,
        clipnorm=None,
        clipvalue=None,
        global_clipnorm=None,
        use_ema=False,
        ema_momentum=0.99,
        ema_overwrite_frequency=None,
        name="adamw",
        **kwargs,
    ):
        super().__init__(
            learning_rate=learning_rate,
            beta_1=beta_1,
            beta_2=beta_2,
            epsilon=epsilon,
            amsgrad=amsgrad,
            name=name,
            weight_decay=weight_decay,
            clipnorm=clipnorm,
            clipvalue=clipvalue,
            global_clipnorm=global_clipnorm,
            use_ema=use_ema,
            ema_momentum=ema_momentum,
            ema_overwrite_frequency=ema_overwrite_frequency,
            **kwargs,
        )

        if self.weight_decay is None:
            raise ValueError(
                "Argument `weight_decay` must be a float. Received: "
                "weight_decay=None"
            )


AdamW.__doc__ = AdamW.__doc__.replace(
    "{{base_optimizer_keyword_args}}", optimizer.base_optimizer_keyword_args
)