# Buggy code
def __init__(
    self,
    learning_rate: Union[FloatTensorLike, Callable] = 0.001,
    beta_1: FloatTensorLike = 0.9,
    beta_2: FloatTensorLike = 0.999,
    epsilon: FloatTensorLike = 1e-7,
    weight_decay: FloatTensorLike = 0.0,
    amsgrad: bool = False,
    sma_threshold: FloatTensorLike = 5.0,
    total_steps: int = 0,
    warmup_proportion: FloatTensorLike = 0.1,
    min_lr: FloatTensorLike = 0.0,
    name: str = "RectifiedAdam",
    **kwargs,
):
    r"""Construct a new RAdam optimizer.

    Args:
        learning_rate: A `Tensor` or a floating point value. or a schedule
            that is a `tf.keras.optimizers.schedules.LearningRateSchedule`
            The learning rate.
        beta_1: A float value or a constant float tensor.
            The exponential decay rate for the 1st moment estimates.
        beta_2: A float value or a constant float tensor.
            The exponential decay rate for the 2nd moment estimates.
        epsilon: A small constant for numerical stability.
        weight_decay: A floating point value. Weight decay for each param.
        amsgrad: boolean. Whether to apply AMSGrad variant of this
            algorithm from the paper "On the Convergence of Adam and
            beyond".
        sma_threshold. A float value.
            The threshold for simple mean average.
        total_steps: An integer. Total number of training steps.
            Enable warmup by setting a positive value.
        warmup_proportion: A floating point value.
            The proportion of increasing steps.
        min_lr: A floating point value. Minimum learning rate after warmup.
        name: Optional name for the operations created when applying
            gradients. Defaults to "RectifiedAdam".
        **kwargs: keyword arguments. Allowed to be {`clipnorm`,
            `clipvalue`, `lr`, `decay`}. `clipnorm` is clip gradients
            by norm; `clipvalue` is clip gradients by value, `decay` is
            included for backward compatibility to allow time inverse
            decay of learning rate. `lr` is included for backward
            compatibility, recommended to use `learning_rate` instead.
    """
    super().__init__(name, **kwargs)
    self._set_hyper("learning_rate", kwargs.get("lr", learning_rate))
    self._set_hyper("beta_1", beta_1)
    self._set_hyper("beta_2", beta_2)
    self._set_hyper("decay", self._initial_decay)
    self._set_hyper("weight_decay", weight_decay)
    self._set_hyper("sma_threshold", sma_threshold)
    self._set_hyper("total_steps", float(total_steps))
    self._set_hyper("warmup_proportion", warmup_proportion)
    self._set_hyper("min_lr", min_lr)
    self.epsilon = epsilon or tf.keras.backend.epsilon()
    self.amsgrad = amsgrad
    self._initial_weight_decay = weight_decay
    self._initial_total_steps = total_steps


# Traceback (TypeError)
Traceback (most recent call last):
File "Boucle_IA.py", line 24, in <module>
model = tf.keras.models.load_model('inference_complete-2020-03-18-Mobilenet.h5', custom_objects={'Lookahead': ranger})
File "C:\Program Files\Python37\lib\site-packages\tensorflow_core\python\keras\saving\save.py", line 146, in load_model
return hdf5_format.load_model_from_hdf5(filepath, custom_objects, compile)
File "C:\Program Files\Python37\lib\site-packages\tensorflow_core\python\keras\saving\hdf5_format.py", line 184, in load_model_from_hdf5
training_config, custom_objects))
File "C:\Program Files\Python37\lib\site-packages\tensorflow_core\python\keras\saving\saving_utils.py", line 229, in compile_args_from_training_config
optimizer_config, custom_objects=custom_objects)
File "C:\Program Files\Python37\lib\site-packages\tensorflow_core\python\keras\optimizers.py", line 819, in deserialize
printable_module_name='optimizer')
File "C:\Program Files\Python37\lib\site-packages\tensorflow_core\python\keras\utils\generic_utils.py", line 303, in deserialize_keras_object
list(custom_objects.items())))
File "C:\Program Files\Python37\lib\site-packages\tensorflow_addons\optimizers\lookahead.py", line 185, in from_config
custom_objects=custom_objects,
File "C:\Program Files\Python37\lib\site-packages\tensorflow_core\python\keras\optimizers.py", line 819, in deserialize
printable_module_name='optimizer')
File "C:\Program Files\Python37\lib\site-packages\tensorflow_core\python\keras\utils\generic_utils.py", line 303, in deserialize_keras_object
list(custom_objects.items())))
File "C:\Program Files\Python37\lib\site-packages\tensorflow_core\python\keras\optimizer_v2\optimizer_v2.py", line 733, in from_config
return cls(**config)
File "C:\Program Files\Python37\lib\site-packages\typeguard\__init__.py", line 809, in wrapper
check_argument_types(memo)
File "C:\Program Files\Python37\lib\site-packages\typeguard\__init__.py", line 670, in check_argument_types
raise exc from None
File "C:\Program Files\Python37\lib\site-packages\typeguard\__init__.py", line 668, in check_argument_types
check_type(description, value, expected_type, memo)
File "C:\Program Files\Python37\lib\site-packages\typeguard\__init__.py", line 598, in check_type
format(argname, qualified_name(expected_type), qualified_name(value)))
TypeError: type of argument "total_steps" must be int; got float instead

# Fixed code
def __init__(
    self,
    learning_rate: Union[FloatTensorLike, Callable] = 0.001,
    beta_1: FloatTensorLike = 0.9,
    beta_2: FloatTensorLike = 0.999,
    epsilon: FloatTensorLike = 1e-7,
    weight_decay: FloatTensorLike = 0.0,
    amsgrad: bool = False,
    sma_threshold: FloatTensorLike = 5.0,
    # float for total_steps is here to be able to load models created before
    # https://github.com/tensorflow/addons/pull/1375 was merged. It should be
    # removed for Addons 0.11.
    total_steps: Union[int, float] = 0,
    warmup_proportion: FloatTensorLike = 0.1,
    min_lr: FloatTensorLike = 0.0,
    name: str = "RectifiedAdam",
    **kwargs,
):
    r"""Construct a new RAdam optimizer.

    Args:
        learning_rate: A `Tensor` or a floating point value. or a schedule
            that is a `tf.keras.optimizers.schedules.LearningRateSchedule`
            The learning rate.
        beta_1: A float value or a constant float tensor.
            The exponential decay rate for the 1st moment estimates.
        beta_2: A float value or a constant float tensor.
            The exponential decay rate for the 2nd moment estimates.
        epsilon: A small constant for numerical stability.
        weight_decay: A floating point value. Weight decay for each param.
        amsgrad: boolean. Whether to apply AMSGrad variant of this
            algorithm from the paper "On the Convergence of Adam and
            beyond".
        sma_threshold. A float value.
            The threshold for simple mean average.
        total_steps: An integer. Total number of training steps.
            Enable warmup by setting a positive value.
        warmup_proportion: A floating point value.
            The proportion of increasing steps.
        min_lr: A floating point value. Minimum learning rate after warmup.
        name: Optional name for the operations created when applying
            gradients. Defaults to "RectifiedAdam".
        **kwargs: keyword arguments. Allowed to be {`clipnorm`,
            `clipvalue`, `lr`, `decay`}. `clipnorm` is clip gradients
            by norm; `clipvalue` is clip gradients by value, `decay` is
            included for backward compatibility to allow time inverse
            decay of learning rate. `lr` is included for backward
            compatibility, recommended to use `learning_rate` instead.
    """
    super().__init__(name, **kwargs)
    self._set_hyper("learning_rate", kwargs.get("lr", learning_rate))
    self._set_hyper("beta_1", beta_1)
    self._set_hyper("beta_2", beta_2)
    self._set_hyper("decay", self._initial_decay)
    self._set_hyper("weight_decay", weight_decay)
    self._set_hyper("sma_threshold", sma_threshold)
    if isinstance(total_steps, float):
        warnings.warn(
            "The parameter `total_steps` passed to the __init__ of RectifiedAdam "
            "is a float. This behavior is deprecated and in Addons 0.11, this "
            "will raise an error. Use an int instead. If you get this message "
            "when loading a model, save it again and the `total_steps` parameter "
            "will automatically be converted to a int.",
            DeprecationWarning,
        )
    self._set_hyper("total_steps", int(total_steps))
    self._set_hyper("warmup_proportion", warmup_proportion)
    self._set_hyper("min_lr", min_lr)
    self.epsilon = epsilon or tf.keras.backend.epsilon()
    self.amsgrad = amsgrad
    self._initial_weight_decay = weight_decay
    self._initial_total_steps = total_steps