def _configure_kfac_kwargs_for_adaptive(kfac_kwargs, adaptive):
    """Checks and fills in some required kwargs to use an adaptive mode.

  This will set up kfac_kwargs for adaptive, adapt_damping, and/or qmodel
  momentum, if needed. It will not check for train_batch or batch_size, as that
  check happens right before the minimize. It will set the following if not set
  by the user:

  If adaptive=True:
    - adapt_damping=True, momentum=None, momentum_type='qmodel'
    - The checks listed below.

  If adapt_damping=True:
    - use_passed_loss=True, and then it will get the loss_tensor from minimize.
    - update_damping_immediately=True
    - damping_adaptation_interval=5 if the user hasn't set this already.
    - invert_every=5 if the user hasn't set this already.

  If momentum_type='qmodel' or momentum_type='qmodel_fixedmu':
    - Ensures learning rate and momentum are None.

  Args:
   kfac_kwargs: dict of keyword arguments to be passed to
     PeriodicInvCovUpdateKfacOpt.
   adaptive: bool indicating the optimizer is in adaptive mode.
  """
    if adaptive:
        kfac_kwargs.update({'adapt_damping': True, 'momentum': None,
            'momentum_type': 'qmodel'})
    if kfac_kwargs.get('momentum_type', 'regular').lower().startswith('qmodel'
        ):
        if kfac_kwargs['learning_rate']:
            raise ValueError(
                'learning_rate must be None to use adaptive/qmodel.')
        if kfac_kwargs.get('momentum', None):
            raise ValueError('momentum must be None to use adaptive/qmodel.')
    if kfac_kwargs.get('adapt_damping', False):
        defaults = {'use_passed_loss': True, 'update_damping_immediately': True
            }
        defaults.update(kfac_kwargs)
        kfac_kwargs.update(defaults)
        if not ('invert_every' in kfac_kwargs and 
            'damping_adaptation_interval' in kfac_kwargs):
            kfac_kwargs['invert_every'] = 5
            kfac_kwargs['damping_adaptation_interval'] = 5
