o �J�h���@s UddlmZddlZddlZddlZddlZddlZddlZddlm Z m Z m Z m ZmZmZmZddlmZddlZddlmZmZddlmZmZmZddgZzddlZd ZWn e yfd ZdZYnwe�!�Z"iZ#d e$d <ed dd�Z%Gdd�d�Z&dd�Z'Gdd�dej(j)e&�Z*dd�Z+ej,dd�dd��Z-ej,dd�dd��Z.ej,dd�dd��Z/dd�Z0d d!�Z1d a2d"d#�Z3d$d%�Z4d8d'd(�Z5d)d*�Z6d9d-d.�Z7Gd/d�d�Z8ej9e8j:_9e&j;j9e8j;_9e&j<j9e8j<_9ej9e8j=_9Gd0d1�d1e:�Z>Gd2d3�d3e8e>d4�Z?d:d6d7�Z@dS);�)� annotationsN)�Any�cast�Dict�Optional�Type�TypeVar�Union)�Self)�_to�_type)�_bool�_int�Storage� TypedStorage�UntypedStorageTFz_Dict[int, threading.RLock]�_share_memory_map�T�!Union[_StorageBase, TypedStorage])�boundcs,eZdZUded<dZded<dZded<ded<d Zd ed <d d �Zd�dd�Zdd�Z dd�Z d�d�dd�Z d�dd�Z d�dd �Z d�d!d"�Z d�d�d%d&�Z d�d�d'd(�Zd�d�d)d*�Zd�d+d,�Zd�d-d.�Zd�d/d0�Zd�d1d2�Zd3d4�Zd5d6�Zed�d:d;��Zed�d<d=��Zed�d>d?��Zed d d@�d�dAdB��Zed�dCdD��Zed�dEdF��Zd�dGdH�ZdIdJ�Z d�dKdL�Z!d�dMdN�Z"dOdP�Z#dQdR�Z$dSdT�Z%d�dUdV�Z&ed�dWdX��Z'dYdZ�Z(ed[d\��Z)e*d]d^��Z+e*d_d`��Z,ed�dadb��Z-ed�dcdd��Z.dedf�Z/d�dgdh�Z0didj�Z1dkdl�Z2dmdn�Z3dodp�Z4dqdr�Z5�fdsdt�Z6dudv�Z7dwdx�Z8dydz�Z9d{d|�Z:d}d~�Z;dd�d�d�d��Z<d�d��Z=d�d��Z>d�d��Z?d�d��Z@d�d��ZAd�d��ZBd�d��ZCd�d��ZDd�d��ZEd�d��ZFd�d��ZGd�d��ZHd�d��ZId�d��ZJd�d��ZKd�d��ZLd�d�d�d��ZMd�d�d�d��ZNd�d��ZOed�d��d�d���ZPd�d��ZQd�d��ZR�ZSS)�� _StorageBaser�_cdataFr � is_sparse� is_sparse_csr� torch.device�deviceN�_Optional[torch.device]� _fake_devicecOsdS�N���self�args�kwargsrr�KC:\pinokio\api\whisper-webui.git\app\env\lib\site-packages\torch\storage.py�__init__-�z_StorageBase.__init__�returnrcC�t�r��NotImplementedError�r!rrr$�__len__0r&z_StorageBase.__len__cCr(rr)�r!�idxrrr$� __getitem__3r&z_StorageBase.__getitem__cOr(rr)r rrr$� __setitem__6r&z_StorageBase.__setitem__�sourcer� non_blocking�_Optional[_bool]cCr(rr)�r!r1r2rrr$�copy_9r&z_StorageBase.copy_rcCr(rr)r+rrr$�new<r&z_StorageBase.newcCr(rr)r+rrr$�nbytes?r&z_StorageBase.nbytescC�|��Sr)r7r+rrr$�sizeB�z_StorageBase.size�dtype�_Optional[str]cC� t|||�Sr)r )r!r;r2rrr$�typeE� z_StorageBase.typecC�(|rt�d|�nt�d�}|j||d�S)a�Returns a copy of this object in CUDA memory. If this object is already in CUDA memory and on the correct device, then no copy is performed and the original object is returned. Args: device (int): The destination GPU id. Defaults to the current device. non_blocking (bool): If ``True`` and the source is in pinned memory, the copy will be asynchronous with respect to the host. Otherwise, the argument has no effect. �cuda�rr2��torchr�to�r!rr2Zdevice2rrr$rAJsz_StorageBase.cudacCr@)a�Returns a copy of this object in HPU memory. If this object is already in HPU memory and on the correct device, then no copy is performed and the original object is returned. Args: device (int): The destination HPU id. Defaults to the current device. non_blocking (bool): If ``True`` and the source is in pinned memory, the copy will be asynchronous with respect to the host. Otherwise, the argument has no effect. �hpurBrCrFrrr$rG[s z_StorageBase.hpucCr(rr)r+rrr$� element_sizejr&z_StorageBase.element_sizecC�|jjSr)r�indexr+rrr$� get_devicemr:z_StorageBase.get_devicecCr(rr)r+rrr$�data_ptrpr&z_StorageBase.data_ptrcCr(rr)r+rrr$� resizablesr&z_StorageBase.resizablecOr(rr)r rrr$�_share_filename_cpu_wr&z!_StorageBase._share_filename_cpu_cOr(rr)r rrr$�_share_fd_cpu_zr&z_StorageBase._share_fd_cpu_�cls�Type[T]r9cCr(rr)�rPr9rrr$�_new_using_filename_cpu}�z$_StorageBase._new_using_filename_cpucCr(rr)rRrrr$�_new_using_fd_cpu�rTz_StorageBase._new_using_fd_cpucOr(rr)�rPr"r#rrr$� from_buffer�rTz_StorageBase.from_buffer)rr;cCr(rr))rP�manager�objr9rr;rrr$�_new_shared_filename_cpu�s z%_StorageBase._new_shared_filename_cpucOr(rr)rVrrr$�_release_ipc_counter_cuda�rTz&_StorageBase._release_ipc_counter_cudacOr(rr)rVrrr$�_new_with_weak_ptr�rTz_StorageBase._new_with_weak_ptrcCr(rr)r+rrr$�_shared_decref�r&z_StorageBase._shared_decrefcOr(rr)r rrr$� _write_file�r&z_StorageBase._write_filecCr(rr)�r!r9rrr$�resize_�r&z_StorageBase.resize_cOr(rr)r rrr$� _weak_ref�r&z_StorageBase._weak_refcOr(rr)r rrr$�_set_from_file�r&z_StorageBase._set_from_filecOr(rr)r rrr$� _set_cdata�r&z_StorageBase._set_cdatacOr(rr)r rrr$� _share_cuda_�r&z_StorageBase._share_cuda_cCr(rr)r+rrr$� is_shared�r&z_StorageBase.is_sharedcOr(rr)rVrrr$�_new_shared_cuda�rTz_StorageBase._new_shared_cudacOr(rr)r rrr$�_shared_incref�r&z_StorageBase._shared_increfcOr(rr)rVrrr$�_free_weak_ref�rTz_StorageBase._free_weak_refcCr(rr)r+rrr$�is_cuda�rTz_StorageBase.is_cudacCr(rr)r+rrr$�is_hpu�rTz_StorageBase.is_hpucCr(rr))rP�filename�sharedr7rrr$� from_file�rTz_StorageBase.from_filecOr(rr)rVrrr$�_expired�rTz_StorageBase._expiredcOr(rr)r rrr$� _byteswap�r&z_StorageBase._byteswapcOr(rr)r rrr$� _get_filename�r&z_StorageBase._get_filenamecshdt����d�j�dt���d�}�jjdkrd|Sdd��fd d �t����D��}|d |S) N�[z(device=� ) of size �]�meta�... � � c3��|] }t�|�VqdSr��str��.0�ir+rr$� <genexpr>���z(_StorageBase.__repr__.<locals>.<genexpr>� )rD�typenamer�lenr>�join�ranger9�r!Zinfo_strZdata_strrr+r$�__repr__�s $ $ z_StorageBase.__repr__cst�fdd�t����D��S)Nc3��|]}�|VqdSrrr{r+rr$r~���z(_StorageBase.__iter__.<locals>.<genexpr>)�iterr�r9r+rr+r$�__iter__�sz_StorageBase.__iter__cCr8r)�cloner+rrr$�__copy__�r:z_StorageBase.__copy__cCs6|�di�}|j|vr||jS|��}|||j<|S)NrD)� setdefaultrr�)r!�memo� new_storagerrr$� __deepcopy__�s    z_StorageBase.__deepcopy__cC�&t��}tj||dd�t|��ffS�NF)Z_use_new_zipfile_serialization��io�BytesIOrD�save�_load_from_bytes�getvalue�r!�brrr$� __reduce__��z_StorageBase.__reduce__cst���|��Sr)�super� __sizeof__r9r+�� __class__rr$r���z_StorageBase.__sizeof__cCst|�|��|jd��|�S)�Return a copy of this storage.�r)r>r7rr5r+rrr$r��sz_StorageBase.clonecCst|�S�z6Return a list containing the elements of this storage.)�listr+rrr$�tolist��z_StorageBase.tolistcCs&|jjdkrt�|����|d�S|S)�AReturn a CPU copy of this storage if it's not already on the CPU.�cpuF�rr>rDrr9r5r+rrr$r��s z_StorageBase.cpucCs*|jjdkrtj|��dd��|d�S|S)zAReturn a MPS copy of this storage if it's not already on the MPS.�mpsr�Fr�r+rrr$r�s z_StorageBase.mpscCsdt|tj�stdt|�����tjgtj|jd��t t |��� |�� �}|� �|� �kr0|��}|S�Nz*Argument 'dtype' must be torch.dtype, not �r;r)� isinstancerDr;� TypeErrorr>�tensor�uint8r�set_rrrE�_typed_storagerLr��r!r;�storagerrr$r s  �z_StorageBase._to�r2cCr=r)r )r!rr2rrr$rEr?z_StorageBase.tocC� |�tj�S�z"Casts this storage to double type.)r rD�doubler+rrr$r�� z_StorageBase.doublecCr��z!Casts this storage to float type.)r rD�floatr+rrr$r�r�z_StorageBase.floatcCr��z Casts this storage to half type.)r rD�halfr+rrr$r�!r�z_StorageBase.halfcCr��z Casts this storage to long type.)r rD�longr+rrr$r�%r�z_StorageBase.longcCr��zCasts this storage to int type.)r rD�intr+rrr$r�)r�z_StorageBase.intcCr��z!Casts this storage to short type.)r rD�shortr+rrr$r�-r�z_StorageBase.shortcCr��z Casts this storage to char type.)r rD�int8r+rrr$�char1r�z_StorageBase.charcCr��z Casts this storage to byte type.)r rDr�r+rrr$�byte5r�z_StorageBase.bytecCr��z Casts this storage to bool type.)r rD�boolr+rrr$r�9r�z_StorageBase.boolcCr��z$Casts this storage to bfloat16 type.)r rD�bfloat16r+rrr$r�=r�z_StorageBase.bfloat16cCr��z*Casts this storage to complex double type.)r rD�cdoubler+rrr$�complex_doubleAr�z_StorageBase.complex_doublecCr��z)Casts this storage to complex float type.)r rD�cfloatr+rrr$� complex_floatEr�z_StorageBase.complex_floatcCr��z&Casts this storage to float8_e5m2 type)r rD� float8_e5m2r+rrr$r�Ir�z_StorageBase.float8_e5m2cCr��z(Casts this storage to float8_e4m3fn type)r rD� float8_e4m3fnr+rrr$r�Mr�z_StorageBase.float8_e4m3fncCr��z*Casts this storage to float8_e5m2fnuz type)r rD�float8_e5m2fnuzr+rrr$r�Qr�z_StorageBase.float8_e5m2fnuzcCr��z*Casts this storage to float8_e4m3fnuz type)r rD�float8_e4m3fnuzr+rrr$r�Ur�z_StorageBase.float8_e4m3fnuzrA�Union[str, torch.device]cCs&tjgtj|jd��tt|���|�S)z�Determine whether the CPU storage is already pinned on device. Args: device (str or torch.device): The device to pin memory on. Default: ``'cuda'``. Returns: A boolean variable. r�)rDr�r�rr�rr� is_pinned�r!rrrr$r�Ys �z_StorageBase.is_pinnedcCsN|jjdkrtd|���d���tjgtj|jd��tt|��� |�}|� �S)z�Copy the CPU storage to pinned memory, if it's not already pinned. Args: device (str or torch.device): The device to pin memory on. Default: ``'cuda'``. Returns: A pinned CPU storage. r�z cannot pin 'z' only CPU memory can be pinnedr�) rr>r�rDr�r�r�rr� pin_memory�untyped_storage)r!rZ pinned_tensorrrr$r�hs  �z_StorageBase.pin_memorycCsJddlm}|jjdtj��fvr |S|�dkr|��|S|��|S)�.See :meth:`torch.UntypedStorage.share_memory_`r��get_sharing_strategyrA� file_system) �torch.multiprocessingr�rr>rD�_C�_get_privateuse1_backend_namerNrO)r!r�rrr$� share_memory_{s  ��z_StorageBase.share_memory_r�r�cCsVddlm}t�|�}|jdtj��dfvr|||d�S|�dkr&|�|�S|�|�S)�>Create a new storage in shared memory with the same data type.rr�rArGr�r�) r�r�rDrr>r�r�rSrU)rPr9rr�rrr$� _new_shared�s      z_StorageBase._new_sharedcCs|Srrr+rrr$�untyped�r&z_StorageBase.untypedcCs2tj�|�}|jrtt|d�d�}|�|�dS)zSwap bytes in underlying data.��N)rD�_utils� _element_size� is_complex�maxr�ro)r!r;Z elem_sizerrr$�byteswap�s z_StorageBase.byteswap�r'rr)r1rr2r3r'r)r'r�NF)r;r<r2r r'r)r'r )rPrQr9rr'r)rPrQr'r)r9r�r'r<)rrr2r r'r�rA�rr�)T�__name__� __module__� __qualname__�__annotations__rrrr%r,r/r0r5r6r7r9r>rArGrHrKrLrMrNrO� classmethodrSrUrWrZr[r\r]r^r`rarbrcrdrerfrgrh�propertyrirjrmrnrorpr�r�r�r�r�r�r�r�r�r�r rEr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�� __classcell__rrr�r$r%s�          � �        �              �    rcst����fdd��}|S)NcsBd}d}t�"|j}|tvrt|}nt��t|<t|��|}Wd�n1s+wY|durF|�Wd�n1sAwYz3�|g|�Ri|��W|dury|j|ks]J�t�t|��t|=Wd�S1sswYSS|dur�|j|ks�J�t�t|��t|=Wd�w1s�wYwr)�_share_memory_lockrr� threading�RLock�acquire�release)r!r"r#Zto_freeZto_wait�key��fnrr$�wrapper�s:   �� � � � �z-_share_memory_lock_protected.<locals>.wrapper)� functools�wraps)rrrrr$�_share_memory_lock_protected�sr csreZdZ�fdd�Zedd��Zedd��Zedd d ��Ze�fd d ��Z e�fd d��Z e�fdd��Z �Z S)rcs&|jjdkr td��t�j|i|��S)Nrt�$Not available for 'meta' device type)rr>r*r�r/r r�rr$r/�s zUntypedStorage.__getitem__cC� |jjdkS�NrA�rr>r+rrr$ri�r�zUntypedStorage.is_cudacCr �NrGrr+rrr$rj�r�zUntypedStorage.is_hpur'r<cCr8)z�Returns the file name associated with this storage. The file name will be a string if the storage is on CPU and was created via :meth:`~torch.from_file()` with ``shared`` as ``True``. This attribute is ``None`` otherwise. )rpr+rrr$rk�szUntypedStorage.filenamec�t�j|i|��S)a{ Moves the storage to shared memory. This is a no-op for storages already in shared memory and for CUDA storages, which do not need to be moved for sharing across processes. Storages in shared memory cannot be resized. Note that to mitigate issues like `this <https://github.com/pytorch/pytorch/issues/95606>`_ it is thread safe to call this function from multiple threads on the same object. It is NOT thread safe though to call any other function on self without proper synchronization. Please see :doc:`/notes/multiprocessing` for more details. .. note:: When all references to a storage in shared memory are deleted, the associated shared memory object will also be deleted. PyTorch has a special cleanup process to ensure that this happens even if the current process exits unexpectedly. It is worth noting the difference between :meth:`share_memory_` and :meth:`from_file` with ``shared = True`` #. ``share_memory_`` uses `shm_open(3) <https://man7.org/linux/man-pages/man3/shm_open.3.html>`_ to create a POSIX shared memory object while :meth:`from_file` uses `open(2) <https://man7.org/linux/man-pages/man2/open.2.html>`_ to open the filename passed by the user. #. Both use an `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_ with ``MAP_SHARED`` to map the file/object into the current virtual address space #. ``share_memory_`` will call ``shm_unlink(3)`` on the object after mapping it to make sure the shared memory object is freed when no process has the object open. ``torch.from_file(shared=True)`` does not unlink the file. This file is persistent and will remain until it is deleted by the user. Returns: ``self`` )r�r�r r�rr$r��s!zUntypedStorage.share_memory_crr)r�rOr r�rr$rO��zUntypedStorage._share_fd_cpu_crr)r�rNr r�rr$rNrz#UntypedStorage._share_filename_cpu_r�) r�r�r�r/r�rirjrkr r�rOrNr�rrr�r$r�s    "cCstjt�|�dd�S)NF)Z weights_only)rD�loadr�r�)r�rrr$r��r�)�maxsizec Cs,tjtjtjtjtjtjtjtjtj tj h Sr) rDr�r�r�r�Zbits8Zbits16Zbits1x8Zbits2x4Zbits4x2� complex32rrrr$� _new_dtypes s�rcCs�itjd�tjd�tjd�tjd�tjd�tjd�tjd�tjd�tj d �tj d �tj d �tj d �tj d �tjd�tjd�tjd�tjd�S)N� DoubleStorage� FloatStorage� HalfStorage� LongStorage� IntStorage� ShortStorage� CharStorage� ByteStorage� BoolStorage�BFloat16Storage�ComplexDoubleStorage�ComplexFloatStorage� QInt8Storage� QInt32Storage� QUInt8Storage�QUInt4x2Storage�QUInt2x4Storage)rDr�r�r�r�r��int16r�r�r�r�r�r��qint8�qint32�quint8�quint4x2�quint2x4rrrr$�_dtype_to_storage_type_mapsF�������� � � � � �����r.cCsdd�t���D�}|S)NcSsi|]\}}||�qSrr)r|r�valrrr$� <dictcomp>;sz._storage_type_to_dtype_map.<locals>.<dictcomp>)r.�items)Z dtype_maprrr$�_storage_type_to_dtype_map9sr2c Csx|tjtjtjtjtjfvr/tjtjtjtjtjtjtjtjtjtji}tj ||||d�}ntj |||d�}|� �j S)Nr�) rDr+r,r-r*r)r��int32r�r�r��_untyped_storage)�sequencer;r�interpret_dtypes� tmp_tensorrrr$�_get_storage_from_sequence?s$�� � r8cCstr t|ttjf�St|t�Sr)� HAS_NUMPYr�r��np�integer)�xrrr$�_isintXs r=cCstSr)�"_always_warn_typed_storage_removalrrrr$�&_get_always_warn_typed_storage_removalbr&r?cCst|t�sJ�|adSr)r�r�r>)Z always_warnrrr$�&_set_always_warn_typed_storage_removalfsr@r�cCs>dd�}t�s |�rd}tj|t|dd�dtjd<dSdS)NcSsttd�sdStjd S)N� has_warnedT)�hasattr�_warn_typed_storage_removal�__dict__rrrr$� is_first_timeos  z2_warn_typed_storage_removal.<locals>.is_first_timeaTypedStorage is deprecated. It will be removed in the future and UntypedStorage will be the only storage class. This should only matter to you if you are using storages directly. To access UntypedStorage directly, use tensor.untyped_storage() instead of tensor.storage()r�)� stacklevelTrA)r?�warnings�warn� UserWarningrCrD)rFrE�messagerrr$rCls ��rCcCsdtjd<dS)NFrA)rCrDrrrr$�!_reset_warn_typed_storage_removal��rK�modulerzcCs,|�dd�d}|dtj��dfvr|SdS)N�.r������rArGr�)�rsplitrDr�r�)rMZ last_partrrr$�_get_device_from_module�srQcs�eZdZUdZded<dZded<ded<ed d ��Zed�d d��Zdd�Z ddddd��fdd� Z ddddd�dd�Z edd��Z edd��Z dd�Zd�dd�Zd d!�Zd�d"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd�d�d0d1�Zd2d3�Zd4d5�Z  d�d�d8d9�Zd�d�d:d;�Zd�d�d<d=�Zdd>�d�dAdB�ZdCdD�ZdEdF�Zd�dHdI�ZdJdK�Z dLdM�Z!dNdO�Z"dPdQ�Z#dRdS�Z$dTdU�Z%�fdVdW�Z&dXdY�Z'dZd[�Z(d\d]�Z)d�d�d`da�Z*d�d�dbdc�Z+ddde�Z,dfdg�Z-ddh�didj�Z.edkdl��Z/edmdn��Z0dodp�Z1dqdr�Z2dsdt�Z3dudv�Z4dwdx�Z5dydz�Z6d{d|�Z7d}d~�Z8dd��Z9d�d��Z:e;d�d���Z<d�d��Z=e;d�d���Z>e;ddd��d�d���Z?d�d��Z@d�d��ZAd�d��ZBd�d��ZCd�d��ZDd�d��ZEd�d��ZFd�d��ZGd�d��ZHd�d��ZId�d��ZJd�d��ZKd�d��ZLd�d��ZMd�d��ZNd�d��ZOd�d��ZPe;d�d���ZQe;d�d���ZRd�d��ZSd�d��ZTd�d��ZUd�d��ZVd�d��ZWd�d��ZXe;d�d���ZYd�d��ZZd�dÄZ[e;ddh�d�dń�Z\d�dDŽZ]d�dɄZ^d�d˄Z_�Z`S)�rFr rNrr� torch.dtyper;cCs|jSr)r;r+rrr$�_dtype�szTypedStorage._dtyper'r<cCrI)z�Returns the file name associated with this storage if the storage was memory mapped from a file. or ``None`` if the storage was not created by memory mapping a file.)r4rkr+rrr$rk�szTypedStorage.filenamecCs t�|�td|���|�|S)Nr)rC�_setitem�slice�_size)r!�valuerrr$�fill_�szTypedStorage.fill_)� wrap_storager;r� _internalcsb|st�|tjjkrtd��|tkrt��|�S|�d�}|dur(t|d��|dur2t|d��|durqt|�dkrBt|d��t|�dkrdt |d�sdt |dt j j �sdt|dt|d�����t||jt|j�d d ��St|�dkr}t|d ��t |tj�s�t|d t|�����t|j�}|jj|kr�t|d |�d|jj����t|||jd d��S)Nz8Only child classes of _LegacyStorage can be instantiatedz�.__new__ received an invalid combination of arguments. Expected one of: * no arguments * (int size) * (Sequence data) * (*, UntypedStorage wrap_storage)z. Keyword argument 'device' cannot be specifiedz- Keyword argument 'dtype' cannot be specifiedr�� Too many positional argumentsr� Argument type not recognized: T)r;rrZ�B No positional arguments should be given when using 'wrap_storage'�9 Argument 'wrap_storage' must be UntypedStorage, but got z" Device of 'wrap_storage' must be z , but got �rYr;rZ)rCrDr��_LegacyStorage� RuntimeErrorrr��__new__r�r=r�� collections�abc�Sequencer�r>rSrQr�rrr;)rPrYr;rrZr"� arg_error_msg� cls_devicer�rr$rb�s� � � �� �  ����� ��  ��  ����zTypedStorage.__new__)rr;rYrZcGs�|st�d}|durUt|�dkrt|d��|dur!t|d��t|tj�s2t|dt|�����|dur<t|d��||_t|tj�sPt|dt|�����||_ dS|dur]t� �n||_t� |durhdn|�}|jtj tj tjtjtjfvr�|jd kr�td ��t|�dkr�tj|d �|_ dSt|�d kr�t|d�r�tjt|d�|��|d �|_ dSt|dtjj�r�t|d|j|�|_ dSt|d t|d�����t|d��)Na1TypedStorage.__init__ received an invalid combination of arguments. Expected one of: * (*, torch.device device, torch.dtype dtype) * (int size, *, torch.device device, torch.dtype dtype) * (Sequence data, *, torch.device device, torch.dtype dtype) * (*, UntypedStorage wrap_storage, torch.dtype dtype)rr]z# Argument 'dtype' must be specifiedz+ Argument 'dtype' must be torch.dtype, not zG Argument 'device' should not be specified when 'wrap_storage' is givenr^r�rA�/Cannot create CUDA storage with quantized dtyper�r�r\r[)rCr�rar�rDr;r�r>rr4�get_default_dtyperr+r,r-r*r)r=r�r�rcrdrer8)r!rr;rYrZr"rfrrr$r%�s�� ���  ����  �� � �    �  ��� zTypedStorage.__init__cC�t�|jjjdkSr �rCr4rr>r+rrr$riY�zTypedStorage.is_cudacCrjrrkr+rrr$rj^rlzTypedStorage.is_hpucCs t�|jS)z2Return the internal :class:`torch.UntypedStorage`.)rCr4r+rrr$r�cszTypedStorage.untypedr cCsBt|�tjks J�t|�tkrttt||jdd��St|�|d�S)NTr_�rY)r>rDrrrr r;)r!r�rrr$�_new_wrapped_storagehs ��z!TypedStorage._new_wrapped_storagecC�t�|��Sr�rCrVr+rrr$r,u�zTypedStorage.__len__cCs�|dur |r |��SdSt|�tkr tdt|��dt|�����|rG||��ks/||�� kr;td|�d|������|dkrA|S||��S||��ksT||�� kr`td|�d|������||��S)Nr�can't index a � with zindex z" out of range for storage of size )rVr>r�r�� IndexErrorr9)r!r.Zis_stoprrr$�_maybe_wrap_indexys& � � zTypedStorage._maybe_wrap_indexcCst�|�||�Sr)rCrT)r!r.rWrrr$r0�s zTypedStorage.__setitem__c Cs�t|ttf�stdt|��dt|�����t�|�r#tdt|�����|jtjtj tj tj tj fvrctjtj tj tj tj tj tj tjtj tji}||j}tjg||jjd�}|�t|j|dd��ntjg|j|jjd��|�}|||<dS)Nrrrsz cannot set item with value type r�Tr_)r�r�rUrar>rD� is_storager;r+r,r-r*r)r�r3r�r�r4rr�r)r!r.rWr6Z tmp_dtyper7rrr$rT�s@ ��  ��� �� zTypedStorage._setitemcC�t�|�|�Sr)rC�_getitemr-rrr$r/�� zTypedStorage.__getitem__c Cs|jjjdkr td��t|t�rtd��t|t�s'tdt|��dt|�����|jt j t j t j t j t jfvrZt j t jt j t jt j t jt j t jt jt ji}t|j||jdd��|�S|�|�}dd lm}|��t jg|j|jjd ��|�}||��Wd�S1s�wYdS) Nrtr z7slices are only supported in UntypedStorage.__getitem__rrrsTr_r)�unset_fake_temporarilyr�)r4rr>r*r�rUrar�r;rDr+r,r-r*r)r�r3r�rrxruZtorch._subclasses.fake_tensorrzr�r��item)r!r.r6Z idx_wrappedrzr7rrr$rx�sL � ����   �� $�zTypedStorage._getitemr1rr2�_Optional[bool]cCs6t�t|t�r|j�|j|�|S|j�||�|Sr)rCr�rr4r5r4rrr$r5�s  �zTypedStorage.copy_cCror)rC�_nbytesr+rrr$r7�rqzTypedStorage.nbytescC� |j��Sr)r4r7r+rrr$r}�� zTypedStorage._nbytesr��&Union[_StorageBase, TypedStorage, str]cCsRt�|dur"|��}|dur|jd|jSd�|jt|�jg�S|j�||�S)NrN)rC�_get_legacy_storage_classr�r�r�r>r4)r!r;r2Z legacy_classrrr$r>�szTypedStorage.typecC�Dt�|jtjtjtjtjtjfvrtd��|j � ||�}|� |�S)Nrh) rCr;rDr+r,r-r*r)rar4rArn)r!rr2Z cuda_storagerrr$rA �� zTypedStorage.cudacCr�)Nz.Cannot create HPU storage with quantized dtype) rCr;rDr+r,r-r*r)rar4rGrn)r!rr2Z hpu_storagerrr$rGr�zTypedStorage.hpur�rrcCsTt�|jtjtjtjtjtjfvrtd|j � ��d���|j j ||d�}|� |�S)NzCannot create z storage with quantized dtyperB)rCr;rDr+r,r-r*r)rar>�upperr4rErn)r!rr2Z to_storagerrr$rE%s�� zTypedStorage.tocCror)rCr�r+rrr$rH4rqzTypedStorage.element_sizecCstj�|j�Sr)rDr�r�r;r+rrr$r�9rLzTypedStorage._element_sizercC�t�|j��Sr)rCr4rKr+rrr$rK<ryzTypedStorage.get_devicec svt�dt����d�j�d�j�dt���d� }�jjdkr#d|Sdd ��fd d �t�� ��D��}|d |S) Nrqz(dtype=z , device=rrrsrtrurvrwc3rxrryr{r+rr$r~Irz'TypedStorage.__str__.<locals>.<genexpr>r�) rCrDr�r;rr�r>r�r�r9r�rr+r$�__str__@s��� $ zTypedStorage.__str__cC�t�t|�Sr)rCrzr+rrr$r�LrqzTypedStorage.__repr__cs$t�t�fdd�t����D��S)Nc3r�rrr{r+rr$r~Rr�z(TypedStorage.__iter__.<locals>.<genexpr>)rCr�r�r9r+rr+r$r�PszTypedStorage.__iter__cCst�|�t�|j��Sr)rCrn�copyr4r+rrr$r�T�zTypedStorage.__copy__cCrwr)rC� _deepcopy�r!r�rrr$r�XryzTypedStorage.__deepcopy__cCs|�t�|j|��Sr)rnr��deepcopyr4r�rrr$r�]rzTypedStorage._deepcopycst�t���|��Sr)rCr�r�r7r+r�rr$r�`r�zTypedStorage.__sizeof__cC�t�|�|j���S)r�)rCrnr4r�r+rrr$r�d�zTypedStorage.clonecCr�r�)rCr�r+rrr$r�i�zTypedStorage.tolistcCr�)r�)rCrnr4r�r+rrr$r�nr�zTypedStorage.cpurAr�cCst�|j�|�S)z�Determine whether the CPU TypedStorage is already pinned on device. Args: device (str or torch.device): The device to pin memory on. Default: ``'cuda'`` Returns: A boolean variable. )rCr4r�r�rrr$r�ss zTypedStorage.is_pinnedcCst�|�|jj|d��S)z�Copy the CPU TypedStorage to pinned memory, if it's not already pinned. Args: device (str or torch.device): The device to pin memory on. Default: ``'cuda'``. Returns: A pinned CPU storage. r�)rCrnr4r�r�rrr$r�s  �zTypedStorage.pin_memorycCro)r�)rC�_share_memory_r+rrr$r��r�zTypedStorage.share_memory_cC�|j��|Sr)r4r�r+rrr$r��� zTypedStorage._share_memory_r�cCs>|durd}t�|�}tjj||��|d�}t||jdd�S)r�Nr�r�Tr_)rDrrr�r�rr;)r!r9rr�rrr$r��s  ��zTypedStorage._new_sharedcCrIr)r4rr+rrr$r�r�zTypedStorage._cdatacCst�|jjSr)rCr4rr+rrr$r�r�zTypedStorage.devicecCrorrpr+rrr$r9�rqzTypedStorage.sizecCs|j��|��Sr)r4r7r�r+rrr$rV�szTypedStorage._sizecCror)rC�_pickle_storage_typer+rrr$�pickle_storage_type�rqz TypedStorage.pickle_storage_typec Cs<zt�|jWSty}z td|j�d��|�d}~ww)Nzdtype z is not recognized)r.r;�KeyError)r!�errr$r��s ��z!TypedStorage._pickle_storage_typecCr�r�r�r�rrr$r��r�zTypedStorage.__reduce__cCror)rC� _data_ptrr+rrr$rL�rqzTypedStorage.data_ptrcCr~r)r4rLr+rrr$r��rzTypedStorage._data_ptrcCr�r)rCr4rMr+rrr$rM�ryzTypedStorage.resizablecCst�|�|�dSr)rC�_resize_r_rrr$r`�szTypedStorage.resize_cCs|j�||���dSr)r4r`r�r_rrr$r��szTypedStorage._resize_cO�tj|i|��Sr)rrhrVrrr$rh��zTypedStorage._free_weak_refcO�|jj|i|��Sr)r4rar rrr$ra�r�zTypedStorage._weak_refcOst�|j|i|��Sr)rC� _from_bufferrVrrr$rW�r�zTypedStorage.from_bufferr�cOs�|tkr2|dur t��n|}t�|durdn|�}|jdkr&td|j����tjj|d|i|��}n$|dus<t|�dkr@td��|durHtd��|j }tjj|d|i|��}t||dd�S) Nr�z3TypedStorage.from_buffer: Not available for device r;�zefrom_buffer: 'dtype' can only be specified in UntypedStorage.from_buffer and TypedStorage.from_bufferzffrom_buffer: 'device' can only be specified in UntypedStorage.from_buffer and TypedStorage.from_bufferTr_) rrDrirr>rarrWr�rS)rPr;rr"r#r�rrr$r��s>  ���������zTypedStorage._from_buffercCs^t|tj�stdt|�����tjg|j|jd��|��|�� �}|� �|� �kr-|� �}|Sr�) r�rDr;r�r>r�rr�rEr�rLr�r�rrr$r s �zTypedStorage._tocC�t�|�tj�Sr�)rCr rDr�r+rrr$r�� zTypedStorage.doublecCr�r�)rCr rDr�r+rrr$r�r�zTypedStorage.floatcCr�r�)rCr rDr�r+rrr$r�r�zTypedStorage.halfcCr�r�)rCr rDr�r+rrr$r�"r�zTypedStorage.longcCr�r�)rCr rDr�r+rrr$r�'r�zTypedStorage.intcCr�r�)rCr rDr�r+rrr$r�,r�zTypedStorage.shortcCr�r�)rCr rDr�r+rrr$r�1r�zTypedStorage.charcCr�r�)rCr rDr�r+rrr$r�6r�zTypedStorage.bytecCr�r�)rCr rDr�r+rrr$r�;r�zTypedStorage.boolcCr�r�)rCr rDr�r+rrr$r�@r�zTypedStorage.bfloat16cCr�r�)rCr rDr�r+rrr$r�Er�zTypedStorage.complex_doublecCr�r�)rCr rDr�r+rrr$r�Jr�zTypedStorage.complex_floatcCr�r�)rCr rDr�r+rrr$r�Or�zTypedStorage.float8_e5m2cCr�r�)rCr rDr�r+rrr$r�Tr�zTypedStorage.float8_e4m3fncCr�r�)rCr rDr�r+rrr$r�Yr�zTypedStorage.float8_e5m2fnuzcCr�r�)rCr rDr�r+rrr$r�^r�zTypedStorage.float8_e4m3fnuzcCs@t�|tkr td��t�|||tj�|j��}||d�}|S)a�from_file(filename, shared=False, size=0) -> Storage Creates a CPU storage backed by a memory-mapped file. If ``shared`` is ``True``, then memory is shared between all processes. All changes are written to the file. If ``shared`` is ``False``, then the changes on the storage do not affect the file. ``size`` is the number of elements in the storage. If ``shared`` is ``False``, then the file must contain at least ``size * sizeof(Type)`` bytes (``Type`` is the type of storage). If ``shared`` is ``True`` the file will be created if needed. Args: filename (str): file name to map shared (bool): whether to share memory (whether ``MAP_SHARED`` or ``MAP_PRIVATE`` is passed to the underlying `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_) size (int): number of elements in the storage z/from_file can only be called on derived classesrm) rCrrarrmrDr�r�r;)rPrkrlr9r�r�rrr$rmcs� zTypedStorage.from_filecOr�r)rrnrVrrr$rn�r�zTypedStorage._expiredcOr�r)r4r^r rrr$r^�r�zTypedStorage._write_filecOr�r)r4rbr rrr$rb�r�zTypedStorage._set_from_filecOr�r)r4rcr rrr$rc�r�zTypedStorage._set_cdatacOr�r)r4rdr rrr$rd�r�zTypedStorage._share_cuda_cCror)rC� _is_sharedr+rrr$re�rqzTypedStorage.is_sharedcCr~r)r4rer+rrr$r��rzTypedStorage._is_sharedcO�tjj|i|��Sr)rDrrfrVrrr$rf�rzTypedStorage._new_shared_cudacOs*|jj|i|��\}}}||||��fSr)r4rNr�)r!r"r#Zmanager_handleZstorage_handler9rrr$rN�s �z!TypedStorage._share_filename_cpu_cCr�r)r4r]r+rrr$r]�r�zTypedStorage._shared_decrefcOstjj|i|��Sr�rDrr[)rPrr"r#rrr$�_release_ipc_counter�rz!TypedStorage._release_ipc_countercOr�r)r4rgr rrr$rg�r�zTypedStorage._shared_increfcOs&|jj|i|��\}}|||��fSr)r4rOr�)r!r"r#�fdr9rrr$rO�szTypedStorage._share_fd_cpu_cCsz|jt�vrdSt�|j}|jjdddtj��fvrdS|jjdkr%tntt|jj�}zt||�WSty<YdSw)Nr�rArG) r;r.rr>rDr�r��getattr�AttributeError)r!Z storage_namerMrrr$r��s"  ��  �z&TypedStorage._get_legacy_storage_classr�)r'r )Fr)r1rr2r|r�)r;r<r2r�r'r�)rrr2r�r'r r�r�r�)ar�r�r�rr�rr�rSrkrXrbr%rirjr�rnr,rur0rTr/rxr5r7r}r>rArGrErHr�rKr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrr9rVr�r�r�rLr�rMr`r�r�rhrarWr�r r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rmrnr^rbrcrdrer�rfrNr]r�rgrOr�r�rrr�r$r�s�    �_ �[    # , �                c@seZdZUded<dd�ZdS)�_LegacyStorageMetarRr;cCs2t|�tkrt|j�}||jjko|j|jkSdSr�)r>rrQr�rr;)rP�instancergrrr$�__instancecheck__�s    �z$_LegacyStorageMeta.__instancecheck__N)r�r�r�r�r�rrrr$r��s  r�c@s0eZdZedd��Zedd��Zedd��ZdS)r`cCs tj�||����}||d�S)r�rm)rDrr�r�)rPr9r�rrr$r��s z_LegacyStorage._new_sharedcOr�rr�rVrrr$r��rz#_LegacyStorage._release_ipc_countercCs(|tj�|j�}|tj�|||�d�S)Nrm)rDr�r�r;rrZ)rPrXrYr9Z bytes_sizerrr$�_new_shared_filename�s ��z#_LegacyStorage._new_shared_filenameN)r�r�r�r�r�r�r�rrrr$r`�s  r`)� metaclassr�c Cs8zt�|WSty}z td|�d��|�d}~ww)Nzpickle storage type "z" is not recognized)r2r�)r�r�rrr$�#_get_dtype_from_pickle_storage_type�s  ����r�)r�)rMrz)r�rz)A� __future__rrcr�rr�rrG�typingrrr�_Dictr� _Optionalrrr �typing_extensionsr rD� torch._utilsr r Z torch.typesr rr�__all__�numpyr:r9�ModuleNotFoundError�Lockr�rr�rrr r�� StorageBaserr�� lru_cacherr.r2r8r=r>r?r@rCrKrQr�__doc__r>rArGrEr�r`r�rrrr$�<module>sr$  �  }$C         E    
Memory