class_docstr: ``CheckpointContext`` gives access to checkpoint-related features of a Determined cluster.
class_docstr_tok: ["``","CheckpointContext","``","gives","access","to","checkpoint-related","features","of","a","Determined","cluster","."]
docstr: ``restore_path()`` is a context manager which downloads a checkpoint (if required by the
  storage backend) and cleans up the temporary files afterwards (if applicable).
  
  In multi-worker scenarios, with the default ``download_mode``
  (``LocalWorkersShareDownload``), all workers must call ``restore_path()`` but only the local
  chief worker on each node (``distributed.local_rank==0``) actually downloads data.
  
  Example:
  
  .. code::
  
     with core_context.checkpoint.restore_path(my_checkpoint_uuid) as path:
         my_model = my_load_model(path)
docstr_tok: ["``","restore_path","(",")","``","is","a","context","manager","which","downloads","a","checkpoint","(","if","required","by","the","storage","backend",")","and","cleans","up","the","temporary","files","afterwards","(","if","applicable",")",".","In","multi-worker","scenarios",",","with","the","default","``","download_mode","``","(","``","LocalWorkersShareDownload","``",")",",","all","workers","must","call","``","restore_path","(",")","``","but","only","the","local","chief","worker","on","each","node","(","``","distributed.local_rank==0","``",")","actually","downloads","data",".","Example",":","..","code",":",":","with","core_context.checkpoint.restore_path","(","my_checkpoint_uuid",")","as","path",":","my_model","=","my_load_model","(","path",")"]
code: def restore_path(
      self,
      storage_id: str,
      download_mode: DownloadMode = DownloadMode.LocalWorkersShareDownload,
      *,
      selector: Optional[Callable[[str], bool]] = None,
  ) -> Iterator[pathlib.Path]:
      """
      ``restore_path()`` is a context manager which downloads a checkpoint (if required by the
      storage backend) and cleans up the temporary files afterwards (if applicable).
  
      In multi-worker scenarios, with the default ``download_mode``
      (``LocalWorkersShareDownload``), all workers must call ``restore_path()`` but only the local
      chief worker on each node (``distributed.local_rank==0``) actually downloads data.
  
      Example:
  
      .. code::
  
         with core_context.checkpoint.restore_path(my_checkpoint_uuid) as path:
             my_model = my_load_model(path)
      """
      download_mode = DownloadMode(download_mode)
  
      if download_mode == DownloadMode.NoSharedDownload:
          with self._storage_manager.restore_path(
              storage_id, selector=selector
          ) as path:
              yield path
          return
  
      want_filter = any(self._dist.allgather(selector is not None))
  
      # LocalWorkersShareDownload case.
      if self._dist.local_rank == 0:
  
          def _selector(path: str) -> bool:
              if not want_filter:
                  return True
              # If anyone has a selector, coordinate every filename across workers' filters.
              # Functions can't be reliably serialized, so instead we pass each filename between
              # all workers. But because this traffic is local (unix sockets by default) it
              # should be far faster than any download.
              _ = self._dist.broadcast_local(path)
              # If selector is None return True => all files will be downloaded.
              upload_path = self._dist.gather_local(
                  selector(path) if selector is not None else True
              )
              # Upload_path is not None when we are on the local chief.
              assert upload_path
              return any(upload_path)
  
          with self._storage_manager.restore_path(
              storage_id, _selector
          ) as path:
              # Tell local workers that download is finished.
              _ = self._dist.broadcast_local(None)
              # Broadcast to local workers.
              _ = self._dist.broadcast_local(path)
              try:
                  yield path
              finally:
                  # Wait for local workers to finish.
                  _ = self._dist.gather_local(None)
      else:
          while True:
              name = self._dist.broadcast_local(None)
              if name is None:
                  # Chief is done downloading files.
                  break
              assert (
                  want_filter
              ), "want_filter is not set but name was not None"
              _ = self._dist.gather_local(
                  selector(name) if selector is not None else True
              )
  
          # Wait for local chief to broadcast.
          path = self._dist.broadcast_local(None)
          try:
              yield path
          finally:
              # Tell local chief we're done.
              _ = self._dist.gather_local(None)
  
imports: import contextlib
  import datetime
  import enum
  import hashlib
  import json
  import logging
  import os
  import pathlib
  import uuid
  from typing import Any, Callable, Dict, Iterator, List, Optional, Set, Tuple, Union
  from determined import core, tensorboard
  from determined.common import api, storage
  from determined.common.api import bindings
label_desc: Use image node_id 13 for calling the CheckpointContext obj's underlying member method code with example usage: obj.restore_path(storage_id, download_mode) and returns: any, True