[refactor] refactor memory constants usage (#31865)

Signed-off-by: Andy Xie <andy.xning@gmail.com>
This commit is contained in:
Ning Xie
2026-01-08 02:37:31 +08:00
committed by GitHub
parent f347ac6c34
commit c907d22158
9 changed files with 33 additions and 30 deletions

View File

@@ -11,11 +11,15 @@ import psutil
import torch
import torch.types
from .mem_constants import GiB_bytes
from .mem_constants import GiB_bytes, MiB_bytes
def format_gib(b: int) -> float:
return round(b / GiB_bytes, 2)
def format_mib(b: int) -> str:
return f"{round(b / MiB_bytes, 2)}"
def format_gib(b: int) -> str:
return f"{round(b / GiB_bytes, 2)}"
@cache