def METHOD_NAME(optimizer):
    if not isinstance(optimizer._param_groups[0], dict):
        params_grads = []
        for param in optimizer._param_groups:
            if param.stop_gradient:
                continue
            if param._grad_ivar() is not None:
                grad_var = param._grad_ivar()
                params_grads.append((param, grad_var))
        # currently, only support ClipGradByGlobalNorm and without regularization.
        if isinstance(params_grads, list) and optimizer.regularization is None:
            if optimizer._grad_clip is None or isinstance(optimizer._grad_clip, paddle.nn.ClipGradByGlobalNorm):
                params_grads = _flatten_param_grads(optimizer, params_grads)
        optimizer._apply_optimize(
            loss=None,
            startup_program=None,
            params_grads=params_grads,
            param_group_idx=0,
        )
    else:
        raise RuntimeError("flatten_param_grads is not supported when _param_groups[0] is dict.")