def METHOD_NAME(optimizer, h5py_file):
    if hasattr(optimizers, "TFOptimizer") and isinstance(optimizer, optimizers.TFOptimizer):
        logging.warning(
            'TensorFlow optimizers do not '
            'make it possible to access '
            'optimizer attributes or optimizer state '
            'after instantiation. '
            'As a result, we cannot save the optimizer '
            'as part of the model save file.'
            'You will have to compile your model again after loading it. '
            'Prefer using a Keras optimizer instead '
            '(see keras.io/optimizers).')
    elif (hasattr(optimizers, "optimizer_experimental.Optimizer") and
          isinstance(optimizer, optimizers.optimizer_experimental.Optimizer)):
        logging.warning(
            'Horovod Spark Keras estimator does not support Keras reworked optimizers after Keras 2.11'
            'You will have to change to tf.keras.optimizers.legacy.Optimizer in Keras 2.11+.'
            '(see reworked optimizers at https://github.com/keras-team/keras/tree/master/keras/optimizers/optimizer_experimental)')
    else:
        h5py_file.attrs['training_config'] = json.dumps(
            {
                'optimizer_config': {
                    'class_name': optimizer.__class__.__name__,
                    'config': optimizer.get_config()
                }
            },
            default=serialization.get_json_type).encode('utf8')
        # Save optimizer weights.
        symbolic_weights = optimizer.variables()
        if symbolic_weights:
            optimizer_weights_group = h5py_file.create_group('optimizer_weights')
            weight_values = K.batch_get_value(symbolic_weights)
            weight_names = []
            for w, val in zip(symbolic_weights, weight_values):
                name = str(w.name)
                weight_names.append(name.encode('utf8'))
            optimizer_weights_group.attrs['weight_names'] = weight_names
            for name, val in zip(weight_names, weight_values):
                param_dset = optimizer_weights_group.create_dataset(
                    name, val.shape, dtype=val.dtype)
                if not val.shape:
                    # scalar
                    param_dset[()] = val
                else:
                    param_dset[:] = val
    h5py_file.flush()