def METHOD_NAME(
    model, optimizer, group=None, offload=False, sync_buffers=False, buffer_max_size=2**23, segment_size=2**20
):
    # check optition type
    assert isinstance(model, paddle.nn.Layer), "The model must be the instance of paddle.nn.Layer."
    assert isinstance(optimizer, Optimizer), "The optimizer must be the instance of paddle.optimizer.Optimizer."
    def check_dtype(param):
        return param.dtype == paddle.float16
    sharded_params = []
    pretreated_params = []
    for p in optimizer._parameter_list:
        if "expert" not in p.name and "gate" not in p.name:
            sharded_params.append(p)
        else:
            pretreated_params.append(p)
    opt_gc = optimizer._grad_clip
    if opt_gc is not None:
        optimizer._grad_clip = ClipGradForShardedMOEByGlobalNorm(
            opt_gc.clip_norm, opt_gc.is_expert_param_func, opt_gc.moe_group, opt_gc.group_name
        )
    # convert model/optimizer
    optimizer = GroupShardedOptimizerStage2(params=sharded_params, optim=optimizer, group=group, offload=offload)
    model = GroupShardedStage2(
        model, optimizer, group=group, sync_buffers=sync_buffers, buffer_max_size=buffer_max_size
    )
    clear_func = model._clear_gradients
    for opt in model._sharding_optimizers:
        def _opt_clear(self):
            clear_func()
            for p in pretreated_params:
                if p.grad is not None:
                    p.grad.zero_()
        opt.clear_grad = MethodType(_opt_clear, opt)
    return model, optimizer