CoolFace
Apppublic

LPDoctor/AIGC-3D

sourceHugging Faceupdated 2y agoView on Hugging Face
3likes
utils.cpython-311.pyc27 linesDownload Raw Back to __pycache__
1�

2��,g���t�ddlZddlZddlZddlZddlZddlmZmZddl	m3Z4d�Zdefd�Z
d�Zd�Zd	�Zd5�ZdS)�N)�autocast�6GradScaler��wrapsc���tj|��tj�|��tj|��t|��tjd<dS)z7        seed everthing8    �PL_GLOBAL_SEEDN)�random�seed�np�torch�manual_seed�str�os�environ)r9s �X/apdcephfs_cq5/share_300600172/huiwenshi/3d_services/repos/hunyuan3d-lite/infer/utils.py�seed_everythingrsR���K������I�N�N�4����	��d����#&�t�9�9�B�J�� � � ��categoryc����fd�}|S)z+10        timing_decorator: record time11    c�N���d�_t�����fd���}|S)Nrc���tj��}�|i|��}tj��}||z12}�xjdz
c_td��d|d�d���|S)N�z
[HunYuan3D]-[z], cost time: z.4f�s)�time�13call_count�print)�args�kwargs�14start_time�result�end_time�elapsed_timer�funcs      ��r�wrapperz4timing_decorator.<locals>.decorator.<locals>.wrapper.sq�������J��T�4�*�6�*�*�F��y�{�{�H�#�j�0�L��O�O�q� �O�O��M�(�M�M�,�M�M�M�M�N�N�N��Mr)rr)r#r$rs` �r�	decoratorz#timing_decorator.<locals>.decorator,s@�������	�t���	�	�	�	�	�15��	��r�)rr%s` r�timing_decoratorr'(s$���������rc�<��t����fd���}|S)z=16        with torch.cuda.amp.autocast()"17            xxx18    c�d��t��5�|i|��}ddd��n#1swxYwY|S�N)r)rr�outputr#s   �rr$z#auto_amp_inference.<locals>.wrapper?s{���
�Z�Z�	+�	+��T�4�*�6�*�*�F�	+�	+�	+�	+�	+�	+�	+�	+�	+�	+�	+����	+�	+�	+�	+��
s�	%�)�)r)r#r$s` r�auto_amp_inferencer,:s5���19�4�[�[������[���Nrc��td�|���D����}td�|���D����}||d�S)Nc3�>K�|]}|���V��dSr*)�numel��.0�ps  r�	<genexpr>z'get_parameter_number.<locals>.<genexpr>Gs*����:�:�!�A�G�G�I�I�:�:�:�:�:�:rc3�LK�|]}|j�	|���V�� dSr*)�
requires_gradr/r0s  rr3z'get_parameter_number.<locals>.<genexpr>Hs1����Q�Q�a���Q����	�	�Q�Q�Q�Q�Q�Qr)�Total�	Trainable)�sum�20parameters)�model�	total_num�
trainable_nums   r�get_parameter_numberr=Fs`���:�:�u�'7�'7�'9�'9�:�:�:�:�:�I��Q�Q�5�+;�+;�+=�+=�Q�Q�Q�Q�Q�M��]�;�;�;rc�B�|���D]	}d|_�21dS)NF)r9r5)r:r2s  r�set_parameter_grad_falser?Ks0��
�
�
�
�
� � ������ � rc�f�|���dvrdS|���dvrdSd�)N)�true�t�yes�y�1T)�false�f�no�n�0FzQbool arg must one of ['true', 't', 'yes', 'y', '1', 'false', 'f', 'no', 'n', '0'])�lower)rs r�str_to_boolrLOs:���w�w�y�y�2�2�2��t�	22�����4�	4�	4��u�b�br)rrr	�numpyrr�torch.cuda.amprr�	functoolsrrrr'r,r=r?rLr&rr�<module>rPs���.23�	�	�	�����
�
�
�
���������/�/�/�/�/�/�/�/�������-�-�-��s�����$24�25�26�<�<�<�27 � � �c�c�c�c�cr