@@ -525,19 +525,6 @@ def __init__(self, device_index: int, interval: float = 0.05):
525525 self ._stop_event = threading .Event ()
526526 self ._thread : threading .Thread | None = None
527527
528- def start (self ) -> None :
529- def monitor_loop () -> None :
530- while not self ._stop_event .is_set ():
531- try :
532- with torch .cuda .device (self .device_index ):
533- free_bytes , total_bytes = torch .cuda .mem_get_info ()
534- used_mb = (total_bytes - free_bytes ) / (1024 ** 2 )
535- self ._peak_used_mb = max (self ._peak_used_mb , used_mb )
536- except Exception :
537- pass
538- time .sleep (self .interval )
539-
540- self ._thread = threading .Thread (target = monitor_loop , daemon = False )
541528 def start (self ) -> None :
542529 def monitor_loop () -> None :
543530 while not self ._stop_event .is_set ():
@@ -570,21 +557,6 @@ def __del__(self):
570557
571558
572559class NPUMemoryMonitor (DeviceMemoryMonitor ):
573- def start (self ) -> None :
574- def monitor_loop () -> None :
575- while not self ._stop_event .is_set ():
576- try :
577- with torch .npu .device (self .device_index ):
578- free_bytes , total_bytes = torch .npu .mem_get_info ()
579- used_mb = (total_bytes - free_bytes ) / (1024 ** 2 )
580- self ._peak_used_mb = max (self ._peak_used_mb , used_mb )
581- except Exception :
582- pass
583- time .sleep (self .interval )
584-
585- self ._thread = threading .Thread (target = monitor_loop , daemon = False )
586- self ._thread .start ()
587-
588560 @property
589561 def peak_used_mb (self ) -> float :
590562 fallback_alloc = torch .npu .max_memory_allocated (device = self .device_index ) / (1024 ** 2 )
@@ -593,21 +565,6 @@ def peak_used_mb(self) -> float:
593565
594566
595567class XPUMemoryMonitor (DeviceMemoryMonitor ):
596- def start (self ) -> None :
597- def monitor_loop () -> None :
598- while not self ._stop_event .is_set ():
599- try :
600- with torch .xpu .device (self .device_index ):
601- free_bytes , total_bytes = torch .xpu .mem_get_info ()
602- used_mb = (total_bytes - free_bytes ) / (1024 ** 2 )
603- self ._peak_used_mb = max (self ._peak_used_mb , used_mb )
604- except Exception :
605- pass
606- time .sleep (self .interval )
607-
608- self ._thread = threading .Thread (target = monitor_loop , daemon = False )
609- self ._thread .start ()
610-
611568 @property
612569 def peak_used_mb (self ) -> float :
613570 fallback_alloc = torch .xpu .max_memory_allocated (device = self .device_index ) / (1024 ** 2 )
0 commit comments