code: def hash_checkpoint(
      checkpoint_path: Union[str, Path], output_dir: Union[str, Path]
  ) -> Tuple[Path, str]:
      """
      Hash the checkpoint file in the format of ``<filename>-<hash>.<ext>``
      to be used with ``check_hash`` of :func:`torch.hub.load_state_dict_from_url`.
  
      Args:
          checkpoint_path: Path to the checkpoint file.
          output_dir: Output directory to store the hashed checkpoint file
              (will be created if not exist).
  
      Returns:
          Path to the hashed checkpoint file, the first 8 digits of SHA256 hash.
  
      .. versionadded:: 0.4.8
      """
  
      if isinstance(checkpoint_path, str):
          checkpoint_path = Path(checkpoint_path)
  
      if not checkpoint_path.exists():
          raise FileNotFoundError(
              f"{checkpoint_path.name} does not exist in {checkpoint_path.parent}."
          )
  
      if isinstance(output_dir, str):
          output_dir = Path(output_dir)
          output_dir.mkdir(parents=True, exist_ok=True)
  
      hash_obj = hashlib.sha256()
      # taken from https://github.com/pytorch/vision/blob/main/references/classification/utils.py
      with checkpoint_path.open("rb") as f:
          # Read and update hash string value in blocks of 4KB
          for byte_block in iter(lambda: f.read(4096), b""):
              hash_obj.update(byte_block)
      sha_hash = hash_obj.hexdigest()
  
      old_filename = checkpoint_path.stem
      new_filename = "-".join((old_filename, sha_hash[:8])) + ".pt"
  
      hash_checkpoint_path = output_dir / new_filename
      shutil.move(str(checkpoint_path), hash_checkpoint_path)
  
      return hash_checkpoint_path, sha_hash
  
imports: import collections.abc
  import functools
  import hashlib
  import logging
  import random
  import shutil
  import warnings
  from pathlib import Path
  from typing import Any, Callable, cast, Dict, List, Optional, TextIO, Tuple, Type, TypeVar, Union
  import torch
label_desc: Use image node_id 10 for calling a global function with example usage: hash_checkpoint(checkpoint_path, output_dir) and returns: hash_checkpoint_path,  sha_hash