code: def replace_tensors(
      m: torch.nn.Module, tensors: List[Dict], device: torch.device
  ):
      """Restore the tensors that extract_tensors() stripped out of a PyTorch model. This operation is performed in
      place.
  
      Reference implementation: https://medium.com/ibm-data-ai/how-to-load-pytorch-models-340-times-faster-with-
      ray-8be751a6944c  # noqa
      """
      modules = [module for _, module in m.named_modules()]
      for module, tensor_dict in zip(modules, tensors):
          # There are separate APIs to set parameters and buffers.
          for name, array in tensor_dict["params"].items():
              module.register_parameter(
                  name,
                  torch.nn.Parameter(
                      torch.as_tensor(
                          array,
                          device=device,
                          dtype=NUMPY_TO_TORCH_DTYPE.get(array.dtype),
                      )
                  ),
              )
  
          for name, array in tensor_dict["buffers"].items():
              module.register_buffer(
                  name,
                  torch.as_tensor(
                      array,
                      device=device,
                      dtype=NUMPY_TO_TORCH_DTYPE.get(array.dtype),
                  ),
              )
  
file_path: ludwig/ludwig/utils/model_utils.py
imports: import logging
  from collections import OrderedDict
  from typing import Dict, List, Tuple
  import numpy
  import torch
label_desc: Use image node_id 2 for calling a global function with example usage: replace_tensors(m, tensors, device) without return types