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","."]
code: def _resolve_conflicts(
      self,
      resources: Dict[str, int],
      conflicts: Dict[str, List[int]],
      ckpt_dir: Optional[str],
  ) -> Dict[str, int]:
      all_conflicts = conflicts.copy()
  
      # Make sure each rank processes files in the same order.
      for fname in sorted(conflicts):
          ranks = conflicts[fname]
          if self._dist.rank in ranks:
              assert ckpt_dir
              fpath = os.path.join(ckpt_dir, fname)
              if os.path.isdir(fpath):
                  # If rankA uploads a directory and rankB uploads a file with the same name,
                  # there is an unresolvable conflict. Emit a non-md5sum, non-None object
                  # to guarantee the fname is kept in the all_conflicts list.
                  md5 = "this is a directory"
              else:
                  with open(fpath, "rb") as f:
                      md5 = hashlib.md5(f.read()).hexdigest()
              md5_ranks = self._dist.allgather(md5)
          else:
              md5_ranks = self._dist.allgather(None)
  
          md5_ranks_filtered = {x for x in md5_ranks if x is not None}
  
          if len(md5_ranks_filtered) == 1:
              # All files have the same md5 checksum, which means there is no conflict.
              all_conflicts.pop(fname)
  
      if len(all_conflicts) > 0:
          self._raise_conflict_error(all_conflicts, "files")
  
      # There may still be multiple ranks having the same version of the file.
      # To avoid uploading the same file multiple times, we use the smallest rank to upload.
      filtered_resources = {
          k: v
          for k, v in resources.items()
          if k not in conflicts or min(conflicts[k]) == self._dist.rank
      }
      return filtered_resources
  
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 5 for calling the CheckpointContext obj's underlying member method code with example usage: obj._resolve_conflicts(resources, conflicts, ckpt_dir) and returns: filtered_resources