+
    –°³ji/  ã                   óò   € ^ RI Ht ^ RIHt ^ RIt^RIHtHt . ROtR R lt	R R lt
R	 R
 ltRR R lltRR R lltRR R lltRR R lltRR R lltRR R lltRR R lltRR R lltRR R lltR# ) é    )ÚOrderedDict)ÚAnyN)Ú	_device_tÚ_get_device_indexc                ó   € V ^8„  d   QhRR/# ©é   ÚreturnN© )Úformats   "ÚY/home/luca/screen-checking/.venv/lib/python3.14/site-packages/torch/accelerator/memory.pyÚ__annotate__r      s   € ÷ 	'ñ 	'�Tñ 	'ó    c                 óŽ   € \         P                  P                  4       '       g   R# \         P                  P                  4        R# )a	  Release all unoccupied cached memory currently held by the caching
allocator so that those can be used in other application.

.. note:: This function is a no-op if the memory allocator for the current
    :ref:`accelerator <accelerators>` has not been initialized.
N)ÚtorchÚ_CÚ#_accelerator_isAllocatorInitializedÚ_accelerator_emptyCacher   r   r   Úempty_cacher      s*   € ô �8‰8×7Ñ7×9Ò9ÙÜ	‡H�H×$Ñ$Ö&r   c                ó   € V ^8„  d   QhRR/# r   r   )r   s   "r   r   r   #   s   € ÷ +ñ +˜$ñ +r   c                 óB   € \         P                  P                  4        R# )a  Release all unoccupied cached host (pinned) memory currently held by the host caching
allocator so that it can be used by other applications.

.. note:: This function is a no-op if the memory allocator for the current
    :ref:`accelerator <accelerators>` has not been initialized.
N)r   r   Ú_accelerator_emptyHostCacher   r   r   Úempty_host_cacher   #   s   € ô 
‡H�H×(Ñ(Ö*r   c                óx   € V ^8„  d   QhR\         \        \        \        3,          ,          R\        R\        RR/# )r	   ÚresultÚprefixÚvaluer
   N)ÚlistÚtupleÚstrr   )r   s   "r   r   r   -   s5   € ÷ 'ñ 'œ4¤¤c¬3 h¥Õ0ð '¼#ð 'Äcð 'Èdñ 'r   c                 óÆ   € \        V\        4      '       d9   VP                  4        F"  w  r4V'       d   V R V 2MTp\        WV4       K$  	  R# V P	                  W34       R# )Ú.N)Ú
isinstanceÚdictÚitemsÚ_flatten_statsÚappend)r   r   r   ÚkeyÚnested_valueÚnested_prefixs   &&&   r   r&   r&   -   sP   € Ü�%œ×ÒØ!&§¡¦ÑˆCß17˜v˜h a¨ uÑ-¸SˆMÜ˜6°,Ö?ó "/ð 	�‰�v�oÖ&r   c                óR   € V ^8„  d   QhR\         R\        \        \        3,          /# ©r	   Údevice_indexr
   )r   r   r    r   )r   s   "r   r   r   6   s'   € ÷ F#ñ F#œyð F#´{Ä3ÌÀ8Õ7Lñ F#r   c               ó
  € \         P                  P                  4       '       g   \        4       # \	        V RR7      p \         P                  P                  V 4      p. p\        VRV4       VP                  4        \        V4      # )ar
  Return a dictionary of accelerator device memory allocator statistics for a given device index.

The return value of this function is a dictionary of statistics, each of
which is a non-negative integer.

Core statistics:

- ``"allocated.{all,large_pool,small_pool}.{current,peak,allocated,freed}"``:
  number of allocation requests received by the memory allocator.
- ``"allocated_bytes.{all,large_pool,small_pool}.{current,peak,allocated,freed}"``:
  amount of allocated memory.
- ``"segment.{all,large_pool,small_pool}.{current,peak,allocated,freed}"``:
  number of reserved segments from device memory allocation.
- ``"reserved_bytes.{all,large_pool,small_pool}.{current,peak,allocated,freed}"``:
  amount of reserved memory.
- ``"active.{all,large_pool,small_pool}.{current,peak,allocated,freed}"``:
  number of active memory blocks.
- ``"active_bytes.{all,large_pool,small_pool}.{current,peak,allocated,freed}"``:
  amount of active memory.
- ``"inactive_split.{all,large_pool,small_pool}.{current,peak,allocated,freed}"``:
  number of inactive, non-releasable memory blocks.
- ``"inactive_split_bytes.{all,large_pool,small_pool}.{current,peak,allocated,freed}"``:
  amount of inactive, non-releasable memory.

For these core statistics, values are broken down as follows.

Pool type:

- ``all``: combined statistics across all memory pools.
- ``large_pool``: statistics for the large allocation pool
  (as of June 2025, for size >= 1MB allocations).
- ``small_pool``: statistics for the small allocation pool
  (as of June 2025, for size < 1MB allocations).

Metric type:

- ``current``: current value of this metric.
- ``peak``: maximum value of this metric.
- ``allocated``: historical total increase in this metric.
- ``freed``: historical total decrease in this metric.

In addition to the core statistics, we also provide some simple event
counters:

- ``"num_alloc_retries"``: number of failed device memory allocation calls that
  result in a cache flush and retry.
- ``"num_ooms"``: number of out-of-memory errors thrown.
- ``"num_sync_all_streams"``: number of ``synchronize_and_free_events`` calls.
- ``"num_device_alloc"``: number of device memory allocation calls.
- ``"num_device_free"``: number of device memory free calls.

Args:
    device_index (:class:`torch.device`, str, int, optional): the index of the device to target.
        If not given, use :func:`torch.accelerator.current_device_index` by default.
        If a :class:`torch.device` or str is provided, its type must match the current
        :ref:`accelerator<accelerators>` device type.

Returns:
    OrderedDict[str, Any]: an ordered dictionary mapping statistic names to their values.
T©ÚoptionalÚ )r   r   r   r   r   Ú_accelerator_getDeviceStatsr&   Úsort)r-   ÚstatsÚ
flat_statss   "  r   Úmemory_statsr6   6   sf   € ôz �8‰8×7Ñ7×9Ò9Ü‹}ÐÜ$ \¸DÔA€LÜ�H‰H×0Ñ0°Ó>€EØ€Jä�:˜r 5Ô)Ø‡O�OÔä�zÓ"Ð"r   c                ó0   € V ^8„  d   QhR\         R\        /# r,   ©r   Úint)r   s   "r   r   r      s   € ÷ Lñ L¤9ð L¼3ñ Lr   c               ó8   € \        V 4      P                  R^ 4      # )a)  Return the current :ref:`accelerator<accelerators>` device memory occupied by tensors
in bytes for a given device index.

Args:
    device_index (:class:`torch.device`, str, int, optional): the index of the device to target.
        If not given, use :func:`torch.accelerator.current_device_index` by default.
        If a :class:`torch.device` or str is provided, its type must match the current
        :ref:`accelerator<accelerators>` device type.

Returns:
    int: the current memory occupied by live tensors (in bytes) within the current process.
zallocated_bytes.all.current©r6   Úget©r-   s   "r   Úmemory_allocatedr>      s   € ô ˜Ó%×)Ñ)Ð*GÈÓKÐKr   c                ó0   € V ^8„  d   QhR\         R\        /# r,   r8   )r   s   "r   r   r   �   s   € ÷ Iñ I¤yð I¼sñ Ir   c               ó8   € \        V 4      P                  R^ 4      # )aû  Return the current :ref:`accelerator<accelerators>` maximum device memory occupied by tensors
in bytes for a given device index.

By default, this returns the peak allocated memory since the beginning of
this program. :func:`~torch.accelerator.reset_peak_memory_stats` can be used to
reset the starting point in tracking this metric.

Args:
    device_index (:class:`torch.device`, str, int, optional): the index of the device to target.
        If not given, use :func:`torch.accelerator.current_device_index` by default.
        If a :class:`torch.device` or str is provided, its type must match the current
        :ref:`accelerator<accelerators>` device type.

Returns:
    int: the peak memory occupied by live tensors (in bytes) within the current process.
zallocated_bytes.all.peakr;   r=   s   "r   Úmax_memory_allocatedrA   �   s   € ô" ˜Ó%×)Ñ)Ð*DÀaÓHÐHr   c                ó0   € V ^8„  d   QhR\         R\        /# r,   r8   )r   s   "r   r   r   £   s   € ÷ Kñ K¤)ð K¼#ñ Kr   c               ó8   € \        V 4      P                  R^ 4      # )a1  Return the current :ref:`accelerator<accelerators>` device memory managed by the caching allocator
in bytes for a given device index.

Args:
    device_index (:class:`torch.device`, str, int, optional): the index of the device to target.
        If not given, use :func:`torch.accelerator.current_device_index` by default.
        If a :class:`torch.device` or str is provided, its type must match the current
        :ref:`accelerator<accelerators>` device type.

Returns:
    int: the current memory reserved by PyTorch (in bytes) within the current process.
zreserved_bytes.all.currentr;   r=   s   "r   Úmemory_reservedrD   £   s   € ô ˜Ó%×)Ñ)Ð*FÈÓJÐJr   c                ó0   € V ^8„  d   QhR\         R\        /# r,   r8   )r   s   "r   r   r   ³   s   € ÷ Hñ H¤ið H¼cñ Hr   c               ó8   € \        V 4      P                  R^ 4      # )a   Return the current :ref:`accelerator<accelerators>` maximum device memory managed by the caching allocator
in bytes for a given device index.

By default, this returns the peak cached memory since the beginning of this
program. :func:`~torch.accelerator.reset_peak_memory_stats` can be used to reset
the starting point in tracking this metric.

Args:
    device_index (:class:`torch.device`, str, int, optional): the index of the device to target.
        If not given, use :func:`torch.accelerator.current_device_index` by default.
        If a :class:`torch.device` or str is provided, its type must match the current
        :ref:`accelerator<accelerators>` device type.

Returns:
    int: the peak memory reserved by PyTorch (in bytes) within the current process.
zreserved_bytes.all.peakr;   r=   s   "r   Úmax_memory_reservedrG   ³   s   € ô" ˜Ó%×)Ñ)Ð*CÀQÓGÐGr   c                ó(   € V ^8„  d   QhR\         RR/# ©r	   r-   r
   N©r   )r   s   "r   r   r   Ç   s   € ÷ Eñ E´ð EÈñ Er   c               ó¦   € \         P                  P                  4       '       g   R# \        V RR7      p \         P                  P	                  V 4      # )ad  Reset the "accumulated" (historical) stats tracked by the current :ref:`accelerator<accelerators>`
memory allocator for a given device index.

Args:
    device_index (:class:`torch.device`, str, int, optional): the index of the device to target.
        If not given, use :func:`torch.accelerator.current_device_index` by default.
        If a :class:`torch.device` or str is provided, its type must match the current
        :ref:`accelerator<accelerators>` device type.

.. note:: This function is a no-op if the memory allocator for the current
    :ref:`accelerator <accelerators>` has not been initialized.
NTr/   )r   r   r   r   Ú"_accelerator_resetAccumulatedStatsr=   s   "r   Úreset_accumulated_memory_statsrM   Ç   s;   € ô �8‰8×7Ñ7×9Ò9ÙÜ$ \¸DÔA€LÜ�8‰8×6Ñ6°|ÓDÐDr   c                ó(   € V ^8„  d   QhR\         RR/# rI   rJ   )r   s   "r   r   r   Ú   s   € ÷ >ñ >¬)ð >À$ñ >r   c               ó¦   € \         P                  P                  4       '       g   R# \        V RR7      p \         P                  P	                  V 4      # )aP  Reset the "peak" stats tracked by the current :ref:`accelerator<accelerators>`
memory allocator for a given device index.

Args:
    device_index (:class:`torch.device`, str, int, optional): the index of the device to target.
        If not given, use :func:`torch.accelerator.current_device_index` by default.
        If a :class:`torch.device` or str is provided, its type must match the current
        :ref:`accelerator<accelerators>` device type.

.. note:: This function is a no-op if the memory allocator for the current
    :ref:`accelerator <accelerators>` has not been initialized.
NTr/   )r   r   r   r   Ú_accelerator_resetPeakStatsr=   s   "r   Úreset_peak_memory_statsrQ   Ú   s;   € ô �8‰8×7Ñ7×9Ò9ÙÜ$ \¸DÔA€LÜ�8‰8×/Ñ/°Ó=Ð=r   c                óR   € V ^8„  d   QhR\         R\        \        \        3,          /# r,   )r   r   r9   )r   s   "r   r   r   í   s"   € ÷ =ñ =¤)ð =¼%ÄÄSÀ½/ñ =r   c               óZ   € \        V RR7      p \        P                  P                  V 4      # )a£  Return the current device memory information for a given device index.

Args:
    device_index (:class:`torch.device`, str, int, optional): the index of the device to target.
        If not given, use :func:`torch.accelerator.current_device_index` by default.
        If a :class:`torch.device` or str is provided, its type must match the current
        :ref:`accelerator<accelerators>` device type.

Returns:
    tuple[int, int]: a tuple of two integers (free_memory, total_memory) in bytes.
        The first value is the free memory on the device (available across all processes and applications),
        The second value is the device's total hardware memory capacity.
Tr/   )r   r   r   Ú_accelerator_getMemoryInfor=   s   "r   Úget_memory_inforU   í   s%   € ô % \¸DÔA€Lä�8‰8×.Ñ.¨|Ó<Ð<r   c                ó$   € V ^8„  d   QhR\         /# )r	   Úaugment_with_fx_traces)Úbool)r   s   "r   r   r      s   € ÷ ñ ´4ñ r   c                ó  € \         P                  P                  4       pVe<   VP                  R8X  d+   \         P                  P
                  P                  WR7      # \         P                  P
                  P                  WR7      # )a  Return a snapshot of the current :ref:`accelerator<accelerators>` memory allocator state.

Requires :func:`_record_memory_history` on the appropriate device module
(e.g., :func:`torch.cuda.memory._record_memory_history`) to have been called.

Args:
    device: the device to snapshot. If not given, uses the current device.
    augment_with_fx_traces (bool, optional): if True, augment stack traces
        with FX graph information. Default: ``False``.

Returns:
    dict: a dictionary containing memory allocator state information.
Úxpu)rW   )r   ÚacceleratorÚcurrent_acceleratorÚtyperZ   ÚmemoryÚ	_snapshotÚcuda)ÚdevicerW   Úaccs   && r   r_   r_      st   € ô ×
Ñ
×
/Ñ
/Ó
1€CØ
‚˜3Ÿ8™8 uÔ,Ü�y‰y×Ñ×)Ñ)Øð *ó 
ð 	
ô �:‰:×Ñ×&Ñ&Øð 'ó ð r   )
r   r   rU   rA   rG   r>   rD   r6   rM   rQ   )N)NF)Úcollectionsr   Útypingr   r   Ú_utilsr   r   Ú__all__r   r   r&   r6   r>   rA   rD   rG   rM   rQ   rU   r_   r   r   r   Ú<module>rg      s`   ðÝ #Ý ã ç 0ò€õ	'õ+õ'÷F#÷RL÷ I÷(K÷ H÷(E÷&>÷&=÷&ñ r   