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: Create the task from config, and optionally load metadata/model_state
  This function will create components including :class:`~DataHandler`,
  :class:`~Trainer`, :class:`~MetricReporter`,
  :class:`~Exporter`, and wire them up.
  
  Args:
      task_config (Task.Config): the config of the current task
      metadata: saved global context of this task, e.g: vocabulary, will be
          generated by :class:`~DataHandler` if it's None
      model_state: saved model parameters, will be loaded into model when given
docstr_tok: ["Create","the","task","from","config",",","and","optionally","load","metadata\/model_state","This","function","will","create","components","including",":","class",":","`","~DataHandler","`",",",":","class",":","`","~Trainer","`",",",":","class",":","`","~MetricReporter","`",",",":","class",":","`","~Exporter","`",",","and","wire","them","up",".","Args",":","task_config","(","Task.Config",")",":","the","config","of","the","current","task","metadata",":","saved","global","context","of","this","task",",","e.g",":","vocabulary",",","will","be","generated","by",":","class",":","`","~DataHandler","`","if","it","'s","None","model_state",":","saved","model","parameters",",","will","be","loaded","into","model","when","given"]
code: def from_config(
      cls,
      task_config,
      metadata=None,
      model_state=None,
      tensorizers=None,
      rank=1,
      world_size=0,
  ):
      """
      Create the task from config, and optionally load metadata/model_state
      This function will create components including :class:`~DataHandler`,
      :class:`~Trainer`, :class:`~MetricReporter`,
      :class:`~Exporter`, and wire them up.
  
      Args:
          task_config (Task.Config): the config of the current task
          metadata: saved global context of this task, e.g: vocabulary, will be
              generated by :class:`~DataHandler` if it's None
          model_state: saved model parameters, will be loaded into model when given
      """
      if hasattr(task_config.labels, "target_prob"):
          assert task_config.labels.target_prob == isinstance(
              task_config.model.output_layer.loss,
              (KLDivergenceBCELoss.Config, KLDivergenceCELoss.Config),
          ), "target_prob must be set to True for KD losses"
      featurizer = create_featurizer(
          task_config.featurizer, task_config.features
      )
      # load data
      data_handler = create_data_handler(
          task_config.data_handler,
          task_config.features,
          task_config.labels,
          featurizer=featurizer,
      )
      print("\nLoading data...")
      if metadata:
          data_handler.load_metadata(metadata)
      else:
          data_handler.init_metadata()
  
      metadata = data_handler.metadata
  
      model = create_model(
          task_config.model, task_config.features, metadata
      )
      if model_state:
          model.load_state_dict(model_state)
  
      if cuda.CUDA_ENABLED:
          model = model.cuda()
      metric_reporter = create_metric_reporter(
          task_config.metric_reporter, metadata
      )
      exporter = (
          create_exporter(
              task_config.exporter,
              task_config.features,
              task_config.labels,
              data_handler.metadata,
              task_config.model,
              task_config.featurizer,
          )
          if task_config.exporter
          else None
      )
      return cls(
          trainer=create_trainer(task_config.trainer, model),
          data_handler=data_handler,
          model=model,
          metric_reporter=metric_reporter,
          exporter=exporter,
      )
  
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 1 for calling the TaskBase obj's underlying member method code with example usage: obj.from_config(cls, task_config, metadata, model_state, tensorizers, rank, world_size) and returns: cls