[Misc] Make mem utils can be reused by other platforms (#32322)
Signed-off-by: shen-shanshan <467638484@qq.com>
This commit is contained in:
@@ -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:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user