code: def merge_metadata(
      all_metadata: List[Dict[str, Any]]
  ) -> Tuple[Dict[str, Any], Dict[str, List[int]]]:
      """
      Given a list of metadata, return:
        - merged metadata
        - a dict mapping conflicting keys to ranks that would upload them
  
      Merging scenarios:
        - merge dictionaries under the same key
        - report conflicts for any repeated key that is not a dictionary
  
      Examples:
      #  Metadata 1     | Metadata 2       | Conflict |  Result
      # ----------------|------------------|----------|-----------------
      #  a: 1           | b: 2             | no       | {a: 1, b: 2}
      #  a: 1           | a: 1             | no       | {a: 1}
      #  a: [1]         | a: [2]           | yes      | n/a
      #  a: [1]         | a: [1]           | no       | {a: [1]}
      #  a: []          | a: 1             | yes      | n/a
      #  a: []          | a: {c: 1}        | yes      | n/a
      #  a: {c: 1}      | a: {d: 1}        | no       | a: {c: 1, d: 1}
      #  a: {c: 1}      | a: 1             | yes      | n/a
      """
  
      # Stores merged metadata.
      merged: Dict[str, Any] = {}
  
      # Maps keys to reporting ranks. It has the same structure as merged with each key
      # having a list of ranks that reports it. Helps to detect conflicts.
      key_ranks: Dict[str, Any] = {}
  
      # Maps fullpath keys (from root) to the list of rank reporting it.
      key_conflicts: Dict[str, List[int]] = {}
  
      for rank, rank_metadata in enumerate(all_metadata):
          merged, key_ranks = _merge_metadata(
              merged, rank_metadata, rank, key_ranks, key_conflicts, ""
          )
  
      return merged, key_conflicts
  
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 2 for calling a global function with example usage: merge_metadata(all_metadata) and returns: merged,  key_conflicts