docstr: Sort the values of each key according to the indices.
  This is to make sure that prediction results follow the order of input samples.
  
  Parameters
  ----------
  x
      A dictionary with all the predictions.
  indices
      A list of indices.
docstr_tok: ["Sort","the","values","of","each","key","according","to","the","indices",".","This","is","to","make","sure","that","prediction","results","follow","the","order","of","input","samples",".","Parameters","--","--","--","--","--","x","A","dictionary","with","all","the","predictions",".","indices","A","list","of","indices","."]
code: def sort(self, x: Dict, indices: List):
      """
      Sort the values of each key according to the indices.
      This is to make sure that prediction results follow the order of input samples.
  
      Parameters
      ----------
      x
          A dictionary with all the predictions.
      indices
          A list of indices.
      """
      if (
          isinstance(x, list) and BBOX in x[0]
      ):  # for detection outputs just sort the batches
          return [
              xi
              for _, xi in sorted(
                  zip(indices, x), key=lambda ele: ele[0]
              )
          ]
  
      results = dict()
      for k, v in x.items():
          if isinstance(v, dict):
              results[k] = self.sort(v, indices)
          else:
              assert len(indices) == len(
                  v
              ), f"Size mismatch, {k}: {v} of len {len(v)} and indices {indices} of length {len(indices)}"
              results[k] = [
                  x
                  for _, x in sorted(
                      zip(indices, v), key=lambda ele: ele[0]
                  )
              ]
              results[k] = torch.stack(results[k])
  
      return results
  
imports: import logging
  import os
  import shutil
  import time
  import uuid
  from pathlib import Path
  from typing import Any, Dict, List, Optional, Sequence
  import lightning.pytorch
  import torch
  from lightning.pytorch.callbacks import BasePredictionWriter
  from ..constants import BBOX, LM_TARGET, LOGIT_SCALE, LOGITS, TEMPLATE_LOGITS, WEIGHT
label_desc: Use image node_id 8 for calling the DDPPredictionWriter obj's underlying member method code with example usage: obj.sort(x, indices) and returns: results, unknown