Upload edit\Qwen3-TTS-test\.venv\Lib\site-packages\torch\mtia\memory.py with huggingface_hub
Browse files
edit//Qwen3-TTS-test//.venv//Lib//site-packages//torch//mtia//memory.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# pyre-strict
|
| 2 |
+
|
| 3 |
+
r"""This package adds support for device memory management implemented in MTIA."""
|
| 4 |
+
|
| 5 |
+
from typing import Any, Dict, Optional
|
| 6 |
+
|
| 7 |
+
import torch
|
| 8 |
+
|
| 9 |
+
from . import _device_t, is_initialized
|
| 10 |
+
from ._utils import _get_device_index
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def memory_stats(device: Optional[_device_t] = None) -> Dict[str, Any]:
|
| 14 |
+
r"""Return a dictionary of MTIA memory allocator statistics for a given device.
|
| 15 |
+
|
| 16 |
+
Args:
|
| 17 |
+
device (torch.device, str, or int, optional) selected device. Returns
|
| 18 |
+
statistics for the current device, given by current_device(),
|
| 19 |
+
if device is None (default).
|
| 20 |
+
"""
|
| 21 |
+
if not is_initialized():
|
| 22 |
+
return {}
|
| 23 |
+
return torch._C._mtia_memoryStats(_get_device_index(device, optional=True))
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def max_memory_allocated(device: Optional[_device_t] = None) -> int:
|
| 27 |
+
r"""Return the maximum memory allocated in bytes for a given device.
|
| 28 |
+
|
| 29 |
+
Args:
|
| 30 |
+
device (torch.device or int, optional): selected device. Returns
|
| 31 |
+
statistic for the current device, given by :func:`~torch.mtia.current_device`,
|
| 32 |
+
if :attr:`device` is ``None`` (default).
|
| 33 |
+
"""
|
| 34 |
+
|
| 35 |
+
return memory_stats(device=device).get("allocated_bytes.all.peak", 0)
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
__all__ = [
|
| 39 |
+
"memory_stats",
|
| 40 |
+
"max_memory_allocated",
|
| 41 |
+
]
|