,g tddlZddlZddlZddlZddlZddlmZmZddl m Z dZ de fdZ dZdZd Zd ZdS) N)autocast GradScalerwrapsctj|tj|tj|t |t jd<dS)z seed everthing PL_GLOBAL_SEEDN)randomseednptorch manual_seedstrosenviron)r s X/apdcephfs_cq5/share_300600172/huiwenshi/3d_services/repos/hunyuan3d-lite/infer/utils.pyseed_everythingrsR KINN4 d#&t99BJ   categorycfd}|S)z+ timing_decorator: record time cNd_tfd}|S)Nrctj}|i|}tj}||z }xjdz c_tdd|dd|S)Nz [HunYuan3D]-[z], cost time: z.4fs)time call_countprint)argskwargs start_timeresultend_time elapsed_timerfuncs rwrapperz4timing_decorator..decorator..wrapper.sqJT4*6**Fy{{H#j0L OOq OO M(MM,MMMM N N NMr)rr)r#r$rs` r decoratorz#timing_decorator..decorator,s@ t       r)rr%s` rtiming_decoratorr'(s$      rc<tfd}|S)z= with torch.cuda.amp.autocast()" xxx cdt5|i|}dddn #1swxYwY|SN)r)rroutputr#s rr$z#auto_amp_inference..wrapper?s{ ZZ + +T4*6**F + + + + + + + + + + + + + + + s %))r)r#r$s` rauto_amp_inferencer,:s5  4[[[ Nrctd|D}td|D}||dS)Nc3>K|]}|VdSr*)numel.0ps r z'get_parameter_number..Gs*::!AGGII::::::rc3LK|]}|j |V dSr*) requires_gradr/r0s rr3z'get_parameter_number..Hs1QQaQ QQQQQQr)Total Trainable)sum parameters)model total_num trainable_nums rget_parameter_numberr=Fs`::u'7'7'9'9:::::IQQ5+;+;+=+=QQQQQM] ; ;;rcB|D] }d|_ dS)NF)r9r5)r:r2s rset_parameter_grad_falser?Ks0         rcf|dvrdS|dvrdSd)N)truetyesy1T)falsefnon0FzQbool arg must one of ['true', 't', 'yes', 'y', '1', 'false', 'f', 'no', 'n', '0'])lower)rs r str_to_boolrLOs:wwyy222t 4 4 4ubbr)rrr numpyr r torch.cuda.amprr functoolsrrrr'r,r=r?rLr&rrrPs.  ////////---s$   <<<    cccccr