[Misc] Make mem utils can be reused by other platforms (#32322)

Signed-off-by: shen-shanshan <467638484@qq.com>
This commit is contained in:
Shanshan Shen
2026-01-14 03:46:01 -08:00
committed by GitHub
parent 3f28174c6a
commit ce0946249d
3 changed files with 21 additions and 25 deletions
+12 -8
View File
@@ -589,14 +589,18 @@ class Platform:
def __getattr__(self, key: str):
device = getattr(torch, self.device_type, None)
if device is not None and hasattr(device, key):
return getattr(device, key)
else:
logger.warning(
"Current platform %s does not have '%s' attribute.",
self.device_type,
key,
)
return None
attr = getattr(device, key)
# NOTE: `hasattr(device, key)=True` can only avoid AttributeError,
# but the value of this attr could be `None`.
if attr is not None:
return attr
logger.warning(
"Current platform %s does not have '%s' attribute.",
self.device_type,
key,
)
return None
def get_global_graph_pool(self) -> Any:
"""