Keep the elastic batch size within max_train_batch_size (#8237)