code: def test_api_save_torchscript(tmpdir):
      """Tests successful saving and loading of model in TorchScript format."""
      input_features = [category_feature(encoder={"vocab_size": 5})]
      output_features = [
          category_feature(
              name="class",
              decoder={"vocab_size": 5},
              reduce_input="sum",
              output_feature=True,
          )
      ]
  
      data_csv = generate_data(
          input_features,
          output_features,
          os.path.join(tmpdir, "dataset.csv"),
      )
      val_csv = shutil.copyfile(
          data_csv, os.path.join(tmpdir, "validation.csv")
      )
      test_csv = shutil.copyfile(
          data_csv, os.path.join(tmpdir, "test.csv")
      )
  
      config = {
          "input_features": input_features,
          "output_features": output_features,
          "combiner": {"type": "concat", "output_size": 14},
      }
      model = LudwigModel(config)
      model.train(
          training_set=data_csv,
          validation_set=val_csv,
          test_set=test_csv,
          output_directory=tmpdir,
      )
  
      test_df = pd.read_csv(test_csv)
      output_df_expected, _ = model.predict(
          test_df, return_type=pd.DataFrame
      )
  
      save_path = os.path.join(tmpdir, "torchscript")
      os.makedirs(save_path, exist_ok=True)
      model.save_torchscript(save_path)
      inference_module = InferenceModule.from_directory(save_path)
      output_df, _ = inference_module.predict(
          test_df, return_type=pd.DataFrame
      )
  
      for col in output_df.columns:
          assert output_df[col].equals(output_df_expected[col])
  
imports: import json
  import os
  import shutil
  from unittest import mock
  import pandas
  import pytest
  import torch
  import yaml
  from ludwig.api import LudwigModel
  from ludwig.callbacks import Callback
  from ludwig.constants import BATCH_SIZE, ENCODER, TRAINER, TYPE
  from ludwig.globals import MODEL_HYPERPARAMETERS_FILE_NAME
  from ludwig.models.inference import InferenceModule
  from ludwig.utils.data_utils import read_csv
  from tests.integration_tests.utils import category_feature, ENCODERS, generate_data, get_weights, image_feature, run_api_experiment, sequence_feature, text_feature
label_desc: Use image node_id 18 for calling a global function with example usage: test_api_save_torchscript(tmpdir) without return types