code: def extract_tensors(
      model: torch.nn.Module,
  ) -> Tuple[torch.nn.Module, List[Dict]]:
      """Remove the tensors from a PyTorch model, convert them to NumPy arrays, and return the stripped model and
      tensors.
  
      Reference implementation: https://medium.com/ibm-data-ai/how-to-load-pytorch-models-340-times-faster-with-
      ray-8be751a6944c  # noqa
      """
  
      tensors = []
      for _, module in model.named_modules():
          # Store the tensors as numpy arrays in Python dictionaries
          # Delete the same tensors since we no longer need them and we want to reduce memory pressure.
          # This ensures that throughout this process, we keep memory nearly linear w.r.t model parameters.
          params = OrderedDict()
          buffers = OrderedDict()
          for name, param in module.named_parameters(recurse=False):
              params[name] = torch.clone(param).detach().numpy()
              del param
          for name, buf in module.named_buffers(recurse=False):
              buffers[name] = torch.clone(buf).detach().numpy()
              del buf
          tensors.append({"params": params, "buffers": buffers})
  
      # Strip all tensors and buffers out of the original model.
      for _, module in model.named_modules():
          for name in [
              name for name, _ in module.named_parameters(recurse=False)
          ] + [name for name, _ in module.named_buffers(recurse=False)]:
              setattr(module, name, None)
  
      return model, tensors
  
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 1 for calling a global function with example usage: extract_tensors(model) and returns: model,  tensors