New PERSISTENT_CACHE (#16373)
Signed-off-by: UltralyticsAssistant <web@ultralytics.com> Co-authored-by: UltralyticsAssistant <web@ultralytics.com>
This commit is contained in:
parent
5024bcac9d
commit
641d09164c
3 changed files with 72 additions and 6 deletions
|
|
@ -110,13 +110,17 @@ def autocast(enabled: bool, device: str = "cuda"):
|
|||
|
||||
def get_cpu_info():
|
||||
"""Return a string with system CPU information, i.e. 'Apple M2'."""
|
||||
with contextlib.suppress(Exception):
|
||||
import cpuinfo # pip install py-cpuinfo
|
||||
from ultralytics.utils import PERSISTENT_CACHE # avoid circular import error
|
||||
|
||||
k = "brand_raw", "hardware_raw", "arch_string_raw" # keys sorted by preference (not all keys always available)
|
||||
info = cpuinfo.get_cpu_info() # info dict
|
||||
string = info.get(k[0] if k[0] in info else k[1] if k[1] in info else k[2], "unknown")
|
||||
return string.replace("(R)", "").replace("CPU ", "").replace("@ ", "")
|
||||
if "cpu_info" not in PERSISTENT_CACHE:
|
||||
with contextlib.suppress(Exception):
|
||||
import cpuinfo # pip install py-cpuinfo
|
||||
|
||||
k = "brand_raw", "hardware_raw", "arch_string_raw" # keys sorted by preference
|
||||
info = cpuinfo.get_cpu_info() # info dict
|
||||
string = info.get(k[0] if k[0] in info else k[1] if k[1] in info else k[2], "unknown")
|
||||
PERSISTENT_CACHE["cpu_info"] = string.replace("(R)", "").replace("CPU ", "").replace("@ ", "")
|
||||
return PERSISTENT_CACHE.get("cpu_info", "unknown")
|
||||
|
||||
return "unknown"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue