code: def store_model_weights(
      model, checkpoint_path, checkpoint_key="model", strict=True
  ):
      """
      This method can be used to prepare weights files for new models. It receives as
      input a model architecture and a checkpoint from the training script and produces
      a file with the weights ready for release.
  
      Examples:
          from torchvision import models as M
  
          # Classification
          model = M.mobilenet_v3_large(weights=None)
          print(store_model_weights(model, './class.pth'))
  
          # Quantized Classification
          model = M.quantization.mobilenet_v3_large(weights=None, quantize=False)
          model.fuse_model(is_qat=True)
          model.qconfig = torch.ao.quantization.get_default_qat_qconfig('qnnpack')
          _ = torch.ao.quantization.prepare_qat(model, inplace=True)
          print(store_model_weights(model, './qat.pth'))
  
          # Object Detection
          model = M.detection.fasterrcnn_mobilenet_v3_large_fpn(weights=None, weights_backbone=None)
          print(store_model_weights(model, './obj.pth'))
  
          # Segmentation
          model = M.segmentation.deeplabv3_mobilenet_v3_large(weights=None, weights_backbone=None, aux_loss=True)
          print(store_model_weights(model, './segm.pth', strict=False))
  
      Args:
          model (pytorch.nn.Module): The model on which the weights will be loaded for validation purposes.
          checkpoint_path (str): The path of the checkpoint we will load.
          checkpoint_key (str, optional): The key of the checkpoint where the model weights are stored.
              Default: "model".
          strict (bool): whether to strictly enforce that the keys
              in :attr:`state_dict` match the keys returned by this module's
              :meth:`~torch.nn.Module.state_dict` function. Default: ``True``
  
      Returns:
          output_path (str): The location where the weights are saved.
      """
      # Store the new model next to the checkpoint_path
      checkpoint_path = os.path.abspath(checkpoint_path)
      output_dir = os.path.dirname(checkpoint_path)
  
      # Deep copy to avoid side effects on the model object.
      model = copy.deepcopy(model)
      checkpoint = torch.load(
          checkpoint_path, map_location="cpu", weights_only=True
      )
  
      # Load the weights to the model to validate that everything works
      # and remove unnecessary weights (such as auxiliaries, etc.)
      if checkpoint_key == "model_ema":
          del checkpoint[checkpoint_key]["n_averaged"]
          torch.nn.modules.utils.consume_prefix_in_state_dict_if_present(
              checkpoint[checkpoint_key], "module."
          )
      model.load_state_dict(checkpoint[checkpoint_key], strict=strict)
  
      tmp_path = os.path.join(output_dir, str(model.__hash__()))
      torch.save(model.state_dict(), tmp_path)
  
      sha256_hash = hashlib.sha256()
      with open(tmp_path, "rb") as f:
          # Read and update hash string value in blocks of 4K
          for byte_block in iter(lambda: f.read(4096), b""):
              sha256_hash.update(byte_block)
          hh = sha256_hash.hexdigest()
  
      output_path = os.path.join(
          output_dir, "weights-" + str(hh[:8]) + ".pth"
      )
      os.replace(tmp_path, output_path)
  
      return output_path
  
imports: import copy
  import datetime
  import errno
  import hashlib
  import os
  import time
  from collections import defaultdict, deque, OrderedDict
  from typing import List, Optional, Tuple
  import torch
  import torch.distributed
label_desc: Use image node_id 11 for calling a global function with example usage: store_model_weights(model, checkpoint_path, checkpoint_key, strict) and returns: output_path