code: def setup_task(cfg: FairseqDataclass, **kwargs):
      task = None
      task_name = getattr(cfg, "task", None)
  
      if isinstance(task_name, str):
          # legacy tasks
          task = TASK_REGISTRY[task_name]
          if task_name in TASK_DATACLASS_REGISTRY:
              dc = TASK_DATACLASS_REGISTRY[task_name]
              cfg = dc.from_namespace(cfg)
      else:
          task_name = getattr(cfg, "_name", None)
  
          if task_name and task_name in TASK_DATACLASS_REGISTRY:
              remove_missing = (
                  "from_checkpoint" in kwargs
                  and kwargs["from_checkpoint"]
              )
              dc = TASK_DATACLASS_REGISTRY[task_name]
              cfg = merge_with_parent(
                  dc(), cfg, remove_missing=remove_missing
              )
              task = TASK_REGISTRY[task_name]
  
      assert (
          task is not None
      ), f"Could not infer task type from {cfg}. Available argparse tasks: {TASK_REGISTRY.keys()}. Available hydra tasks: {TASK_DATACLASS_REGISTRY.keys()}"
  
      return task.setup_task(cfg, **kwargs)
  
file_path: fairseq/fairseq/tasks/__init__.py
imports: import argparse
  import importlib
  import os
  from fairseq.dataclass import FairseqDataclass
  from fairseq.dataclass.utils import merge_with_parent
  from hydra.core.config_store import ConfigStore
  from .fairseq_task import FairseqTask, LegacyFairseqTask
label_desc: Use image node_id 1 for calling a global function with example usage: setup_task(cfg) and returns: task