code: def load_torch_model(
      saved_model: Union[torch.nn.Module, Dict],
      model_definition: Optional[torch.nn.Module] = None,
  ) -> torch.nn.Module:
      """Loads a PyTorch model from the provided ``saved_model``.
  
      ``model_definition`` is only used when ``saved_model`` is
      a torch state dict, which will be loaded into ``model_definition``.
      Otherwise, ``model_definition`` is discarded.
      """
      if isinstance(saved_model, torch.nn.Module):
          return saved_model
      elif isinstance(saved_model, dict):
          if not model_definition:
              raise ValueError(
                  "Attempting to load torch model from a "
                  "state_dict, but no `model_definition` was "
                  "provided."
              )
          model_definition.load_state_dict(saved_model)
          return model_definition
      else:
          raise ValueError(
              f"Saved model is of type {type(saved_model)}. "
              f"The model saved in the checkpoint is expected "
              f"to be of type `torch.nn.Module`, or a model "
              f"state dict of type dict."
          )
  
file_path: ray/python/ray/air/_internal/torch_utils.py
imports: import os
  import warnings
  from typing import Dict, List, Optional, Union, Any
  import numpy
  import pandas
  import torch
  import ray
  from ray.air.util.data_batch_conversion import _unwrap_ndarray_object_type_if_needed
label_desc: Use image node_id 5 for calling a global function with example usage: load_torch_model(saved_model, model_definition) and returns: saved_model, model_definition