class_docstr: Base container for PyTorch models.
class_docstr_tok: ["Base","container","for","PyTorch","models","."]
docstr: Method used to save the container for future use.
  
  Args:
      location: The location on the file system where to save the model.
docstr_tok: ["Method","used","to","save","the","container","for","future","use",".","Args",":","location",":","The","location","on","the","file","system","where","to","save","the","model","."]
code: def save(self, location):
      """
      Method used to save the container for future use.
  
      Args:
          location: The location on the file system where to save the model.
      """
      assert self.model is not None, "Saving a None model is undefined."
      import hmac
      import hashlib
  
      if constants.TEST_INPUT in self._extra_config:
          self._extra_config[constants.TEST_INPUT] = None
  
      if location.endswith("zip"):
          location = location[:-4]
      assert not os.path.exists(
          location
      ), "Directory {} already exists.".format(location)
      os.makedirs(location)
  
      if "torch.jit" in str(type(self.model)):
          # This is a torchscript model.
          # Save the model type.
          with open(
              os.path.join(
                  location, constants.SAVE_LOAD_MODEL_TYPE_PATH
              ),
              "w",
          ) as file:
              file.write("torch.jit")
  
          # Save the actual model.
          digest = self.model.save(
              os.path.join(location, constants.SAVE_LOAD_TORCH_JIT_PATH)
          )
  
          model = self.model
          self._model = None
  
          # Save the container.
          with open(
              os.path.join(location, "container.pkl"), "wb"
          ) as file:
              pickle.dump(self, file)
  
          self._model = model
      elif "Executor" in str(type(self.model)):
          # This is a pytorch model.
          # Save the model type.
          with open(
              os.path.join(
                  location, constants.SAVE_LOAD_MODEL_TYPE_PATH
              ),
              "w",
          ) as file:
              file.write("torch")
  
          # Save the actual model plus the container
          with open(
              os.path.join(
                  location, constants.SAVE_LOAD_TORCH_JIT_PATH
              ),
              "wb",
          ) as file:
              pickle.dump(self, file)
      else:
          shutil.rmtree(location)
          raise RuntimeError(
              "Model type {} not recognized.".format(type(self.model))
          )
  
      # Save the module versions.
      versions = dump_versions(hummingbird, torch)
      with open(
          os.path.join(
              location, constants.SAVE_LOAD_MODEL_CONFIGURATION_PATH
          ),
          "w",
      ) as file:
          file.writelines(versions)
  
      # Zip the dir.
      shutil.make_archive(location, "zip", location)
  
      with open(location + ".zip", "rb") as file:
          digest = hmac.new(
              b"shared-key", file.read(), hashlib.sha1
          ).hexdigest()
          print("Model saved with digest: {}".format(digest))
  
      # Remove the directory.
      shutil.rmtree(location)
  
      return digest
  
imports: import pickle
  import os
  import numpy
  import shutil
  import torch
  import warnings
  import hummingbird
  from hummingbird.ml._utils import pandas_installed, get_device, from_strings_to_ints, dump_versions, check_dumped_versions
  from hummingbird.ml.operator_converters import constants
  from hummingbird.ml.containers._sklearn_api_containers import SklearnContainer, SklearnContainerTransformer, SklearnContainerRegression, SklearnContainerClassification, SklearnContainerAnomalyDetection
label_desc: Use image node_id 1 for calling the PyTorchSklearnContainer obj's underlying member method code with example usage: obj.save(location) and returns: digest