
    JTh                         S SK Jr  S SKJr  S SKrS\\R
                     S\R
                  4S jrS\R
                  S\\R
                     SS4S jrS	\R
                  S
\\   S\4S jr	g)    )Iterable)OptionalN
parametersreturnc                     Sn/ nU  H.  n[        X15      nUR                  UR                  S5      5        M0     [        R                  " U5      $ )zFlatten an iterable of parameters into a single vector.

Args:
    parameters (Iterable[Tensor]): an iterable of Tensors that are the
        parameters of a model.

Returns:
    The parameters represented by a single vector
N)_check_param_deviceappendviewtorchcat)r   param_devicevecparams       Y/var/www/auris/envauris/lib/python3.13/site-packages/torch/nn/utils/convert_parameters.pyparameters_to_vectorr      sF     L
C*5?

5::b>"	 
 99S>    r   c                 &   [        U [        R                  5      (       d"  [        S[        R                  " U 5       35      eSnSnU HF  n[        XB5      nUR                  5       nXX5-    R                  U5      R                  Ul        X5-  nMH     g)zCopy slices of a vector into an iterable of parameters.

Args:
    vec (Tensor): a single vector representing the parameters of a model.
    parameters (Iterable[Tensor]): an iterable of Tensors that are the
        parameters of a model.
z expected torch.Tensor, but got: Nr   )	
isinstancer   Tensor	TypeErrortypenamer	   numelview_asdata)r   r   r   pointerr   	num_params         r   vector_to_parametersr      s     c5<<((:5>>#;N:OPQQL G*5? KKM	7#67??FKK
 	 r   r   old_param_devicec                 :   S[         R                  R                  5       /nUc0  U R                  R                  U;   a  U R                  5       nU$ SnU$ SnU R                  R                  U;   a  U R                  5       U:g  nOUS:g  nU(       a  [        S5      eU$ )a  Check if the parameters are located on the same device.

Currently, the conversion between model parameters and single vector form is not supported
for multiple allocations, e.g. parameters in different GPUs/PrivateUse1s, or mixture of CPU/GPU/PrivateUse1.

Args:
    param ([Tensor]): a Tensor of a parameter of a model
    old_param_device (int): the device where the first parameter of a
                            model is allocated.

Returns:
    old_param_device (int): report device for the first time
cudar   FzKFound two parameters on different devices, this is currently not supported.)r   _C_get_privateuse1_backend_namedevicetype
get_devicer   )r   r   support_device_typeswarns       r   r	   r	   :   s     #EHH$J$J$LM"',,"3"37K"KE 	   RT 	   LL!55##%)99D#r)D3  r   )
collections.abcr   typingr   r   r   r   r   intr	    r   r   <module>r-      sy    $  Xell%;  ,ell 8N SW :!u|| !x} !QT !r   