code: def _get_rank_aware_path_pytorch_profiler(
      path: pathlib.Path, pytorch_profiler_extension: str, rank: int
  ) -> pathlib.Path:
      path_parts = path.parts
      file_name = path_parts[-1]
      match = pytorch_profiler_file_pattern.match(file_name)
  
      if match:
          match_groups = match.groups()
  
          worker = match_groups[0]
          worker = f"{worker}#{rank}"
  
          span = match_groups[1]
  
          if span:
              file_name = f"{worker}{span}{pytorch_profiler_extension}"
          else:
              file_name = f"{worker}{pytorch_profiler_extension}"
  
          if len(path_parts) == 1:
              # only file name is passed in
              return pathlib.Path(file_name)
          else:
              # path with directory is passed in
              output_path = pathlib.Path(path_parts[0])
              for i in range(1, len(path_parts) - 1):
                  output_path = output_path.joinpath(path_parts[i])
              output_path = output_path.joinpath(file_name)
              return output_path
      else:
          raise Exception(
              (
                  f"Path: {path} has pytorch profiler extension {pytorch_profiler_extension}",
                  "but no matching file pattern",
              )
          )
  
file_path: determined/harness/determined/tensorboard/util.py
imports: import logging
  import pathlib
  import re
  from typing import List, Optional
label_desc: Use image node_id 3 for calling a global function with example usage: _get_rank_aware_path_pytorch_profiler(path, pytorch_profiler_extension, rank) and returns: pathlib, output_path