class_docstr: Google TPU accelerators.
docstr: Attempt to detect the TPU accelerator type.
  
  The output of this function will return the "ray accelerator type"
  resource (e.g. TPU-V4) that indicates the TPU version.
  
  We also expect that our TPU nodes contain a "TPU pod type"
  resource, which indicates information about the topology of
  the TPU pod slice.
  
  We expect that the "TPU pod type" resource to be used when
  running multi host workers, i.e. when TPU units are pod slices.
  
  We expect that the "ray accelerator type" resource to be used when
  running single host workers, i.e. when TPU units are single hosts.
  
  Returns:
      A string representing the TPU accelerator type,
      e.g. "TPU-V2", "TPU-V3", "TPU-V4" if applicable, else None.
docstr_tok: ["Attempt","to","detect","the","TPU","accelerator","type",".","The","output","of","this","function","will","return","the","``","ray","accelerator","type","''","resource","(","e.g",".","TPU-V4",")","that","indicates","the","TPU","version",".","We","also","expect","that","our","TPU","nodes","contain","a","``","TPU","pod","type","''","resource",",","which","indicates","information","about","the","topology","of","the","TPU","pod","slice",".","We","expect","that","the","``","TPU","pod","type","''","resource","to","be","used","when","running","multi","host","workers",",","i.e",".","when","TPU","units","are","pod","slices",".","We","expect","that","the","``","ray","accelerator","type","''","resource","to","be","used","when","running","single","host","workers",",","i.e",".","when","TPU","units","are","single","hosts",".","Returns",":","A","string","representing","the","TPU","accelerator","type",",","e.g",".","``","TPU-V2","''",",","``","TPU-V3","''",",","``","TPU-V4","''","if","applicable",",","else","None","."]
code: def get_current_node_accelerator_type() -> Optional[str]:
      """Attempt to detect the TPU accelerator type.
  
      The output of this function will return the "ray accelerator type"
      resource (e.g. TPU-V4) that indicates the TPU version.
  
      We also expect that our TPU nodes contain a "TPU pod type"
      resource, which indicates information about the topology of
      the TPU pod slice.
  
      We expect that the "TPU pod type" resource to be used when
      running multi host workers, i.e. when TPU units are pod slices.
  
      We expect that the "ray accelerator type" resource to be used when
      running single host workers, i.e. when TPU units are single hosts.
  
      Returns:
          A string representing the TPU accelerator type,
          e.g. "TPU-V2", "TPU-V3", "TPU-V4" if applicable, else None.
  
      """
  
      def tpu_pod_type_to_ray_accelerator_type(
          tpu_pod_type: str,
      ) -> Optional[str]:
          return "TPU-" + str(tpu_pod_type.split("-")[0].upper())
  
      ray_accelerator_type = None
      tpu_pod_type = (
          TPUAcceleratorManager._get_current_node_tpu_pod_type()
      )
  
      if tpu_pod_type is not None:
          ray_accelerator_type = tpu_pod_type_to_ray_accelerator_type(
              tpu_pod_type=tpu_pod_type
          )
          if ray_accelerator_type is None:
              logger.info(
                  "While trying to autodetect a TPU type, "
                  f"received malformed accelerator_type: {tpu_pod_type}"
              )
  
      if ray_accelerator_type is None:
          logging.info("Failed to auto-detect TPU type.")
  
      return ray_accelerator_type
  
imports: import os
  import re
  import glob
  import requests
  import logging
  from typing import Dict, Optional, List, Tuple
  from ray._private.accelerators.accelerator import AcceleratorManager
label_desc: Use image node_id 12 for calling the TPUAcceleratorManager obj's underlying member method code with example usage: obj.get_current_node_accelerator_type() and returns: ray_accelerator_type, unknown