code: def torchscript_export(
      context, export_json, model, output_path, quantize, target
  ):
      """Convert a pytext model snapshot to a torchscript model."""
      export_cfg = ExportConfig()
      # only populate from export_json if no export option is configured from the command line.
      if export_json:
          export_json_config = _load_and_validate_export_json_config(
              export_json
          )
  
          read_chunk_size = export_json_config.pop(
              "read_chunk_size", None
          )
          if read_chunk_size is not None:
              print("Warning: Ignoring read_chunk_size.")
  
          if (
              export_json_config.get("read_chunk_size", None)
              is not None
          ):
              print(
                  "Error: Do not know what to do with read_chunk_size.  Ignoring."
              )
  
          if "export" in export_json_config.keys():
              export_cfgs = [export_json_config["export"]]
          else:
              export_cfgs = export_json_config["export_list"]
  
          if target:
              print(
                  "A single export was specified in the command line. Filtering out all other export options"
              )
              export_cfgs = [
                  cfg for cfg in export_cfgs if cfg["target"] == target
              ]
              if export_cfgs == []:
                  print(
                      "No ExportConfig matches the target name specified in the command line."
                  )
  
          for partial_export_cfg in export_cfgs:
              if not quantize and not output_path:
                  export_cfg = config_from_json(
                      ExportConfig, partial_export_cfg
                  )
              else:
                  print(
                      "the export-json config is ignored because export options are found the command line"
                  )
                  export_cfg = config_from_json(
                      ExportConfig,
                      partial_export_cfg,
                      ("export_caffe2_path", "export_onnx_path"),
                  )
                  export_cfg.torchscript_quantize = quantize
              # if config has export_torchscript_path, use export_torchscript_path from config, otherwise keep the default from CLI
              if export_cfg.export_torchscript_path is not None:
                  output_path = export_cfg.export_torchscript_path
              if not model or not output_path:
                  config = context.obj.load_config()
                  model = model or config.save_snapshot_path
                  output_path = (
                      output_path
                      or f"{config.save_snapshot_path}.torchscript"
                  )
  
              print(
                  f"Exporting {model} to torchscript file: {output_path}"
              )
              print(export_cfg)
              export_saved_model_to_torchscript(
                  model, output_path, export_cfg
              )
  
imports: import json
  import pprint
  import sys
  import tempfile
  from importlib import import_module
  from pydoc import locate
  from typing import Dict, List, Optional, Union
  import click
  import torch
  from pytext import create_predictor
  from pytext.builtin_task import add_include
  from pytext.common.utils import eprint
  from pytext.config import ExportConfig, LATEST_VERSION, PyTextConfig
  from pytext.config.component import register_tasks
  from pytext.config.config_adapter import upgrade_to_latest
  from pytext.config.serialize import config_from_json, config_to_json, parse_config, pytext_config_from_json
  from pytext.config.utils import find_param, replace_param
  from pytext.data.data_handler import CommonMetadata
  from pytext.metric_reporters.channel import Channel, TensorBoardChannel
  from pytext.PreprocessingMap.ttypes import ModelType
  from pytext.task import load
  from pytext.utils.documentation import find_config_class, get_subclasses, pretty_print_config_class, replace_components, ROOT_CONFIG
  from pytext.utils.file_io import PathManager
  from pytext.workflow import export_saved_model_to_caffe2, export_saved_model_to_torchscript, get_logits, prepare_task_metadata, save_pytext_snapshot, test_model_from_snapshot_path, train_model
  from torch.multiprocessing.spawn import spawn
label_desc: Use image node_id 14 for calling a global function with example usage: torchscript_export(context, export_json, model, output_path, quantize, target) without return types