
    Pg֕                     \   U 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 d dlm	Z	m
Z
mZmZmZmZmZ d dlmZmZ d dlZdqdZdrdZd Zd Zd	 Zd
 Zd Z	 dsdZ	 dsdZg Zed   ed<   d Zd Z d Z!d Z"d Z#e#Z$d Z%d Z&d Z'd Z(d Z)d Z*d Z+d Z,d Z-d Z.d Z/d  Z0d! Z1d" Z2d# Z3d$ Z4 G d% d&e5      Z6 G d' d(      Z7d) Z8d* Z9d+ Z:d, Z;d- Z<d.e=fd/Z>	 	 dtd0e	d1e?d2e?d.e=fd3Z@d4 ZAd5 ZB G d6 d7      ZCd8 ZDer ed9eE:      d.e?fd;       ZFnd.e?fd<ZFd= ZG ej                  d>      d?e5fd@       ZIdAe5d.eJfdBZK G dC dD      ZL ej                  eN      ZO edE      ZP G dF dGeeP         ZQdHdIdJdKdLdMdMdMdNdOdOdPZRi dQdRdSdTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcdddedfdgdhdidjdkdldmdZdndodpdhZSy)u    N)defaultdict)AnyCallableDefaultDictGenericListOptionalTYPE_CHECKING)
deprecated	ParamSpecc                    t        d||      }|&| j                  dz   | j                  j                  z   S t	        |t
              rt        |      }|t        |       k(  r| S | j                  r|j                  st        d      |j                  j                  dd      }|dz   |j                  z   }t        j                  j                  |       j                  ||      }|dz   }t        j                  j                  |       j                  ||      } |||| j                               S |j                  rt        d       || j                               j!                  | |      S )a  Returns the type if `dtype` is not provided, else casts this object to
    the specified type.

    If this is already of the correct type, no copy is performed and the
    original object is returned.

    Args:
        dtype (type or string): The desired type
        non_blocking (bool): If ``True``, and the source is in pinned memory
            and destination is on the GPU or vice versa, the copy is performed
            asynchronously with respect to the host. Otherwise, the argument
            has no effect.
        **kwargs: For compatibility, may contain the key ``async`` in place of
            the ``non_blocking`` argument. The ``async`` arg is deprecated.
    type.z)Cannot cast sparse tensor to dense tensorz.sparse z.LongTensorz)Cannot cast dense tensor to sparse tensor)_get_async_or_non_blocking
__module__	__class____name__
isinstancestr_import_dotted_namer   	is_sparseRuntimeErrorreplacetorchTensor_values_indicessizecopy_)	selfdtypenon_blockingkwargsnew_module_namenew_values_type_name
new_valuesnew_indices_type_namenew_indicess	            S/var/www/html/suriana-translation/venv/lib/python3.12/site-packages/torch/_utils.py_typer+      s9     .flFKL}$t~~'>'>>>%#E*T
~~JKK**229bA.4u~~E\\))$/445I<X
 /- ?ll++D166!<
 [*diik::FGG##D,77    c                    | j                   |k(  r| S |j                  dk(  r|xr6 | j                   j                  dt        j                  j	                         fv }t        j
                  | j                         t        j                  ||      j                         }|j                  | |       |S t        t        |j                  d      }|"J |j                  j                          d       |j                  |      5  | j                  rt        |d      rt        |j                  | j                  j                         } t        t        j"                  j%                  |       |j                        ||      } t        t        j"                  j'                  |       |j                        ||      } |||| j)                               cddd       S | j                  r#J d|j                  j                          d       t        j*                  | j)                         |	      }|j                  | |       |cddd       S # 1 sw Y   yxY w)
a  Returns a copy of this object in device memory.

    If this object is already on the correct device, then no copy is performed
    and the original object is returned.

    Args:
        device (int): The destination 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.
    cpucuda)r"   device
pin_memoryNz device module is not loadedsparsez$sparse storage is not supported for z tensors)r0   )r0   r   r   _C_get_privateuse1_backend_nameemptynbytesuint8untyped_storager    getattrupperr   hasattrr2   r   r   r   r   r   r   UntypedStorage)	r!   r0   r#   r1   r8   device_modulenew_typeindicesvaluess	            r*   _torA   7   s    {{f{{e! 
dkk&6&6HH224;
 '

  ++KKMV


/
 	 	dL1E6;;5M!<
++


	:;<!			f	% #>>gmX>}33T^^5L5LMHGgell33D96;;GG FWU\\11$7EF GVTYY[9# # NNT5fkk6G6G6I5J(ST"#22499;vNO!!$5"!# # #s   CIA'IIc                     |s|S t        |      dk7  sd|vrDd}t        |j                               j                         }t	        |j                  | |            t        j                  d       |d   S )zReturn the non-blocking flag given the function name and kwargs.

    Args:
        function_name (str): the name of the function being used.
        non_blocking (bool): the default value.
        **kwargs (dict): the kwargs passed to the function.
       asyncz,{}() got an unexpected keyword argument '{}'z)'async' is deprecated; use 'non_blocking')lenlistkeyspop	TypeErrorformatwarningswarn)function_namer#   r$   messagearguments        r*   r   r   h   sk     
6{a7&0@&**,}h?@@MM=>'?r,   c                 
   t         j                  j                  j                  }|| S t	        |t
              r|j                  | |       S t	        |t        t         j                  f      r|S t        |      sJ t        d      )z{Return the map_location location.

    Used for rebuild functions where the tensor device is distinct from the storage
    zgCallable map_location not supported with _rebuild_wrapper_subclass or _rebuild_device_tensor_from_numpy)r   serialization_serialization_tlsmap_locationr   dictgetr   r0   callabler   )r0   rS   s     r*   _get_restore_locationrW   z   s|     &&99FFLlD)##FF33sELL&9:L)))7 r,   c                     t        j                  d| j                  | j                  j                        }|j                  | j                  |||      S )Nr   r"   r0   )r   r5   r"   _untyped_storager0   set_)storagestorage_offsetr   stridets        r*   _rebuild_tensorra      s?    Dg6N6N6U6UVA66'**ND&IIr,   c                 x    t        | t        j                        sJ t        j                  j	                  |       S N)r   r   r   r3   _get_tensor_metadatatensors    r*   get_tensor_metadatarg      s-     fell+++88((00r,   c                     t        |t              sJ t        | t        j                        sJ t        j                  j                  | |       y rc   )r   rT   r   r   r3   _set_tensor_metadata)rf   metadatas     r*   set_tensor_metadatark      s:    h%%%fell+++	HH!!&(3r,   c                 Z    t        | |||      }||_        |rt        ||       ||_        |S rc   )ra   requires_gradrk   _backward_hooks)r]   r^   r   r_   rm   backward_hooksrj   rf   s           r*   _rebuild_tensor_v2rp      s8     WndFCF(FFH-
 ,FMr,   c                     t        j                  d|| j                  j                  |      }|j	                  | j                  |||       |rt        ||       ||_        |S )NrY   r"   r0   rm   )r   r5   r[   r0   r\   rk   rn   )	r]   r^   r   r_   rm   ro   r"   rj   r`   s	            r*   _rebuild_tensor_v3rs      s^     	''..#		A FF7##^T6BAx(&AHr,   ztorch.Tensor_sparse_tensors_to_validatec                  t   	 t         D ]  } | j                  t        j                  u rQt        j                  | j                         | j                         | j                         | j                                q| j                  t        j                  t        j                  t        j                  t        j                  hv r| j                  t        j                  t        j                  hv r!| j                         | j                         }}n | j                         | j!                         }}t        j"                  ||| j%                         | j                         | j                         it'        d| j                   d       	 t         j)                          y # t         j)                          w xY w)Nz,_validate_loaded_sparse_tensors for layout ``)rt   layoutr   
sparse_coo _validate_sparse_coo_tensor_argsr   r   r   is_coalesced
sparse_csr
sparse_csc
sparse_bsr
sparse_bsccrow_indicescol_indicesccol_indicesrow_indices'_validate_sparse_compressed_tensor_argsr@   NotImplementedErrorclear)r`   compressed_indicesplain_indicess      r*   _validate_loaded_sparse_tensorsr     sM   !,, 	Axx5+++66JJL!))+qvvx9I         	  88 0 0%2B2BCC( )6& ( )6& ==&qxxz1668QXX *B188*AN 7	@ 	$))+#))+s   F	F! !F7c                    | t         j                  k(  rOt        |      dk(  r	|\  }}}d}n|\  }}}}t        j                  |||d|      }t        j                  |       |S | t         j                  t         j                  t         j                  t         j                  hv r9|\  }}}}t        j                  ||||| d      }t        j                  |       |S t        d|        )z
    Rebuilds a sparse tensor from its sparse storage representation.

    Args:
        layout (str): The sparse storage layout of the tensor.
        data (tuple): The tensor's sparse storage representation.
       NF)check_invariantsrz   )rw   r   z$rebuilding sparse tensor for layout )r   rx   rE   sparse_coo_tensorrt   appendr{   r|   r}   r~   sparse_compressed_tensorr   )	rw   datar?   r@   r   rz   resultr   r   s	            r*   _rebuild_sparse_tensorr   *  s     !!!t9>$(!GVTL26/GVT<((VTE
 	$**62		 
 ;?7M64//"
 	$**62
 DVHM
NNr,   c                 2    t        j                  | |||      S rc   )r   _nested_view_from_buffer)buffersizesstridesstorage_offsetss       r*   _rebuild_nested_tensorr   T  s    ))&%/RRr,   c                 P    t        |      }| j                  ||      }||_        |S NrZ   )rW   torm   r   r"   r0   rm   rf   s        r*   &_rebuild_device_tensor_from_cpu_tensorr   X  s+    "6*FWW5W0F(FMr,   c                 v    t        |      }t        j                  |       j                  ||      }||_        |S r   )rW   r   
from_numpyr   rm   r   s        r*   !_rebuild_device_tensor_from_numpyr   _  s9    "6*Fd#&&U6&BF(FMr,   c                 6    t        j                  ||| d|      S )Nmetarr   )r   empty_strided)r"   r   r_   rm   s       r*   _rebuild_meta_tensor_no_storager   j  s     fE& r,   c           
      f    t        |      }t        j                  j                  | |||||||      S )N)r   r"   r^   rw   r0   rm   )rW   r   r   _make_wrapper_subclass)clsr"   r   r_   r^   rw   r0   rm   s           r*   _rebuild_wrapper_subclassr   p  sB     #6*F<<..%# / 	 	r,   c                    |d   }|t         j                  k(  r6|\  }}	}
t        j                  ||	|
| j                  | j                        }n^|t         j
                  t         j                  fv r-|\  }}}}t        |      t        u rt        |      t        u r|t         j
                  k(  rat        j                  |t         j                  | j                        }t        j                  |t         j                  | j                        }n`t        j                  |t         j                  | j                        }t        j                  |t         j                  | j                        }t        j                  ||||| j                  | j                        }nt        d|       |j                  | |||       ||_        ||_        |S )Nr   )scale
zero_pointr"   r0   rZ   )scaleszero_pointsaxisr"   r0   z0Can't deserialize quantized tensor with qscheme )r   per_tensor_affine_empty_affine_quantizedr"   r0   per_channel_affine per_channel_affine_float_qparamsr   rF   rf   doublelongfloat#_empty_per_channel_affine_quantizedr   r\   rm   rn   )r]   r^   r   r_   quantizer_paramsrm   ro   qscheme_r   r   rf   r   r   r   s                  r*   _rebuild_qtensorr     sx    q!G%)))/5*..!-->>
 
U--u/U/UV	V'7$6;<4D$5$=%222fELLX#lluzz'.. fEKKW#llu{{7>> ::#-->>
 MgYWXX
KKv6(F ,FMr,   c                 T    t         j                  j                  | |      }||_        |S rc   )r   nn	Parameterrn   )r   rm   ro   params       r*   _rebuild_parameterr     s'    HHt]3E +ELr,   c                 l    t         j                  j                  | |      }||_        t	        ||      }|S rc   )r   r   r   rn   _set_obj_state)r   rm   ro   stater   s        r*   _rebuild_parameter_with_stater     s5    HHt]3E +E 5%(ELr,   c           	         t        | dd       }|r	 |       }|S t        j                  | j                        }|r5| j                  |D ci c]  }t        | |      r|t        | |       c}f}|S | j                  }|S c c}w )N__getstate__)r9   copyreg
_slotnamesr   __dict__r;   )objgetstate_fnr   slots_to_savenames        r*   _get_obj_stater     s     #~t4K L  **3==9 !.sD) '#t,,E L LLELs   	 A=c                    t        |t              r't        |      dk(  st        d|       |d   }|d   }n|}d }|r%|j	                         D ]  \  }}t        | ||        |r%|j	                         D ]  \  }}t        | ||        | S )N   zInvalid serialized state: r   rC   )r   tuplerE   r   itemssetattr)r   r   
dict_stateslots_statekvs         r*   r   r     s    %5zQ!;E7CDD1X
Ah
 $$& 	DAqCA	 %%' 	DAqCA	Jr,   c                 p    | j                  d      }t        |d         }|dd  D ]  }t        ||      } |S )Nr   r   rC   )split
__import__r9   )r   
componentsr   	components       r*   r   r     sC    CJ
Z]
#C^ &	c9%&Jr,   c                 T    t         j                  j                  j                  |       S )a  Flatten dense tensors into a contiguous 1D buffer. Assume tensors are of
    same dense type.

    Since inputs are dense, the resulting tensor will be a concatenated 1D
    buffer. Element-wise operation on this buffer will be equivalent to
    operating individually.

    Args:
        tensors (Iterable[Tensor]): dense tensors to flatten.

    Returns:
        A contiguous 1D buffer containing input tensors.
    )r   r3   _nnflatten_dense_tensors)tensorss    r*   _flatten_dense_tensorsr     s     88<<--g66r,   c                 n   t         j                  j                  j                  | D cg c]!  }t         j                  j                  |      # c}      }t         j                  j                  j                  | D cg c]!  }t         j                  j                  |      # c}      }||fS c c}w c c}w )ab  Flatten sparse tensors into two contiguous 1D buffers, one of indices and
    one of values. Assume tensors are of same sparse type.

    Args:
        tensors (Iterable[Tensor]): sparse tensors to flatten.

    Returns:
        A tuple of two contiguous 1D buffers, one containing input tensors'
        indices and the other containing the values.
    )r   r3   r   r   r   r   r   )r   r`   flat_indicesflat_valuess       r*   _flatten_sparse_tensorsr     s     88<<55+23a		q	!3L ((,,44*12Q		a	 2K $$ 	4 	3s   &B-<&B2c                 V    t         j                  j                  j                  | |      S )a  View a flat buffer using the sizes of tensors. Assume that tensors are of
    same dense type, and that flat is given by _flatten_dense_tensors.

    Args:
        flat (Tensor): flattened dense tensors to unflatten.
        tensors (Iterable[Tensor]): dense tensors whose sizes will be used to
          unflatten flat.

    Returns:
        Unflattened dense tensors with sizes same as tensors and values from
        flat.
    )r   r3   r   unflatten_dense_tensors)flatr   s     r*   _unflatten_dense_tensorsr   0  s     88<<//g>>r,   c           	         | \  }}t         j                  j                  j                  ||D cg c]!  }t         j                  j                  |      # c}      }t         j                  j                  j                  ||D cg c]!  }t         j                  j                  |      # c}      }g }t        |||      D ]6  \  }}}	|j                  |j                  ||	|j                                      8 t        |      S c c}w c c}w )a  View flat buffer (containing indices and values) using the sizes of
    tensors. Assume that tensors are of same sparse type, and that flat is given
    by _flatten_sparse_tensors.

    Args:
        flat (tuple(Tensor, Tensor)): flattened indices and values of sparse
          tensors to unflatten.
        tensors (Iterable[Tensor]): sparse tensors whose sizes will be used to
          unflatten flat.

    Returns:
        Unflattened sparse tensors with sizes same as tensors and values from
        flat.
    )r   r3   r   r   r   r   r   zipr   newr   r   )
r   r   r   r   r`   r?   r@   outputsir   s
             r*   _unflatten_sparse_tensorsr   @  s     !%L+hhll22AAu||,,Q/AG XX\\11w?!ell**1-?F Gw0 .1aquuQ1668,-.> B @s   &D
&D
c                    t        t              }| D ]$  }||j                            j                  |       & |j	                         D ci c]  \  }}|t        |       c}}t        fd|D              S c c}}w )a  Assume that tensors are of same order as ordered_tensors within their
    types, e.g., from _take_tensors. Reorder them to be of same order as
    ordered_tensors.

    Args:
        tensors (Iterable[Tensor]): tensors to be reordered. They should be of
          the same order as ordered_tensors within their own types.
        ordered_tensors (Iterable[Tensor]): tensors whose order will be the
          reference.

    Returns:
        Ordered tuple of tensors with contents from tensors and order of
        ordered_tensors.
    c              3   V   K   | ]   }t        |j                                   " y wrc   )nextr   ).0rf   
type_dict_s     r*   	<genexpr>z&_reorder_tensors_as.<locals>.<genexpr>o  s!     OVj/0Os   &))r   rF   r   r   r   iterr   )r   ordered_tensors	type_dictrf   r`   collr   s         @r*   _reorder_tensors_asr   \  sq     D!I 0&++- ''/0/8/@AGAt!T$Z-AJOOOO Bs   A;c              #     K   t        d       }| D ]  }|j                         }|j                  rt        j                  j                  |      }t        j                  j                  |      }|j                         |j                         z  |j                         |j                         z  z   }n!|j                         |j                         z  }||   }|d   |z   |kD  r|d   dkD  r|d    g dgx}||<   |d   j                  |       |dxx   |z  cc<    |j                         D ]  \  }	}
t        |	      dkD  s|	  yw)a  Group tensors into chunks. This generator yields a chunk at each time,
    each containing tensors of same type up to certain byte limit in total size.

    Args:
        tensors (Sequence): A sequence of tensors to be separated into chunks.
        size_limit (int): The limit of each chunk in bytes.

    Yields:
        Blocks of tensors of same type and within size_limit. The yielded
        tensors are only ordered as the original sequence within its types.
    c                  
    g dgS )Nr    r   r,   r*   <lambda>z_take_tensors.<locals>.<lambda>~  s
    B7 r,   rC   r   N)r   r   r   r   r   r   r   numelelement_sizer   r@   rE   )r   
size_limitbuf_dictrf   r`   r?   r@   r   buf_and_sizebufr   s              r*   _take_tensorsr  r  s=     (3?'CH  KKMll++F3G\\))&1F'"6"6"88,,.6#6#6#889 
 <<>F$7$7$99D{?T!J.<?Q3Fq/!*,a0L8A;Qv&Q4! " //# Qs8a<Is   EEEc                       fd}|S )Nc                 F    t              | _        | j                  d<   | S )Nreturn)rT   __annotations__)funr$   rets    r*   deczannotate.<locals>.dec  s$    "6l(+H%
r,   r   )r
  r$   r  s   `` r*   annotater    s    
 Jr,   c                 z   t         j                  j                  |       }|t        |       }g }t         j                  j                  dd      5  |j                  d |D               |j                  d |j                         D               | ddj                  |       d}d d d        |S # 1 sw Y   S xY w)Nr   )	threshold	edgeitemsc              3   2   K   | ]  }t        |        y wrc   repr)r   as     r*   r   zrender_call.<locals>.<genexpr>  s     .AQ.s   c              3   B   K   | ]  \  }}| d t        |         yw)=Nr  )r   r   r   s      r*   r   zrender_call.<locals>.<genexpr>  s#     DTQ1#QtAwi(Ds   (z, ))	r   	overridesresolve_namer   _tensor_strprintoptionsextendr   join)fnargsr$   str_fnstr_argsrs         r*   render_callr#    s    __))"-F~RH				'	'!q	'	A /...DV\\^DDha		(+,A./ H	/ Hs   AB00B:c                       e Zd ZdZd Zy)KeyErrorMessagez(str subclass that returns itself in reprc                     | S rc   r   r!   s    r*   __repr__zKeyErrorMessage.__repr__  s    r,   N)r   r   __qualname____doc__r(  r   r,   r*   r%  r%    s
    3r,   r%  c                       e Zd ZdZddZd Zy)ExceptionWrapperz?Wraps an exception plus traceback to communicate across threadsNc                     |t        j                         }|d   | _        dj                  t	        j
                  |       | _        || _        y )Nr   r   )sysexc_infoexc_typer  	tracebackformat_exceptionexc_msgwhere)r!   r/  r4  s      r*   __init__zExceptionWrapper.__init__  sB     ||~H wwy998DE
r,   c                 R   d| j                   j                   d| j                   d| j                   }| j                   t        k(  rt        |      }n)t        | j                   dd      r| j                  |      	 | j                  |      }|# t        $ r t        |      dw xY w)z4Reraises the wrapped exception in the current threadzCaught  z.
Original rN   N)rN   )	r0  r   r4  r3  KeyErrorr%  r9   rI   r   )r!   msg	exceptions      r*   reraisezExceptionWrapper.reraise  s     ../qLW==H$ "#&CT]]It4 ---,,	.c*I
 	  	. s#-	.s   =B B&)Nzin background)r   r   r)  r*  r5  r;  r   r,   r*   r,  r,    s    Jr,   r,  c                     t         j                  j                         ryt         j                  j                  j                         ryt        t         d      rt         j                  j                         ryt        t         d      rt         j                  j                         ryt         j                  j                         } t        t         | d       }|r|j                         r| S y Nr/   mpsxpumtia)r   r/   is_availablebackendsr>  r;   r?  r@  r3   r4   r9   )custom_backend_namecustom_device_mods     r*   _get_available_device_typerE    s    zz ~~&&(ue!7!7!9uf%**"9"9";((@@B':DA.;;=""r,   c                    t               }|r)|j                         dk(  r | t        j                        S |r)|j                         dk(  r | t        j                        S |r)|j                         dk(  r | t        j
                        S |r)|j                         dk(  r | t        j                        S |t        j                  j                         k(  r | t        t        |            S y r=  )
rE  lowerr   r/   r>  r?  r@  r3   r4   r9   )
get_memberdevice_types     r*   _get_device_attrrJ    s    ,.K{((*f4%**%%{((*e3%))$${((*e3%))$${((*f4%**%%ehh<<>>'%566r,   c                      t        d       S )Nc                 "    | j                         S rc   )current_devicems    r*   r   z+_get_current_device_index.<locals>.<lambda>  s    a&6&6&8 r,   rJ  r   r,   r*   _get_current_device_indexrQ    s    899r,   c                      t        d       S )Nc                 F    t        t        | j                                     S rc   )rF   rangedevice_countrN  s    r*   r   z)_get_all_device_indices.<locals>.<lambda>  s    d51A+B&C r,   rP  r   r,   r*   _get_all_device_indicesrV    s    CDDr,   c                 H    | D cg c]  t        fd       c}S c c}w )Nc                 &    | j                        S rc   )get_device_properties)rO  r   s    r*   r   z)_get_devices_properties.<locals>.<lambda>  s    q'>'>q'A r,   rP  )
device_idsr   s    `r*   _get_devices_propertiesr[    s    LVWqABWWWs   r  c                      t         j                  j                         dkD  rt         j                  j                         S y)zChecks if there are CUDA devices available and
    returns the device index of the current default CUDA device.
    Returns -1 in case there are no CUDA devices available.
    Arguments: ``None``
    r   )r   r/   rU  rM  r   r,   r*   get_current_device_indexr^    s/     zz 1$zz((**r,   r0   optional	allow_cpuc                    t        | t              rt        j                  |       } d}t        | t        j                        r<|s| j                  dk(  rt        d|        | j                  dk(  rdn| j                  }t        | t              r| }|F|r6t        j                  j                         rt               }|S t               }|S t        d|        |S )a'  Gets the device index from :attr:`device`, which can be a torch.device
    object, a Python integer, or ``None``.

    If :attr:`device` is a torch.device object, returns the device index if it
    has index. Note that for a device without a specified index,
    i.e., ``torch.device('xxx')``, this will return the current default
    device of that type if :attr:`optional` is ``True``. If :attr:`allow_cpu` is ``True``,
    CPU devices will be accepted and ``-1`` will be returned in this case.

    If :attr:`device` is a Python integer, it is returned as is.

    If :attr:`device` is ``None``, this will return the current default
    device of the supported runtime platform if :attr:`optional` is ``True``.
    i.e., the current default CUDA device will be returned if CUDA runtime is supported.
    Nr.   z$Expected a non cpu device, but got: r]  zFExpected a torch.device with a specified index or an integer, but got:)r   r   r   r0   r   
ValueErrorindexintjitis_scriptingr^  rQ  )r0   r_  r`  
device_idxs       r*   _get_device_indexrh    s    ( &#f% $J&%,,'V[[E1CF8LMM!;;%/RV\\
&#
 yy%%'57
  78

  XY_X`a  r,   c                     t        | t        j                  j                        s%| j	                         rt        j
                  |       S | S )z
    Returns a real view of a tensor if complex dtype else just the tensor
    need to check if a UninitializedParameter because otherwise checking is_complex is an error for a LazyModule
    )r   r   r   UninitializedParameter
is_complexview_as_realre   s    r*   _handle_complexrm  J  sC     &%(("A"AB 	6" 	r,   c                    t        | t        j                        st        dt	        |              | j
                  r"t        j                  |       j                  dz	  S | j                  r"t        j                  |       j                  dz	  S | t        j                  k(  ryt        j                  |       j                  dz	  S )z8
    Returns the element size for a dtype, in bytes
    zexpected torch.dtype, but got r   r   rC   )r   r   r"   r   r   rk  finfobitsis_floating_pointbooliinfo)r"   s    r*   _element_sizert  W  s     eU[[);DK=IJJ{{5!&&!++		 	 {{5!&&!++	%**	{{5!&&!++r,   c                       e Zd ZddZddZy)_ClassPropertyDescriptorNc                     || _         y rc   )fget)r!   rx  fsets      r*   r5  z!_ClassPropertyDescriptor.__init__j  s	    	r,   c                 ^    |t        |      } | j                  j                  ||             S rc   )r   rx  __get__)r!   instanceowners      r*   r{  z _ClassPropertyDescriptor.__get__m  s,    =NE1tyy  5133r,   rc   )r   r   r)  r5  r{  r   r,   r*   rv  rv  i  s    4r,   rv  c                 Z    t        | t        t        f      st        |       } t        |       S rc   )r   classmethodstaticmethodrv  )funcs    r*   classpropertyr  s  s&    d[,784 #D))r,   U`torch._utils.is_compiling` is deprecated. Use `torch.compiler.is_compiling` instead.)categoryc                  >    t         j                  j                         S rc   )r   compileris_compilingr   r,   r*   r  r  |  s    
 ~~**,,r,   c                  l    t        j                  dd       t        j                  j	                         S )zd
        Indicates whether we are tracing/compiling with torch.compile() or torch.export().
        r  r   )
stacklevel)rK   rL   r   r  r  r   r,   r*   r  r    s+     	c	

 ~~**,,r,   c                    ddl m} t        | |      rt        j                  j                  t        j                  j                  j                        }	 t        j                  | j                         | t        j                  j                  |       y y t        j                  |        y # | t        j                  j                  |       w w xY w)Nr   )FunctionalTensor)#torch._subclasses.functional_tensorr  r   r   r3   _unset_dispatch_mode_TorchDispatchModeKey
FUNCTIONAL_functionalize_syncelem_set_dispatch_mode)r`   r  maybe_functional_modes      r*   r  r    s     E!%& !& = =HH**55!
	C%%aff-$0++,AB 1 	!!!$ %0++,AB 1s   B- -$Cr   rI  c                 P    t        t        | d       }|t        d|  d|  d      |S )NzDevice 'z<' does not have a corresponding module registered as 'torch.z'.)r9   r   r   )rI  r=   s     r*   _get_device_moduler    sA    E;5M{m#_`k_llno
 	
 r,   r   c                 X    dt         fd}t        | t        f |d       |d      d      S )Nis_initc                       fd}|S )Nc                 j    r| j                   j                  }n| j                  }t        d|       )Nz&Tried to instantiate dummy base class )r   r   r   )r   r  r$   
class_namer  s       r*   err_fnz/_dummy_type.<locals>.get_err_fn.<locals>.err_fn  s1     ]]33
 \\
!G
|TUUr,   r   )r  r  s   ` r*   
get_err_fnz_dummy_type.<locals>.get_err_fn  s    	V r,   TF)r5  __new__)rr  r   object)r   r  s     r*   _dummy_typer    s5    D  vij&6:eCTU r,   c                   *    e Zd Zd Zd Zd ZdefdZy)_LazySeedTrackerc                 .    d | _         d | _        g | _        y rc   manual_seed_all_cbmanual_seed_cb
call_orderr'  s    r*   r5  z_LazySeedTracker.__init__  s    "&"r,   c                 P    ||f| _         | j                  | j                   g| _        y rc   r  r!   cbr1  s      r*   queue_seed_allz_LazySeedTracker.queue_seed_all  s&    #%y/..0G0GHr,   c                 P    ||f| _         | j                  | j                   g| _        y rc   )r  r  r  r  s      r*   
queue_seedz_LazySeedTracker.queue_seed  s&    !9o22D4G4GHr,   r  c                     | j                   S rc   )r  r'  s    r*   	get_callsz_LazySeedTracker.get_calls  s    r,   N)r   r   r)  r5  r  r  r   r  r   r,   r*   r  r    s    

I
I
4 r,   r  Pc                   n    e Zd ZdefdZdeedf   ddfdZdej                  dej                  ddfd	Z
y)
CallbackRegistryr   c                      || _         g | _        y rc   )r   callback_list)r!   r   s     r*   r5  zCallbackRegistry.__init__  s    	68r,   r  Nr  c                 :    | j                   j                  |       y rc   )r  r   )r!   r  s     r*   add_callbackzCallbackRegistry.add_callback  s    !!"%r,   r  r$   c                     | j                   D ]  }	  ||i |  y # t        $ r*}t        j                  d| j                         Y d }~=d }~ww xY w)Nz6Exception in callback for %s registered with gpu trace)r  	Exceptionloggerr:  r   )r!   r  r$   r  es        r*   fire_callbackszCallbackRegistry.fire_callbacks  sW    $$ 	BD#F#	    Ldii s   	A A

A)r   r   r)  r   r5  r   r  r  r  r$   r  r   r,   r*   r  r    sL    9S 9&x40 &T &AFF ahh 4 r,   r  builtinsr   queuereprlibzcollections.abccollectionsdbmio)__builtin__copy_regQueuer  _abcollUserDictUserList
UserStringwhichdbStringIO	cStringIO)r  xrange)r  rT  )r  reduce)	functoolsr  )r  intern)r.  r  )r  unichr)r  chr)r  unicode)r  r   )r  r   )r  rd  )	itertoolsizip)r  r   )r  imap)r  map)r  ifilter)r  filter)r  ifilterfalse)r  filterfalse)r  izip_longest)r  zip_longest)r  IterableUserDict)r  r  )r  r  )r  r  )r  r  )r  r  )r  
basestring)
exceptionsStandardError)r  r  )r  r  )NF)Frc   )FF)Tr   r  loggingr.  r1  rK   r  r   typingr   r   r   r   r   r	   r
   typing_extensionsr   r   r   r+   rA   r   rW   ra   rg   rk   rp   rs   rt   r  r   r   r   r   r   _rebuild_xla_tensorr   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r#  r   r%  r,  rE  rJ  rQ  rV  r[  rd  r^  rr  rh  rm  rt  rv  r  FutureWarningr  r  	lru_cacher  r   r  r  	getLoggerr   r  r  r  IMPORT_MAPPINGNAME_MAPPINGr   r,   r*   <module>r     s/      
   # U U U 3 %8P.#b$zJ14 : . 57 T.1 6",J'OTS 8 20f	6,7"%(? 8P, J
,c    F" :
E
X
#  ,,, , 		,^
,$4 4*  _-$ -	-
	-$ 	-%< QC  c d   0 
		8	$cNwqz ,  &46 0 2	
  3 0 . . 4 "#? "#? %&A 9 !"?  "#6!" $%>#$ 9%r,   