code: def save_and_export(
      config: PyTextConfig,
      task: Task_Deprecated,
      metric_channels: Optional[List[Channel]] = None,
  ) -> None:
      latest_snapshot_path = config.save_snapshot_path
      print("\n=== Saving model to: " + latest_snapshot_path)
      meta = None
      tensorizers = None
      if hasattr(task, "data_handler"):
          meta = task.data_handler.metadata_to_save()
      else:
          tensorizers = task.data.tensorizers
      save(config, task.model, meta, tensorizers=tensorizers)
  
      if config.export_list:
          export_configs = config.export_list
      elif config.export:
          export_configs = [config.export]
      else:
          export_configs = []
          print("No export options provided.")
  
      for export_config in export_configs:
          if export_config is not None:
              if len(export_configs) > 1:
                  local_task = reload_task_for_multi_export(
                      config, latest_snapshot_path
                  )
              else:
                  local_task = task
              if export_config.export_caffe2_path:
                  local_task.export(
                      model=local_task.model,
                      export_path=export_config.export_caffe2_path,
                      metric_channels=metric_channels,
                      export_onnx_path=export_config.export_onnx_path,
                  )
              if export_config.export_torchscript_path:
                  try:
                      local_task.torchscript_export(
                          model=local_task.model,
                          export_path=export_config.export_torchscript_path,
                          export_config=export_config,
                      )
                  except (RuntimeError, TypeError) as e:
                      print(
                          "Ran into error: {}".format(", ".join(e.args))
                      )
                      traceback.print_exception(*sys.exc_info())
                      print(
                          f"The torchscript model at {export_config.export_torchscript_path} could not be saved, skipping for now."
                      )
              if export_config.export_lite_path:
                  local_task.lite_export(
                      model=local_task.model,
                      export_path=export_config.export_lite_path,
                      export_config=export_config,
                  )
  
imports: import gzip
  import json
  import os
  import sys
  import traceback
  from typing import Any, Dict, get_type_hints, IO, Iterator, List, Optional, Tuple, Union
  import torch
  from pytext.common.constants import Stage
  from pytext.config import ExportConfig, PyTextConfig, TestConfig
  from pytext.config.component import ComponentType, create_component, create_exporter
  from pytext.data.data import Batcher
  from pytext.data.data_handler import CommonMetadata
  from pytext.metric_reporters.channel import Channel
  from pytext.task import create_task, get_latest_checkpoint_path, load, NewTask, save, Task_Deprecated
  from pytext.task.disjoint_multitask import NewDisjointMultitask
  from pytext.trainers import TrainingState
  from pytext.utils import cuda, distributed, precision, round_seq, set_random_seeds, timing
  from pytext.utils.file_io import PathManager
label_desc: Use image node_id 8 for calling a global function with example usage: save_and_export(config, task, metric_channels) without return types