
    wi                    P   U d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dlm	Z	m
Z
mZmZmZmZmZmZ d dlmZ d dlZd dlmZmZ d dlmZmZmZ erd dlmZ dd	gZ	 d dl Z!d
Z"n# e#$ r dZ"dZ!Y nw xY w ej$                    Z%i Z&de'd<    edd          Z( G d d          Z)d Z* G d d	ej+        j,        e)          Z-d Z. ej/        d          d             Z0 ej/        d          d             Z1 ej/        d          d             Z2d Z3d Z4da5d Z6d Z7d,dZ8d  Z9d-d#Z: G d$ d          Z;ej<        e;j=        _<        e)j>        j<        e;j>        _<        e)j?        j<        e;j?        _<        ej<        e;j@        _<         G d% d&e=          ZA G d' d(e;eA)          ZBd.d+ZCdS )/    )annotationsN)AnycastDictOptionalTypeTYPE_CHECKINGTypeVarUnion)Self)_to_type)_bool_intStorage)DeviceLikeTypeTypedStorageUntypedStorageTFz_Dict[int, threading.RLock]_share_memory_mapT!Union[_StorageBase, TypedStorage])boundc                  B    e Zd ZU ded<   dZded<   dZded<   ded<   d	Zd
ed<   d ZdidZd Z	d Z
djdkdZdldZdidZdidZ	 dmdndZ	 dmdldZdmdldZdid Zdid!Zdid"Zdod#Zd$ Zd% Zedpd)            Zedpd*            Zedqd+            Zed	d	d,dqd-            Zedqd.            Zedqd/            Zdld0Zd1 Z drd2Z!dld3Z"d4 Z#d5 Z$d6 Z%dod7Z&edqd8            Z'd9 Z(ed:             Z)e*d;             Z+e*d<             Z,edld=            Z-edld>            Z.d? Z/dsd@Z0dA Z1dB Z2dC Z3dD Z4dE Z5 fdFZ6dG Z7dH Z8dI Z9dJ Z:dK Z;ddLdtdNZ<dO Z=dP Z>dQ Z?dR Z@dS ZAdT ZBdU ZCdV ZDdW ZEdX ZFdY ZGdZ ZHd[ ZId\ ZJd] ZKd^ ZLdudvdaZMdudvdbZNdc ZOedddedf            ZPdg ZQdh ZR xZSS )w_StorageBaser   _cdataFr   	is_sparseis_sparse_csrztorch.devicedeviceN_Optional[torch.device]_fake_devicec                    d S N selfargskwargss      ]/root/.openclaw/workspace/chatterbox_venv_py311/lib/python3.11/site-packages/torch/storage.py__init__z_StorageBase.__init__:   s        returnr   c                    t           r"   NotImplementedErrorr%   s    r(   __len__z_StorageBase.__len__=       !!r*   c                    t           r"   r-   r%   idxs     r(   __getitem__z_StorageBase.__getitem__@   r1   r*   c                    t           r"   r-   r$   s      r(   __setitem__z_StorageBase.__setitem__C   r1   r*   sourcer   non_blocking_Optional[_bool]c                    t           r"   r-   r%   r8   r9   s      r(   copy_z_StorageBase.copy_F   r1   r*   r   c                    t           r"   r-   r/   s    r(   newz_StorageBase.newI   r1   r*   c                    t           r"   r-   r/   s    r(   nbytesz_StorageBase.nbytesL   r1   r*   c                *    |                                  S r"   )rA   r/   s    r(   sizez_StorageBase.sizeO   s    {{}}r*   dtype_Optional[str]c                $    t          | ||          S r"   )r   )r%   rD   r9   s      r(   typez_StorageBase.typeR   s     T5,///r*   c                    |rt          j        d|          nt          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r   r9   torchr   tor%   r   r9   device2s       r(   rI   z_StorageBase.cudaW   s?     39R%,vv...el6>R>RwwgLwAAAr*   c                    |rt          j        d|          nt          j        d          }|                     ||          S )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.
        hpurJ   rK   rN   s       r(   rQ   z_StorageBase.hpuh   s?     28P%,uf---U\%=P=PwwgLwAAAr*   c                    t           r"   r-   r/   s    r(   element_sizez_StorageBase.element_sizew   r1   r*   c                    | j         j        S r"   )r   indexr/   s    r(   
get_devicez_StorageBase.get_devicez   s    {  r*   c                    t           r"   r-   r/   s    r(   data_ptrz_StorageBase.data_ptr}   r1   r*   c                    t           r"   r-   r/   s    r(   	resizablez_StorageBase.resizable   r1   r*   c                    t           r"   r-   r$   s      r(   _share_filename_cpu_z!_StorageBase._share_filename_cpu_   r1   r*   c                    t           r"   r-   r$   s      r(   _share_fd_cpu_z_StorageBase._share_fd_cpu_   r1   r*   clsType[T]rC   c                    t           r"   r-   r_   rC   s     r(   _new_using_filename_cpuz$_StorageBase._new_using_filename_cpu       !!r*   c                    t           r"   r-   rb   s     r(   _new_using_fd_cpuz_StorageBase._new_using_fd_cpu   rd   r*   c                    t           r"   r-   r_   r&   r'   s      r(   from_bufferz_StorageBase.from_buffer   rd   r*   )r   rD   c                   t           r"   r-   )r_   managerobjrC   r   rD   s         r(   _new_shared_filename_cpuz%_StorageBase._new_shared_filename_cpu   s
     "!r*   c                    t           r"   r-   rh   s      r(   _release_ipc_counter_cudaz&_StorageBase._release_ipc_counter_cuda   rd   r*   c                    t           r"   r-   rh   s      r(   _new_with_weak_ptrz_StorageBase._new_with_weak_ptr   rd   r*   c                    t           r"   r-   r/   s    r(   _shared_decrefz_StorageBase._shared_decref   r1   r*   c                    t           r"   r-   r$   s      r(   _write_filez_StorageBase._write_file   r1   r*   c                    t           r"   r-   r%   rC   s     r(   resize_z_StorageBase.resize_   r1   r*   c                    t           r"   r-   r$   s      r(   	_weak_refz_StorageBase._weak_ref   r1   r*   c                    t           r"   r-   r$   s      r(   _set_from_filez_StorageBase._set_from_file   r1   r*   c                    t           r"   r-   r$   s      r(   
_set_cdataz_StorageBase._set_cdata   r1   r*   c                    t           r"   r-   r$   s      r(   _share_cuda_z_StorageBase._share_cuda_   r1   r*   c                    t           r"   r-   r/   s    r(   	is_sharedz_StorageBase.is_shared   r1   r*   c                    t           r"   r-   rh   s      r(   _new_shared_cudaz_StorageBase._new_shared_cuda   rd   r*   c                    t           r"   r-   r$   s      r(   _shared_increfz_StorageBase._shared_incref   r1   r*   c                    t           r"   r-   rh   s      r(   _free_weak_refz_StorageBase._free_weak_ref   rd   r*   c                    t           r"   r-   r/   s    r(   is_cudaz_StorageBase.is_cuda   rd   r*   c                    t           r"   r-   r/   s    r(   is_hpuz_StorageBase.is_hpu   rd   r*   c                    t           r"   r-   )r_   filenamesharedrA   s       r(   	from_filez_StorageBase.from_file   rd   r*   c                    t           r"   r-   rh   s      r(   _expiredz_StorageBase._expired   rd   r*   c                    t           r"   r-   r$   s      r(   	_byteswapz_StorageBase._byteswap   r1   r*   c                    t           r"   r-   r$   s      r(   _get_filenamez_StorageBase._get_filename   r1   r*   c                $    dt          j                    d j         dt                      d} j        j        dk    rd|z   S dd                     fd	t                                                     D                       z   }|d
z   |z   S )N[z(device=
) of size ]meta...
 
 c              3  B   K   | ]}t          |                   V  d S r"   str.0ir%   s     r(   	<genexpr>z(_StorageBase.__repr__.<locals>.<genexpr>   s-      #M#MQCQLL#M#M#M#M#M#Mr*   
)rL   typenamer   lenrG   joinrangerC   r%   info_strdata_strs   `  r(   __repr__z_StorageBase.__repr__   s    Xu~d++XXT[XXCPTIIXXX;v%%X%%#M#M#M#M%		:L:L#M#M#MMMM$))r*   c                x     t           fdt                                                     D                       S )Nc              3  (   K   | ]}|         V  d S r"   r#   r   s     r(   r   z(_StorageBase.__iter__.<locals>.<genexpr>   '      88DG888888r*   )iterr   rC   r/   s   `r(   __iter__z_StorageBase.__iter__   s6    8888U499;;%7%7888888r*   c                *    |                                  S r"   )cloner/   s    r(   __copy__z_StorageBase.__copy__   s    zz||r*   c                    |                     di           }| j        |v r|| j                 S |                                 }||| j        <   |S )NrL   )
setdefaultr   r   )r%   memonew_storages      r(   __deepcopy__z_StorageBase.__deepcopy__   sN    w++;$$$jjll'T[r*   c                    t          j                    }t          j        | |d           t          |                                ffS NF)_use_new_zipfile_serializationioBytesIOrL   save_load_from_bytesgetvaluer%   bs     r(   
__reduce__z_StorageBase.__reduce__   9    JLL
45AAAA 1::<</22r*   c                n    t                                                      |                                 z   S r"   )super
__sizeof__rC   r%   	__class__s    r(   r   z_StorageBase.__sizeof__   s&    ww!!##diikk11r*   c                     t          |           |                                 | j                                      |           S )Return a copy of this storage.r   )rG   rA   r   r=   r/   s    r(   r   z_StorageBase.clone   s5    tDzz$++--<<<BB4HHHr*   c                     t          |           S z6Return a list containing the elements of this storage.)listr/   s    r(   tolistz_StorageBase.tolist  s    Dzzr*   c                    | j         j        dk    r:t          j        |                                                               | d          S | S )AReturn a CPU copy of this storage if it's not already on the CPU.cpuFr   rG   rL   r   rC   r=   r/   s    r(   r   z_StorageBase.cpu  s@    ;u$$'		44::4GGGr*   c                    | j         j        dk    r<t          j        |                                 d                              | d          S | S )zAReturn a MPS copy of this storage if it's not already on the MPS.mpsr   Fr   r/   s    r(   r   z_StorageBase.mps  sE    ;u$$'		EBBBHHuUUUr*   c                   t          |t          j                  st          dt	          |                     t          j        g t          j        | j                                      t          t          |                                         |                                          }|                                |                                 k    r|                                }|S Nz*Argument 'dtype' must be torch.dtype, not rD   r   )
isinstancerL   rD   	TypeErrorrG   tensoruint8r   set_r   r   rM   _typed_storagerX   r   r%   rD   storages      r(   r   z_StorageBase._to  s    %-- 	XVeVVWWWL5;t{CCCT$w%%&&RYY^	 	 00mmooGr*   r9   r   c                   t          |t          j                  st          j        |          }t          | ||          S r"   )r   rL   r   r   )r%   r   r9   s      r(   rM   z_StorageBase.to!  s7    &%,// 	*\&))F4...r*   c                @    |                      t          j                  S z"Casts this storage to double type.)r   rL   doubler/   s    r(   r   z_StorageBase.double&      xx%%%r*   c                @    |                      t          j                  S z!Casts this storage to float type.)r   rL   floatr/   s    r(   r   z_StorageBase.float*      xx$$$r*   c                @    |                      t          j                  S z Casts this storage to half type.)r   rL   halfr/   s    r(   r   z_StorageBase.half.      xx
###r*   c                @    |                      t          j                  S z Casts this storage to long type.)r   rL   longr/   s    r(   r   z_StorageBase.long2  r   r*   c                @    |                      t          j                  S zCasts this storage to int type.)r   rL   intr/   s    r(   r   z_StorageBase.int6  s    xx	"""r*   c                @    |                      t          j                  S z!Casts this storage to short type.)r   rL   shortr/   s    r(   r   z_StorageBase.short:  r   r*   c                @    |                      t          j                  S z Casts this storage to char type.)r   rL   int8r/   s    r(   charz_StorageBase.char>  r   r*   c                @    |                      t          j                  S z Casts this storage to byte type.)r   rL   r   r/   s    r(   bytez_StorageBase.byteB  r   r*   c                @    |                      t          j                  S z Casts this storage to bool type.)r   rL   boolr/   s    r(   r  z_StorageBase.boolF  r   r*   c                @    |                      t          j                  S z$Casts this storage to bfloat16 type.)r   rL   bfloat16r/   s    r(   r	  z_StorageBase.bfloat16J  s    xx'''r*   c                @    |                      t          j                  S z*Casts this storage to complex double type.)r   rL   cdoubler/   s    r(   complex_doublez_StorageBase.complex_doubleN  s    xx&&&r*   c                @    |                      t          j                  S z)Casts this storage to complex float type.)r   rL   cfloatr/   s    r(   complex_floatz_StorageBase.complex_floatR  r   r*   c                @    |                      t          j                  S z&Casts this storage to float8_e5m2 type)r   rL   float8_e5m2r/   s    r(   r  z_StorageBase.float8_e5m2V  s    xx)***r*   c                @    |                      t          j                  S z(Casts this storage to float8_e4m3fn type)r   rL   float8_e4m3fnr/   s    r(   r  z_StorageBase.float8_e4m3fnZ  s    xx+,,,r*   c                @    |                      t          j                  S z*Casts this storage to float8_e5m2fnuz type)r   rL   float8_e5m2fnuzr/   s    r(   r  z_StorageBase.float8_e5m2fnuz^      xx-...r*   c                @    |                      t          j                  S z*Casts this storage to float8_e4m3fnuz type)r   rL   float8_e4m3fnuzr/   s    r(   r  z_StorageBase.float8_e4m3fnuzb  r  r*   rI   Union[str, torch.device]c                    t          j        g t           j        | j                                      t          t          |                                         |          S )zDetermine 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   )rL   r   r   r   r   r   r   	is_pinnedr%   r   s     r(   r!  z_StorageBase.is_pinnedf  sE     L5;t{CCCT$w%%&&Yv	
r*   c                R   | j         j        dk    r%t          d|                                  d          t          j        g t          j        | j                                       t          t          |                     	                    |          }|
                                S )zCopy 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   )r   rG   r   rL   r   r   r   r   r   
pin_memoryuntyped_storage)r%   r   pinned_tensors      r(   r$  z_StorageBase.pin_memoryu  s     ;u$$W499;;WWWXXX L5;t{CCCT$w%%&&Z 	
 ,,...r*   c                    ddl m} | j        j        dt          j                                        fv rn7 |            dk    r|                                  n|                                  | S ).See :meth:`torch.UntypedStorage.share_memory_`r   get_sharing_strategyrI   file_system)	torch.multiprocessingr*  r   rG   rL   _C_get_privateuse1_backend_namer\   r^   )r%   r*  s     r(   share_memory_z_StorageBase.share_memory_  sz    >>>>>>;(N(N(P(PQQQ!!##}44%%''''!!!r*   r   r   c                  ddl m} t          j        |          }|j        dt          j                                        dfv r | ||          S  |            dk    r|                     |          S |                     |          S )>Create a new storage in shared memory with the same data type.r   r)  rI   rQ   r   r+  )	r,  r*  rL   r   rG   r-  r.  rc   rf   )r_   rC   r   r*  s       r(   _new_sharedz_StorageBase._new_shared  s     	?>>>>>f%%;658#I#I#K#KUSSS3tF++++!!##}44..t444((...r*   c                    | S r"   r#   r/   s    r(   untypedz_StorageBase.untyped  s    r*   c                    t           j                            |          }|j        r t	          t          |dz            d          }|                     |           dS )zSwap bytes in underlying data.      N)rL   _utils_element_size
is_complexmaxr   r   )r%   rD   	elem_sizes      r(   byteswapz_StorageBase.byteswap  sU    L..u55	 	3C	A..22Iy!!!!!r*   r+   r   r"   )r8   r   r9   r:   r+   r   )r+   r   NF)rD   rE   r9   r   r+   r   )r+   r   )r_   r`   rC   r   r+   r   )r_   r`   r+   r   )rC   r   r+   rE   )r   r   r9   r   rI   r   r  )T__name__
__module____qualname____annotations__r   r   r    r)   r0   r5   r7   r=   r?   rA   rC   rG   rI   rQ   rS   rV   rX   rZ   r\   r^   classmethodrc   rf   ri   rm   ro   rq   rs   ru   rx   rz   r|   r~   r   r   r   r   r   propertyr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rM   r   r   r   r   r   r   r   r  r  r	  r  r  r  r  r  r  r!  r$  r/  r2  r4  r=  __classcell__r   s   @r(   r   r   2   s]        KKKI M    ,0L0000  " " " "" " "" " "" " " " "" " " "" " " "    CH0 0 0 0 0 ).B B B B B"B B B B B" " " "! ! ! !" " " "" " " "" " "" " " " " " [" " " " [" " " " ["  	" 	" 	" 	" 	" [	" " " " [" " " " ["" " " "" " "" " " "" " " "" " "" " "" " "" " " " " " " ["" " " " " [" " " X" " " X" " " " [" " " " ["" " "" " " "* * *9 9 9    3 3 3
2 2 2 2 2I I I         CH / / / / / /
& & &% % %$ $ $$ $ $# # #% % %$ $ $% % %$ $ $( ( (' ' '& & &+ + +- - -/ / // / /
 
 
 
 
/ / / / /&
 
 
 ). 
/ 
/ 
/ 
/ [
/  " " " " " " "r*   r   c                F     t          j                    fd            }|S )Nc                   d }d }t           5  | j        }|t          v rt          |         }n<t          j                    t          |<   t          |                                          |}d d d            n# 1 swxY w Y   ||5  	 d d d            n# 1 swxY w Y   	  | g|R i ||T| j        |k    sJ t           5  t          |                                          t          |= d d d            S # 1 swxY w Y   S S # |T| j        |k    sJ t           5  t          |                                          t          |= d d d            w # 1 swxY w Y   w w xY wr"   )_share_memory_lockr   r   	threadingRLockacquirerelease)r%   r&   r'   to_freeto_waitkeyfns         r(   wrapperz-_share_memory_lock_protected.<locals>.wrapper  s    	 	+C'''+C0)2):):!#&!#&..000	 	 	 	 	 	 	 	 	 	 	 	 	 	 	                 	32d,T,,,V,, " {g----' 3 3%g.66888)'23 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3	 #w" {g----' 3 3%g.66888)'23 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3	 #sf   AA44A8;A8BBBC? >(C22C6	9C6	?E(E
>E
EEEE)	functoolswraps)rU  rV  s   ` r(   _share_memory_lock_protectedrY    s8    _R3 3 3 3 3> Nr*   c                       e Zd Z fdZed             Zed             Zed
d            Ze fd            Z	e fd            Z
e fd	            Z xZS )r   c                t    | j         j        dk    rt          d           t                      j        |i |S )Nr   $Not available for 'meta' device type)r   rG   r.   r   r5   r%   r&   r'   r   s      r(   r5   zUntypedStorage.__getitem__  s>    ;v%%%&LMMM"uww"D3F333r*   c                "    | j         j        dk    S NrI   r   rG   r/   s    r(   r   zUntypedStorage.is_cuda  s    {6))r*   c                "    | j         j        dk    S NrQ   r`  r/   s    r(   r   zUntypedStorage.is_hpu  s    {5((r*   r+   rE   c                *    |                                  S )zReturns 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.
        )r   r/   s    r(   r   zUntypedStorage.filename  s     !!###r*   c                6     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]  s      r(   r/  zUntypedStorage.share_memory_  s"    B %uww$d5f555r*   c                6     t                      j        |i |S r"   )r   r^   r]  s      r(   r^   zUntypedStorage._share_fd_cpu_  s    %uww%t6v666r*   c                6     t                      j        |i |S r"   )r   r\   r]  s      r(   r\   z#UntypedStorage._share_filename_cpu_  s    +uww+T<V<<<r*   r@  )rC  rD  rE  r5   rH  r   r   r   rY  r/  r^   r\   rI  rJ  s   @r(   r   r     s       4 4 4 4 4
 * * X* ) ) X) $ $ $ X$ " 6  6  6  6 "! 6D "7 7 7 7 "!7 "= = = = "!= = = = =r*   c                R    t          j        t          j        |           d          S )NF)weights_only)rL   loadr   r   )r   s    r(   r   r     s    :bjmm%8888r*   )maxsizec                 $   t           j        t           j        t           j        t           j        t           j        t           j        t           j        t           j        t           j	        t           j
        t           j        t           j        t           j        hS r"   )rL   r  r  r  r  bits8bits16bits1x8bits2x4bits4x2	complex32uint16uint32uint64r#   r*   r(   _new_dtypesru    sS    
 	 r*   c                    i t           j        dt           j        dt           j        dt           j        dt           j        dt           j        dt           j        dt           j        dt           j	        d	t           j
        d
t           j        dt           j        dt           j        dt           j        dt           j        dt           j        dt           j        dS )NDoubleStorageFloatStorageHalfStorageLongStorage
IntStorageShortStorageCharStorageByteStorageBoolStorageBFloat16StorageComplexDoubleStorageComplexFloatStorageQInt8StorageQInt32StorageQUInt8StorageQUInt4x2StorageQUInt2x4Storage)rL   r   r   r   r   r   int16r   r   r  r	  r  r  qint8qint32quint8quint4x2quint2x4r#   r*   r(   _dtype_to_storage_type_mapr  -  s    o^ 	
M 	
M	
 		< 	^ 	
M 	] 	
M 	) 	- 	+ 	^ 	o 	o  	)!" 	)# r*   c                 Z    d t                                                      D             } | S )Nc                    i | ]\  }}||	S r#   r#   )r   rT  vals      r(   
<dictcomp>z._storage_type_to_dtype_map.<locals>.<dictcomp>K  s    OOOhc3cOOOr*   )r  items)	dtype_maps    r(   _storage_type_to_dtype_mapr  I  s.    OO*D*F*F*L*L*N*NOOOIr*   c           
        |t           j        t           j        t           j        t           j        t           j        fv rt           j        t           j        t           j        t           j        t           j        t           j        t           j        t           j        t           j        t           j        i}t          j	        | ||         |          }nt          j	        | ||          }|
                                j        S )Nr   )rL   r  r  r  r  r  r   int32r   r   r   _untyped_storage)sequencerD   r   interpret_dtypes
tmp_tensors        r(   _get_storage_from_sequencer  O  s       L%+NEKNEKL%+K
 \,U3F
 
 



 \(%GGG
$$&&77r*   c                |    t           r!t          | t          t          j        f          S t          | t                    S r"   )	HAS_NUMPYr   r   npinteger)xs    r(   _isintr  h  s1     "!c2:.///!S!!!r*   c                     t           S r"   )"_always_warn_typed_storage_removalr#   r*   r(   &_get_always_warn_typed_storage_removalr  r  s    --r*   c                8    t          | t                    sJ | ad S r"   )r   r  r  )always_warns    r(   &_set_always_warn_typed_storage_removalr  v  s$    k4((((()4&&&r*   r6  c                    d }t                      s
 |            r2d}t          j        |t          | dz              dt          j        d<   d S d S )Nc                 V    t          t          d          sdS t          j        d          S )N
has_warnedT)hasattr_warn_typed_storage_removal__dict__r#   r*   r(   is_first_timez2_warn_typed_storage_removal.<locals>.is_first_time  s,    2LAA 	J42;LIIIr*   a  TypedStorage 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()r7  )
stacklevelTr  )r  warningswarnUserWarningr  r  )r  r  messages      r(   r  r  |  s{    J J J .// B==?? BQ 	 	g{zA~FFFF=A#,\:::B Br*   c                 $    dt           j        d<   d S )NFr  )r  r  r#   r*   r(   !_reset_warn_typed_storage_removalr    s    9>(666r*   moduler   c                    |                      dd          d         }|dt          j                                        dfv r|S dS )N.r7  rI   rQ   r   )rsplitrL   r-  r.  )r  	last_parts     r(   _get_device_from_moduler    sE    c1%%b)IVUXCCEEuMMMur*   c                  |    e Zd ZU dZded<   dZded<   ded<   ed	             Zedtd            Zd Z	ddddd fd
Z
ddddddZed             Zed             Zd ZdudZd ZdvdZd Zd Zd Zd Zdwdxd!Zd" Zd# Z	 	 dydzd&Zdydud'Zdydud(Zdd)d{d,Zd- Zd. Zd|d0Zd1 Z d2 Z!d3 Z"d4 Z#d5 Z$d6 Z% fd7Z&d8 Z'd9 Z(d: Z)d}d~d=Z*d}d~d>Z+d? Z,d@ Z-ddAdBZ.edC             Z/edD             Z0dE Z1dF Z2dG Z3dH Z4dI Z5dJ Z6dK Z7dL Z8dM Z9dN Z:e;dO             Z<dP Z=e;dQ             Z>e;dddRdS            Z?dT Z@dU ZAdV ZBdW ZCdX ZDdY ZEdZ ZFd[ ZGd\ ZHd] ZId^ ZJd_ ZKd` ZLda ZMdb ZNdc ZOdd ZPe;de             ZQe;df             ZRdg ZSdh ZTdi ZUdj ZVdk ZWdl ZXe;dm             ZYdn ZZdo Z[e;ddAdp            Z\dq Z]dr Z^ds Z_ xZ`S )r   Fr   r   Nr   r    torch.dtyperD   c                    | j         S r"   )rD   r/   s    r(   _dtypezTypedStorage._dtype  s
    zr*   r+   rE   c                    | j         j        S )zReturns 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.)r  r   r/   s    r(   r   zTypedStorage.filename  s     $--r*   c                    t                       |                     t          d|                                           |           | S )Nr   )r  _setitemslice_size)r%   values     r(   fill_zTypedStorage.fill_  s9    #%%%eAtzz||,,e444r*   )wrap_storagerD   r   	_internalc                  |st                       | t          j        j        k    rt	          d          | t
          k    r!t                                          |           S |  d}|t	          |dz             |t	          |dz             |t          |          dk    rt	          |dz             t          |          dk    rbt          |d                   sMt          |d         t          j        j                  s(t          |dt          |d                    z             t          || j        t#          | j                  d	d
S t          |          dk    rt	          |dz             t          |t          j                  s"t          |dt          |           z             t#          | j                  }|j        j        |k    r"t	          |d| d|j        j         z             t          ||| j        d	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 specifiedr7  
Too many positional argumentsr   
Argument type not recognized: T)rD   r   r  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 r  rD   r  )r  rL   r   _LegacyStorageRuntimeErrorr   r   __new__r   r  r   collectionsabcSequencer   rG   r  r  rD  r   r   rD   )	r_   r  rD   r   r  r&   arg_error_msg
cls_devicer   s	           r(   r  zTypedStorage.__new__  s     	*')))%-...J   ,77??3'''  6 6 6  !"!$UU    "!$TT   #t99q==&%(II  
 IINN"47OO #&tAw0HII # $%LT$q']]LLM  
 $*23>BB"	    t99>>&%))   ",0DEE #%kW[\hWiWikkl  
 5S^DD
&+z99&%@
 @ @%1%8%=@ @@   $!-)"	   r*   )r   rD   r  r  c               ,   |st                       d}|t          |          dk    rt          |dz             |t          |dz             t          |t          j                  s"t          |dt          |           z             |t          |dz             || _        t          |t          j                  s"t          |dt          |           z             || _	        d S |t	          j
                    n|| _        t	          j        |dn|          }| j        t          j        t          j        t          j        t          j        t          j        fv r|j        d	k    rt          d
          t          |          dk    rt	          j        |          | _	        d S t          |          dk    rt#          |d                   rEt	          j        t%          |d                   |                                 z  |          | _	        d S t          |d         t(          j        j                  r#t/          |d         | j        |          | _	        d S t          |dt          |d                    z             t          |dz             )Na1  TypedStorage.__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)r   r  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   rI   /Cannot create CUDA storage with quantized dtyper   r7  r  r  )r  r   r  r   rL   rD   r   rG   r   r  get_default_dtyper   r  r  r  r  r  r  r   r9  r  r  r  r  )r%   r   rD   r  r  r&   r  s          r(   r)   zTypedStorage.__init__  s     	*')))E 	 #4yyA~~"!%%   }"!$JJ   eU[11 !RT%[[RRS  
 !"!`a  
 DJlE,@AA !gSWXdSeSeggh  
 %1D!!! 7<m0222DJ\6>%%vFFFz   ;&((&I   4yyA~~(-(<F(K(K(K%%%Ta$q'?? ,1,@DGt'9'9';';;F- - -D)))  Q)ABB ,FQV- -D))) $%LT$q']]LLM   #=3T#TUUUr*   c                H    t                       | j        j        j        dk    S r_  r  r  r   rG   r/   s    r(   r   zTypedStorage.is_cudai  s"    #%%%$+0F::r*   c                H    t                       | j        j        j        dk    S rb  r  r/   s    r(   r   zTypedStorage.is_hpun  s"    #%%%$+0E99r*   c                ,    t                       | j        S )z2Return the internal :class:`torch.UntypedStorage`.)r  r  r/   s    r(   r4  zTypedStorage.untypeds  s    #%%%$$r*   r   c                    t          |          t          j        k    sJ t          |           t          k    r*t	          t
          t          || j        d                    S  t          |           |          S )NTr  r  )rG   rL   r   r   r   r   rD   )r%   r%  s     r(   _new_wrapped_storagez!TypedStorage._new_wrapped_storagex  sz    O$$(<<<<<::%%!0
d     4::?;;;;r*   c                F    t                       |                                 S r"   r  r  r/   s    r(   r0   zTypedStorage.__len__      #%%%zz||r*   c                   ||r|                                  S dS t          |          t          k    r/t          dt          |            dt          |                     |rw||                                  k    s||                                   k     r't	          d| d|                                            |dk    r|S ||                                  z  S ||                                  k    s||                                   k     r't	          d| d|                                            ||                                  z  S )Nr   can't index a  with zindex z" out of range for storage of size )r  rG   r   r   
IndexErrorrC   )r%   r4   is_stops      r(   _maybe_wrap_indexzTypedStorage._maybe_wrap_index  sH   ; zz||#q CyyC Nd N N499 N NOOO *$**,,&&C4::<<-,?,?$UUU		UU   77J--4::<<''SDJJLL=-@-@$UUU		UU   TZZ\\))r*   c                J    t                       |                     ||          S r"   )r  r  )r%   r4   r  s      r(   r7   zTypedStorage.__setitem__  s"    #%%%}}S%(((r*   c           
        t          |t          t          f          s/t          dt	          |            dt	          |                     t          j        |          rt          dt	          |                     | j        t
          j        t
          j	        t
          j
        t
          j        t
          j        fv rt
          j        t
          j        t
          j	        t
          j        t
          j
        t
          j        t
          j        t
          j        t
          j        t
          j        i}|| j                 }t          j        g || j        j                  }|                    t)          | j        |d                     n9t          j        g | j        | j        j                                      |           }|||<   d S )Nr  r  z cannot set item with value type r   Tr  )r   r   r  r  rG   rL   
is_storagerD   r  r  r  r  r  r   r  r   r   r  r   r   r   )r%   r4   r  r  	tmp_dtyper  s         r(   r  zTypedStorage._setitem  s   #U|,, 	OMT

MM$s))MMNNNE"" 	QO$u++OOPPP:LNNLK
 
 
 ekekUZ  )4I)D,A,H  J OO!%!6iSW      $*T-B-I  d4jj   
3r*   c                H    t                       |                     |          S r"   )r  _getitemr3   s     r(   r5   zTypedStorage.__getitem__  s     #%%%}}S!!!r*   c           
        | j         j        j        dk    rt          d          t	          |t
                    rt          d          t	          |t                    s/t          dt          |            dt          |                     | j        t          j
        t          j        t          j        t          j        t          j        fv rt          j
        t          j        t          j        t          j        t          j        t          j        t          j        t          j        t          j        t          j        i}t%          | j         || j                 d                              |          S |                     |          }dd	lm}  |            5  t          j        g | j        | j         j        
                              |           }||                                         cd d d            S # 1 swxY w Y   d S )Nr   r\  z7slices are only supported in UntypedStorage.__getitem__r  r  Tr  r   )unset_fake_temporarilyr   )r  r   rG   r.   r   r  r  r   rD   rL   r  r  r  r  r  r   r  r   r   r  r  torch._subclasses.fake_tensorr  r   r   item)r%   r4   r  idx_wrappedr  r  s         r(   r  zTypedStorage._getitem  s    ',66%&LMMM c5!! 	OI   C%% 	OMT

MM$s))MMNNN:LNNLK
 
 
 ekekUZ   !2&tz2   hsmm	 ,,S11HHHHHH##%% 	2 	2$*T-B-I  d4jj  k*//11		2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2s   AG77G;>G;r8   r   r9   _Optional[bool]c                    t                       t          |t                    r!| j                            |j        |           n| j                            ||           | S r"   )r  r   r   r  r=   r<   s      r(   r=   zTypedStorage.copy_  s]    #%%%fl++ 	>!''(?NNNN!''===r*   c                F    t                       |                                 S r"   )r  _nbytesr/   s    r(   rA   zTypedStorage.nbytes  s    #%%%||~~r*   c                4    | j                                         S r"   )r  rA   r/   s    r(   r  zTypedStorage._nbytes  s    $++---r*   r  &Union[_StorageBase, TypedStorage, str]c                   t                       |V|                                 }||j        dz   |j        z   S d                    | j        t          |           j        g          S | j                            ||          S )Nr  )r  _get_legacy_storage_classrD  rC  r   rG   r  )r%   rD   r9   legacy_classs       r(   rG   zTypedStorage.type
  s    
 	$%%%=99;;L'#.4|7LLL88T_d4jj.ABCCC (--e\BBBr*   c                   t                       | j        t          j        t          j        t          j        t          j        t          j        fv rt          d          | j	        
                    ||          }|                     |          S )Nr  )r  rD   rL   r  r  r  r  r  r  r  rI   r  )r%   r   r9   cuda_storages       r(   rI   zTypedStorage.cuda  sx    #%%%:LNNLK
 
 
 PQQQ,11&,GG((666r*   c                   t                       | j        t          j        t          j        t          j        t          j        t          j        fv rt          d          | j	        
                    ||          }|                     |          S )Nz.Cannot create HPU storage with quantized dtype)r  rD   rL   r  r  r  r  r  r  r  rQ   r  )r%   r   r9   hpu_storages       r(   rQ   zTypedStorage.hpu(  sx    #%%%:LNNLK
 
 
 OPPP+//EE((555r*   r   r   r   c                  t                       t          |t          j                  st          j        |          }| j        t          j        t          j        t          j        t          j        t          j	        fv r*t          d|j                                         d          | j                            ||          }|                     |          S )NzCannot create z storage with quantized dtyperJ   )r  r   rL   r   rD   r  r  r  r  r  r  rG   upperr  rM   r  )r%   r   r9   
to_storages       r(   rM   zTypedStorage.to5  s    #%%%&%,// 	*\&))F:LNNLK
 
 
 S!2!2!4!4SSS   *--V,-WW
((444r*   c                F    t                       |                                 S r"   )r  r9  r/   s    r(   rS   zTypedStorage.element_sizeF  s     #%%%!!###r*   c                J    t           j                            | j                  S r"   )rL   r8  r9  rD   r/   s    r(   r9  zTypedStorage._element_sizeK  s    |))$*555r*   r   c                P    t                       | j                                        S r"   )r  r  rV   r/   s    r(   rV   zTypedStorage.get_deviceN  s#    #%%%$//111r*   c           
     P    t                       dt          j                    d j         d j         dt                      d	} j        j        dk    rd|z   S dd	                     fd
t           	                                          D                       z   }|dz   |z   S )Nr   z(dtype=z	, device=r   r   r   r   r   r   c              3  B   K   | ]}t          |                   V  d S r"   r   r   s     r(   r   z'TypedStorage.__str__.<locals>.<genexpr>[  s-      'Q'QDG'Q'Q'Q'Q'Q'Qr*   r   )
r  rL   r   rD   r   r   rG   r   r   rC   r   s   `  r(   __str__zTypedStorage.__str__R  s    #%%%:t$$ : :TZ : :k: :-0YY: : : 	 ;v%%X%%UZZ'Q'Q'Q'QeDIIKK>P>P'Q'Q'QQQQHd?X--r*   c                <    t                       t          |           S r"   )r  r   r/   s    r(   r   zTypedStorage.__repr__^  s    #%%%4yyr*   c                     t                       t           fdt                                                     D                       S )Nc              3  (   K   | ]}|         V  d S r"   r#   r   s     r(   r   z(TypedStorage.__iter__.<locals>.<genexpr>d  r   r*   )r  r   r   rC   r/   s   `r(   r   zTypedStorage.__iter__b  sB    #%%%8888U499;;%7%7888888r*   c                v    t                       |                     t          j        | j                            S r"   )r  r  copyr  r/   s    r(   r   zTypedStorage.__copy__f  s/    #%%%((43H)I)IJJJr*   c                H    t                       |                     |          S r"   )r  	_deepcopyr%   r   s     r(   r   zTypedStorage.__deepcopy__j  s     #%%%~~d###r*   c                \    |                      t          j        | j        |                    S r"   )r  r  deepcopyr  r  s     r(   r  zTypedStorage._deepcopyo  s%    ((t7Ld)S)STTTr*   c                    t                       t                                                      |                                 z   S r"   )r  r   r   rA   r   s    r(   r   zTypedStorage.__sizeof__r  s2    #%%%ww!!##dkkmm33r*   c                v    t                       |                     | j                                                  S )r   )r  r  r  r   r/   s    r(   r   zTypedStorage.clonev  s1    #%%%(()>)D)D)F)FGGGr*   c                <    t                       t          |           S r   )r  r   r/   s    r(   r   zTypedStorage.tolist{  s    #%%%Dzzr*   c                v    t                       |                     | j                                                  S )r   )r  r  r  r   r/   s    r(   r   zTypedStorage.cpu  s1    #%%%(()>)B)B)D)DEEEr*   rI   r  c                R    t                       | j                            |          S )zDetermine 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.
        )r  r  r!  r"  s     r(   r!  zTypedStorage.is_pinned  s'     	$%%%$..v666r*   c                z    t                       |                     | j                            |                    S )zCopy 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   )r  r  r  r$  r"  s     r(   r$  zTypedStorage.pin_memory  s?     	$%%%((!,,F,;;
 
 	
r*   c                F    t                       |                                 S )r(  )r  _share_memory_r/   s    r(   r/  zTypedStorage.share_memory_  s     #%%%""$$$r*   c                8    | j                                          | S r"   )r  r/  r/   s    r(   r  zTypedStorage._share_memory_  s    ++---r*   r   c                   |d}t          j        |          }t           j                            ||                                 z  |          }t          || j        d          S )r1  Nr   r   Tr  )rL   r   r   r2  r9  r   rD   )r%   rC   r   r%  s       r(   r2  zTypedStorage._new_shared  sp    >Ff%%.::4%%''' ; 
 
 (
d
 
 
 	
r*   c                    | j         j        S r"   )r  r   r/   s    r(   r   zTypedStorage._cdata  s    $++r*   c                6    t                       | j        j        S r"   )r  r  r   r/   s    r(   r   zTypedStorage.device  s    #%%%$++r*   c                F    t                       |                                 S r"   r  r/   s    r(   rC   zTypedStorage.size  r  r*   c                ^    | j                                         |                                 z  S r"   )r  rA   r9  r/   s    r(   r  zTypedStorage._size  s*     $++--1C1C1E1EEEr*   c                F    t                       |                                 S r"   )r  _pickle_storage_typer/   s    r(   pickle_storage_typez TypedStorage.pickle_storage_type  s     #%%%((***r*   c                    	 t                      | j                 S # t          $ r}t          d| j         d          |d }~ww xY w)Nzdtype z is not recognized)r  rD   KeyError)r%   es     r(   r&  z!TypedStorage._pickle_storage_type  s\    	K-//
;; 	K 	K 	KBDJBBBCCJ	Ks    
A>Ac                    t          j                    }t          j        | |d           t          |                                ffS r   r   r   s     r(   r   zTypedStorage.__reduce__  r   r*   c                F    t                       |                                 S r"   )r  	_data_ptrr/   s    r(   rX   zTypedStorage.data_ptr  s    #%%%~~r*   c                4    | j                                         S r"   )r  rX   r/   s    r(   r-  zTypedStorage._data_ptr  s    $--///r*   c                P    t                       | j                                        S r"   )r  r  rZ   r/   s    r(   rZ   zTypedStorage.resizable  s#    #%%%$..000r*   c                L    t                       |                     |           d S r"   )r  _resize_rw   s     r(   rx   zTypedStorage.resize_  s&    #%%%dr*   c                d    | j                             ||                                 z             d S r"   )r  rx   r9  rw   s     r(   r1  zTypedStorage._resize_  s0    %%dT-?-?-A-A&ABBBBBr*   c                $    t          j        |i |S r"   )r   r   rh   s      r(   r   zTypedStorage._free_weak_ref  s    ,d=f===r*   c                &     | j         j        |i |S r"   )r  rz   r$   s      r(   rz   zTypedStorage._weak_ref  s    .t$.????r*   c                8    t                        | j        |i |S r"   )r  _from_bufferrh   s      r(   ri   zTypedStorage.from_buffer  s&    #%%%s0000r*   r   c                  | t           k    rj|t          j                    n|}t          j        |dn|          }|j        dk    rt          d|j                   t          j        j        |d|i|}nT|t          |          dk    rt          d          |t          d          | j	        }t          j        j        |d|i|}t          ||d          S )	Nr   z3TypedStorage.from_buffer: Not available for device rD      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  )
r   rL   r  r   rG   r  r   ri   r   r  )r_   rD   r   r&   r'   r%  s         r(   r6  zTypedStorage._from_buffer  s*   ,16E+---EE\6>%%vFFF{e##"W&+WW   5:4H4T5"5&,5 5OO
  CIINN"N   !"N  
 JE#2>"&, O QUVVVVr*   c                   t          |t          j                  st          dt	          |                     t          j        g | j        | j                                      |                               |          	                                }|
                                | 
                                k    r|                                }|S r   )r   rL   rD   r   rG   r   r   r   rM   r   rX   r   r   s      r(   r   zTypedStorage._to  s    %-- 	XVeVVWWWL4:dkBBBT$ZZRYY^	 	 00mmooGr*   c                \    t                       |                     t          j                  S r   )r  r   rL   r   r/   s    r(   r   zTypedStorage.double%  "    #%%%xx%%%r*   c                \    t                       |                     t          j                  S r   )r  r   rL   r   r/   s    r(   r   zTypedStorage.float*  "    #%%%xx$$$r*   c                \    t                       |                     t          j                  S r   )r  r   rL   r   r/   s    r(   r   zTypedStorage.half/  "    #%%%xx
###r*   c                \    t                       |                     t          j                  S r   )r  r   rL   r   r/   s    r(   r   zTypedStorage.long4  r?  r*   c                \    t                       |                     t          j                  S r   )r  r   rL   r   r/   s    r(   r   zTypedStorage.int9  s"    #%%%xx	"""r*   c                \    t                       |                     t          j                  S r   )r  r   rL   r   r/   s    r(   r   zTypedStorage.short>  r=  r*   c                \    t                       |                     t          j                  S r   )r  r   rL   r   r/   s    r(   r   zTypedStorage.charC  r?  r*   c                \    t                       |                     t          j                  S r  )r  r   rL   r   r/   s    r(   r  zTypedStorage.byteH  r=  r*   c                \    t                       |                     t          j                  S r  )r  r   rL   r  r/   s    r(   r  zTypedStorage.boolM  r?  r*   c                \    t                       |                     t          j                  S r  )r  r   rL   r	  r/   s    r(   r	  zTypedStorage.bfloat16R  s"    #%%%xx'''r*   c                \    t                       |                     t          j                  S r  )r  r   rL   r  r/   s    r(   r  zTypedStorage.complex_doubleW  s"    #%%%xx&&&r*   c                \    t                       |                     t          j                  S r  )r  r   rL   r  r/   s    r(   r  zTypedStorage.complex_float\  r;  r*   c                \    t                       |                     t          j                  S r  )r  r   rL   r  r/   s    r(   r  zTypedStorage.float8_e5m2a  s#    #%%%xx)***r*   c                \    t                       |                     t          j                  S r  )r  r   rL   r  r/   s    r(   r  zTypedStorage.float8_e4m3fnf  s#    #%%%xx+,,,r*   c                \    t                       |                     t          j                  S r  )r  r   rL   r  r/   s    r(   r  zTypedStorage.float8_e5m2fnuzk  #    #%%%xx-...r*   c                \    t                       |                     t          j                  S r  )r  r   rL   r  r/   s    r(   r  zTypedStorage.float8_e4m3fnuzp  rL  r*   c                    t                       | t          k    rt          d          t                              |||t
          j                            | j                  z            } | |          }|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 classesr  )	r  r   r  r   r   rL   r8  r9  rD   )r_   r   r   rC   r%  r   s         r(   r   zTypedStorage.from_fileu  sv    ( 	$%%%,PQQQ(22fdU\%?%?	%J%JJ
 
 #?333r*   c                $    t          j        |i |S r"   )r   r   rh   s      r(   r   zTypedStorage._expired  s    &7777r*   c                &     | j         j        |i |S r"   )r  ru   r$   s      r(   ru   zTypedStorage._write_file  s    0t$0$A&AAAr*   c                &     | j         j        |i |S r"   )r  r|   r$   s      r(   r|   zTypedStorage._set_from_file      3t$3TDVDDDr*   c                &     | j         j        |i |S r"   )r  r~   r$   s      r(   r~   zTypedStorage._set_cdata  s    /t$/@@@@r*   c                &     | j         j        |i |S r"   )r  r   r$   s      r(   r   zTypedStorage._share_cuda_  s    1t$14B6BBBr*   c                F    t                       |                                 S r"   )r  
_is_sharedr/   s    r(   r   zTypedStorage.is_shared  s    #%%%   r*   c                4    | j                                         S r"   )r  r   r/   s    r(   rV  zTypedStorage._is_shared  s    $..000r*   c                .    t          j        j        |i |S r"   )rL   r   r   rh   s      r(   r   zTypedStorage._new_shared_cuda  s    #4dEfEEEr*   c                b     | j         j        |i |\  }}}||||                                 z  fS r"   )r  r\   r9  )r%   r&   r'   manager_handlestorage_handlerC   s         r(   r\   z!TypedStorage._share_filename_cpu_  sH    
 7D!6GGG		
~tt7I7I7K7K/KKKr*   c                8    | j                                          | S r"   )r  rs   r/   s    r(   rs   zTypedStorage._shared_decref  s    ,,...r*   c               .    t          j        j        |i |S r"   rL   r   ro   )r_   r   r&   r'   s       r(   _release_ipc_counterz!TypedStorage._release_ipc_counter      #=tNvNNNr*   c                &     | j         j        |i |S r"   )r  r   r$   s      r(   r   zTypedStorage._shared_incref  rR  r*   c                ^     | j         j        |i |\  }}|||                                 z  fS r"   )r  r^   r9  )r%   r&   r'   fdrC   s        r(   r^   zTypedStorage._share_fd_cpu_  s<    74(7HHHD44--/////r*   c                r   | j         t                      vrd S t                      | j                  }| j        j        dddt          j                                        fvrd S | j        j        dk    rt          nt          t          | j        j                  }	 t          ||          S # t          $ r Y d S w xY w)Nr   rI   rQ   )	rD   r  r   rG   rL   r-  r.  getattrAttributeError)r%   storage_namer  s      r(   r  z&TypedStorage._get_legacy_storage_class  s    :799994133DJ?;H2244	$
 
 
 4 [%..EEGE4;CS4T4T 		6<000 	 	 	44	s   B( (
B65B6r@  )r+   r   )Fr"   )r8   r   r9   r  r?  )rD   rE   r9   r  r+   r  )r   r   r9   r  r+   r   r>  rA  rB  )arC  rD  rE  r   rF  r    rH  r  r   r  r  r)   r   r   r4  r  r0   r  r7   r  r5   r  r=   rA   r  rG   rI   rQ   rM   rS   r9  rV   r  r   r   r   r   r  r   r   r   r   r!  r$  r/  r  r2  r   r   rC   r  r'  r&  r   rX   r-  rZ   rx   r1  rG  r   rz   ri   r6  r   r   r   r   r   r   r   r   r  r  r	  r  r  r  r  r  r  r   r   ru   r|   r~   r   r   rV  r   r\   rs   r_  r   r^   r  rI  rJ  s   @r(   r   r     s?        I,0L0000  X . . . X.
   Z Z Z Z Z Z Z~ YV YV YV YV YVv ; ; X; : : X:% % %
< < < <  * * * *4) ) )!  !  ! F" " "*2 *2 *2X      
. . .
 !%"C C C C C"7 7 7 7 76 6 6 6 6 BG 5 5 5 5 5 5"$ $ $
6 6 62 2 2 2
. 
. 
.  9 9 9K K K$ $ $
U U U4 4 4 4 4H H H
  
F F F

7 
7 
7 
7 
7
 
 
 
 
% % %   +/ 

 

 

 

 

 , , X, , , X,  
F F F
+ + +
K K K3 3 3
     
0 0 01 1 1  
C C C > > [>@ @ @ 1 1 [1 '+D W W W W [W>  & & &
% % %
$ $ $
$ $ $
# # #
% % %
$ $ $
% % %
$ $ $
( ( (
' ' '
& & &
+ + +
- - -
/ / /
/ / /
   [8 8 8 [8B B BE E EA A AC C C! ! !
1 1 1 F F [FL L L   04 O O O O [OE E E0 0 0      r*   c                       e Zd ZU ded<   d ZdS )_LegacyStorageMetar  rD   c                    t          |          t          k    r4t          | j                  }||j        j         k    o| j        |j        k    S dS r?  )rG   r   r  rD  r   rD   )r_   instancer  s      r(   __instancecheck__z$_LegacyStorageMeta.__instancecheck__  sL    >>\))0@@J(/"66 	X^+ ur*   N)rC  rD  rE  rF  rl  r#   r*   r(   ri  ri    s1             r*   ri  c                  P    e Zd Zed             Zed             Zed             ZdS )r  c                    t           j                            | |                                             z            } | |          S )r1  r  )rL   r   r2  r9  )r_   rC   r%  s      r(   r2  z_LegacyStorage._new_shared  sD      .::4##%%BUBUBWBW;WXXs0000r*   c                .    t          j        j        |i |S r"   r^  rh   s      r(   r_  z#_LegacyStorage._release_ipc_counter  r`  r*   c                    |t           j                            | j                  z  } | t           j                            |||                    S )Nr  )rL   r8  r9  rD   r   rm   )r_   rk   rl   rC   
bytes_sizes        r(   _new_shared_filenamez#_LegacyStorage._new_shared_filename  sT    EL66syAAA
s-FFj 
 
 
 	
r*   N)rC  rD  rE  rG  r2  r_  rr  r#   r*   r(   r  r    sf        1 1 [1
 O O [O 
 
 [
 
 
r*   r  )	metaclassr'  c                x    	 t                      |          S # t          $ r}t          d|  d          |d }~ww xY w)Nzpickle storage type "z" is not recognized)r  r)  )r'  r*  s     r(   #_get_dtype_from_pickle_storage_typeru    s\    )++,?@@   L$7LLL
 
	s    
949)r6  )r  r   )r'  r   )D
__future__r   r  r  rW  r   rN  r  typingr   r   r   _Dictr   	_Optionalr   r	   r
   r   typing_extensionsr   rL   torch._utilsr   r   torch.typesr   r   r   torch._prims_commonr   __all__numpyr  r  ModuleNotFoundErrorLockrM  r   rF  r   r   rY  r-  StorageBaser   r   	lru_cacheru  r  r  r  r  r  r  r  r  r  r  r   __doc__rG   rI   rQ   rM   ri  r  ru  r#   r*   r(   <module>r     s*   # " " " " " "          				     	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 # " " " " "  # # # # # # # # , , , , , , , , , ,  3222222 +
,II   I	BBB
 $Y^%% 13  3 3 3 3GC:;;;x" x" x" x" x" x" x" x"v! ! !H@= @= @= @= @=UX)< @= @= @=F9 9 9 T"""  #"( T"""  #"6 T"""  #"
8 8 82" " " &+ ". . .5 5 5B B B B(? ? ?   ~ ~ ~ ~ ~ ~ ~ ~B "M  (-5  '+3  + 	 	 	 	 	 	 	 	
 
 
 
 
\-? 
 
 
 
*     s   A$ $	A0/A0