docstr: Batch based schedulers require knowing the number of batches in
  the data. We're not supporting that yet with the Data api, need to figure out
  how to expose this info or restructure batch-based schedulers to not need it.
docstr_tok: ["Batch","based","schedulers","require","knowing","the","number","of","batches","in","the","data",".","We","'re","not","supporting","that","yet","with","the","Data","api",",","need","to","figure","out","how","to","expose","this","info","or","restructure","batch-based","schedulers","to","not","need","it","."]
code: def _prepare_scheduler(self, training_batches, scheduler=None):
      """Batch based schedulers require knowing the number of batches in
      the data. We're not supporting that yet with the Data api, need to figure out
      how to expose this info or restructure batch-based schedulers to not need it.
      """
      if scheduler.batch_based_schedulers:
          raise Exception(
              "New tasks don't yet support batch-based scheduling"
          )
      return scheduler
  
imports: import itertools
  import time
  from contextlib import ExitStack
  from typing import Any, Iterable, List, Optional, Tuple
  import torch
  from pytext.common.constants import BatchContext, Stage
  from pytext.config import PyTextConfig
  from pytext.config.component import Component, ComponentType, create_optimizer, create_scheduler, create_sparsifier
  from pytext.config.pytext_config import ConfigBase
  from pytext.data.data_handler import BatchIterator
  from pytext.metric_reporters import MetricReporter
  from pytext.metrics.intent_slot_metrics import AllMetrics
  from pytext.models.distributed_model import DistributedModel
  from pytext.models.model import Model
  from pytext.optimizer import Adam, learning_rates, Optimizer
  from pytext.optimizer.fp16_optimizer import FP16Optimizer, FP16OptimizerFairseq
  from pytext.optimizer.scheduler import Scheduler
  from pytext.optimizer.sparsifiers.sparsifier import Sparsifier
  from pytext.task.serialize import save
  from pytext.trainers.training_state import TrainingState
  from pytext.utils import cuda, distributed, precision, timing
  from torch.distributed.algorithms.ddp_comm_hooks.default_hooks import fp16_compress_hook
label_desc: Use image node_id 2 for calling the TaskTrainer obj's underlying member method code with example usage: obj._prepare_scheduler(training_batches, scheduler) and returns: scheduler