code: def query_cgroup_cpu_count() -> float:
      # Query active cpu processor count using cgroup v1 API, based on OpenJDK
      # implementation for `active_processor_count` using cgroup v1:
      # https://github.com/openjdk/jdk/blob/master/src/hotspot/os/linux/cgroupSubsystem_linux.cpp
      # For cgroup v2, see:
      # https://github.com/openjdk/jdk/blob/master/src/hotspot/os/linux/cgroupV2Subsystem_linux.cpp
      # Possible supports: cpuset.cpus on kubernetes
      def _read_cgroup_file(filename: str) -> float:
          with open(filename, "r", encoding="utf-8") as f:
              return int(f.read().strip())
  
      cgroup_root = "/sys/fs/cgroup/"
      cfs_quota_us_file = os.path.join(
          cgroup_root, "cpu", "cpu.cfs_quota_us"
      )
      cfs_period_us_file = os.path.join(
          cgroup_root, "cpu", "cpu.cfs_period_us"
      )
      cpu_max_file = os.path.join(cgroup_root, "cpu.max")
  
      quota = None
  
      if os.path.exists(cfs_quota_us_file) and os.path.exists(
          cfs_period_us_file
      ):
          try:
              quota = _read_cgroup_file(
                  cfs_quota_us_file
              ) / _read_cgroup_file(cfs_period_us_file)
          except FileNotFoundError as err:
              logger.warning(
                  "Caught exception while calculating CPU quota: %s",
                  err,
              )
      # reading from cpu.max for cgroup v2
      elif os.path.exists(cpu_max_file):
          try:
              with open(
                  cpu_max_file, "r", encoding="utf-8"
              ) as max_file:
                  cfs_string = max_file.read()
                  quota_str, period_str = cfs_string.split()
                  if quota_str.isnumeric() and period_str.isnumeric():
                      quota = float(quota_str) / float(period_str)
                  else:
                      # quota_str is "max" meaning the cpu quota is unset
                      quota = None
          except FileNotFoundError as err:
              logger.warning(
                  "Caught exception while calculating CPU quota: %s",
                  err,
              )
      if quota is not None and quota < 0:
          quota = None
      elif quota == 0:
          quota = 1
  
      os_cpu_count = float(os.cpu_count() or 1.0)
  
      limit_count = math.inf
  
      if quota:
          limit_count = quota
  
      return float(min(limit_count, os_cpu_count))
  
imports: from __future__ import annotations
  import functools
  import logging
  import math
  import os
  import re
  import typing
  from abc import ABC
  from abc import abstractmethod
  import psutil
  from ..exceptions import BentoMLConfigException
label_desc: Use image node_id 3 for calling a global function with example usage: query_cgroup_cpu_count() and returns: float, int