U ,g @s~ddlZddlZddlZddlZddlZddlmZmZddl m Z ddZ e dddZ d d Zd d Zd dZddZdS)N)autocast GradScalerwrapscCs2t|tj|t|t|tjd<dS)z seed everthing ZPL_GLOBAL_SEEDN)randomseednptorchZ manual_seedstrosenviron)rr X/apdcephfs_cq5/share_300600172/huiwenshi/3d_services/repos/hunyuan3d-lite/infer/utils.pyseed_everythings   rcategorycsfdd}|S)z+ timing_decorator: record time cs d_tfdd}|S)NrcsLt}||}t}||}jd7_tdd|dd|S)Nz [HunYuan3D]-[z], cost time: z.4fs)time call_countprint)argskwargsZ start_timeresultZend_timeZ elapsed_time)rfuncr rwrapper.s z4timing_decorator..decorator..wrapper)rrrrrrr decorator,sz#timing_decorator..decoratorr )rrr rrtiming_decorator(s rcstfdd}|S)z= with torch.cuda.amp.autocast()" xxx c s t||}W5QRX|SN)r)rroutputrr rr?sz#auto_amp_inference..wrapperrrr rrauto_amp_inference:sr"cCs6tdd|D}tdd|D}||dS)Ncss|]}|VqdSr )numel.0pr r r Gsz'get_parameter_number..css|]}|jr|VqdSr ) requires_gradr#r$r r rr'Hs)TotalZ Trainable)sum parameters)modelZ total_numZ trainable_numr r rget_parameter_numberFsr-cCs|D] }d|_qdS)NF)r+r()r,r&r r rset_parameter_grad_falseKs r.cCs(|dkrdS|dkr dSddS)N)truetyesy1T)falsefnon0FzQbool arg must one of ['true', 't', 'yes', 'y', '1', 'false', 'f', 'no', 'n', '0'])lower)rr r r str_to_boolOs   r:)r rrnumpyrr Ztorch.cuda.amprr functoolsrrr rr"r-r.r:r r r rs