class_docstr: Task is the central place to define and wire up components for data processing,
  model training, metric reporting, etc. Task class has a Config class containing
  the config of each component in a descriptive way.
class_docstr_tok: ["Task","is","the","central","place","to","define","and","wire","up","components","for","data","processing",",","model","training",",","metric","reporting",",","etc",".","Task","class","has","a","Config","class","containing","the","config","of","each","component","in","a","descriptive","way","."]
docstr: Wrapper method to train the model using :class:`~Trainer` object.
  
  Args:
      train_config (PyTextConfig): config for training
      rank (int): for distributed training only, rank of the gpu, default is 0
      world_size (int): for distributed training only, total gpu to use, default
          is 1
docstr_tok: ["Wrapper","method","to","train","the","model","using",":","class",":","`","~Trainer","`","object",".","Args",":","train_config","(","PyTextConfig",")",":","config","for","training","rank","(","int",")",":","for","distributed","training","only",",","rank","of","the","gpu",",","default","is","0","world_size","(","int",")",":","for","distributed","training","only",",","total","gpu","to","use",",","default","is","1"]
code: def train(
      self, train_config, rank=0, world_size=1, training_state=None
  ):
      """
      Wrapper method to train the model using :class:`~Trainer` object.
  
      Args:
          train_config (PyTextConfig): config for training
          rank (int): for distributed training only, rank of the gpu, default is 0
          world_size (int): for distributed training only, total gpu to use, default
              is 1
      """
      if training_state:
          result = self.trainer.train_from_state(
              training_state,
              self.data_handler.get_train_iter(rank, world_size),
              self.data_handler.get_eval_iter(),
              self.metric_reporter,
              train_config,
          )
      else:
          result = self.trainer.train(
              self.data_handler.get_train_iter(rank, world_size),
              self.data_handler.get_eval_iter(),
              self.model,
              self.metric_reporter,
              train_config,
              rank=rank,
          )
      return result
  
imports: from typing import List, Optional
  from pytext.common.constants import BatchContext
  from pytext.config import ConfigBase
  from pytext.config.component import Component, ComponentType, create_component, create_data_handler, create_exporter, create_featurizer, create_metric_reporter, create_model, create_trainer
  from pytext.config.field_config import FeatureConfig
  from pytext.data import DataHandler
  from pytext.data.featurizer import Featurizer, SimpleFeaturizer
  from pytext.exporters import ModelExporter
  from pytext.loss import KLDivergenceBCELoss, KLDivergenceCELoss
  from pytext.metric_reporters import MetricReporter
  from pytext.models import Model
  from pytext.trainers import Trainer
  from pytext.utils import cuda
  from pytext.utils.usage import log_class_usage
label_desc: Use image node_id 3 for calling the TaskBase obj's underlying member method code with example usage: obj.train(train_config, rank, world_size, training_state) and returns: result