CoolFace
Apppublic

declare-lab/tango2

sourceHugging Faceupdated 2y agoView on Hugging Face
92likes
torch_utils.cpython-39.pyc25 linesDownload Raw Back to __pycache__
1a

2��'d��@s�dZddlmZmZmZmZddlmZddlm	Z	m3Z4e	�rFddlZe�e
�Zdeeefeeeddfeded	ed5d�dd
�Zdd�ZdS)z16PyTorch utilities: Utilities related to PyTorch7�)�List�Optional�Tuple�Union�)�logging)�is_torch_available�is_torch_versionNztorch.Generatorztorch.deviceztorch.dtypeztorch.layout)�shape�	generator�device�dtype�layoutc	s|��d}�ptj�|p"t�d�}�dur�t�t�s>�jjn8�djj}||jkr�|dkr�d�|dkr�t�d|�d|�d|�d��n(||jkr�|d	kr�td9|�d|�d���t�t�r�d
�dd�������fdd�t	|�D�}tj10|dd��|�}ntj�����d��|�}|S)aThis is a helper function that allows to create random tensors on the desired `device` with the desired `dtype`. When11    passing a list of generators one can seed each batched size individually. If CPU generators are passed the tensor12    will always be created on CPU.13    r�cpuN�mpszBThe passed generator was created on 'cpu' even though a tensor on zB was expected. Tensors will be created on 'cpu' and then moved to zk. Note that one can probably slighly speed up this function by passing a generator that was created on the z device.�cudazCannot generate a z! tensor from a generator of type �.)rrc	s$g|]}tj��|���d��qS)�rrr
r)�torch�randn)�.0�i�r
rrZrand_devicer14��P/home/deep/Projects/audio_diffusion/diffusers/src/diffusers/utils/torch_utils.py�15<listcomp>>s�z randn_tensor.<locals>.<listcomp>)�dimr)
r�stridedr�16isinstance�list�type�logger�info�17ValueError�range�cat�tor)r18rrr
r�19batch_sizeZgen_device_typeZlatentsrrr�randn_tensors420���21�r(cCs(tdd�sttd�sdSt|tjjj�S)z:Check whether the module was compiled with torch.compile()�<z2.0.0�_dynamoF)r	�hasattrrrr*Z22eval_frameZOptimizedModule)�modulerrr�is_compiled_moduleIsr-)NNNN)�__doc__�typingrrrr�r�import_utilsrr	r�23get_logger�__name__r!r(r-rrrr�<module>s$24�25�,