
    Χg                         d dl mZmZ d dlZdeej                 dej        fdZdej        deej                 ddfdZdej        d	ee         defd
ZdS )    )IterableOptionalN
parametersreturnc                     d}g }| D ]:}t          ||          }|                    |                    d                     ;t          j        |          S )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       ]/var/www/html/ai-engine/env/lib/python3.11/site-packages/torch/nn/utils/convert_parameters.pyparameters_to_vectorr      sY     L
C # #*5,??

5::b>>""""9S>>    r   c                 :   t          | t          j                  s$t          dt          j        |                      d}d}|D ]U}t          ||          }|                                }| |||z                                |          j        |_        ||z  }VdS )a  Copy 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<(( RP5>#;N;NPPQQQL G 
 
*5,?? KKMM	7Y#667??FFK
 	9
 
r   r   old_param_devicec                    dt           j                                        g}|%| j        j        |v r|                                 nd}n@d}| j        j        |v r|                                 |k    }n|dk    }|rt          d          |S )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
    cudaNr   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	   9   s     #EH$J$J$L$LM"',"37K"K"KEQS 	 L!555##%%)99DD#r)D 	3   r   )	typingr   r   r   r   r   r   intr	    r   r   <module>r,      s    % % % % % % % % Xel%;     ,el 8N SW    :!u| !x} !QT ! ! ! ! ! !r   