Ë
    [^(h  ã                   óV  — d Z ddlZddlmZ ddlmZ ddlmZm	Z	  G d„ de«      Z
	 	 	 ddej                  j                  d	eee      d
eee	      dedej                  j                   f
d„Zdej                  j                  fd„Zdej                  j                  d
ee   dee   fd„Zy)zKThis module contains utility method for mobile model optimization and lint.é    N)ÚEnum)Ú_MobileOptimizerType)ÚOptionalÚAnyStrc                   ó   — e Zd ZdZdZdZdZy)ÚLintCodeé   é   é   é   N)Ú__name__Ú
__module__Ú__qualname__ÚBUNDLED_INPUTÚREQUIRES_GRADÚDROPOUTÚ	BATCHNORM© ó    úZ/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/torch/utils/mobile_optimizer.pyr   r   	   s   „ Ø€MØ€MØ€GØ�Ir   r   Úscript_moduleÚoptimization_blocklistÚpreserved_methodsÚbackendÚreturnc                 óp  ‡ — t        ‰ t        j                  j                  «      st	        dt        ‰ «      › d�«      ‚|€
t        «       }|€g }|D �cg c]  }t        |«      ‘Œ }}t        ‰ |«      }t        ˆ fd„|D «       «      rt        t        ||z   «      «      }|D �cg c]  }t        ‰ |«      rŒ|‘Œ }}|rt        ddj                  |«      › �«      ‚|j                  «       }|dk(  r,t        j                  j!                  ‰ j"                  ||«      }nl|dk(  r,t        j                  j%                  ‰ j"                  ||«      }n;|dk(  r+t        j                  j'                  ‰ j"                  |«      }nt	        d	«      ‚t        j                  j(                  j+                  |«      S c c}w c c}w )
aÈ  
    Optimize a torch script module for mobile deployment.

    Args:
        script_module: An instance of torch script module with type of ScriptModule.
        optimization_blocklist: A set with type of MobileOptimizerType. When set is not passed,
            optimization method will run all the optimizer pass; otherwise, optimizer
            method will run the optimization pass that is not included inside optimization_blocklist.
        preserved_methods: A list of methods that needed to be preserved when freeze_module pass is invoked
        backend: Device type to use for running the result model ('CPU'(default), 'Vulkan' or 'Metal').
    Returns:
        A new optimized torch script module
    úGot ú, but ScriptModule is expected.c              3   ó6   •K  — | ]  }t        ‰|«      –— Œ y ­w)N)Úhasattr)Ú.0Úmethodr   s     €r   ú	<genexpr>z&optimize_for_mobile.<locals>.<genexpr>1   s   øè ø€ Ò
R¨fŒ7�= &×)Ñ
Rùs   ƒzAThe following methods to preserve do not exist in script_module: z, ÚcpuÚvulkanÚmetalz:Unknown backend, must be one of 'CPU', 'Vulkan' or 'Metal')Ú
isinstanceÚtorchÚjitÚScriptModuleÚ	TypeErrorÚtypeÚsetÚstrÚ(_get_bundled_inputs_preserved_attributesÚallÚlistr    ÚAttributeErrorÚjoinÚlowerÚ_CÚ_jit_pass_optimize_for_mobileÚ_cÚ$_jit_pass_vulkan_optimize_for_mobileÚ#_jit_pass_metal_optimize_for_mobileÚ
_recursiveÚwrap_cpp_module)	r   r   r   r   r"   Úpreserved_methods_strÚbundled_inputs_attributesÚnon_exist_methodsÚoptimized_cpp_modules	   `        r   Úoptimize_for_mobiler@      s³  ø€ ô$ �m¤U§Y¡Y×%;Ñ%;Ô<ÜØ”4˜Ó&Ð'Ð'FÐGóIð 	Ið Ð%Ü!$£ÐàÐ ØÐð
 CTÖ'T¸¬¨F­Ð'TÐÐ'Tä HÈÐXmÓ nÐÜ
Ó
RÐ8QÔ
RÔRÜ $¤SÐ)>ÐAZÑ)ZÓ%[Ó \Ðà.CÖj FÌ7ÐS`ÐbhÕKišÐjÐÐjÙÜØOÐPT×PYÑPYÐZkÓPlÐOmÐnópð 	pð �m‰m‹o€GØ�%ÒÜ$Ÿx™x×EÑEØ×ÑØ"Ø!ó #Ñð 
�HÒ	Ü$Ÿx™x×LÑLØ×ÑØ"Ø!ó #Ñð 
�GÒ	Ü$Ÿx™x×KÑKÈM×L\ÑL\Ð^sÓtÑäÐTÓUÐUä�9‰9×Ñ×/Ñ/Ð0DÓEÐEùò7 (Uùò ks   ÁF.Â!F3Â3F3c                 óº  — t        | t        j                  j                  «      st	        dt        | «      › d�«      ‚g }t        | d«      s,|j                  t        j                  j                  ddœ«       | j                  «       D ]B  \  }}|j                  sŒ|j                  t        j                  j                  d|› d�dœ«       ŒD t        j                  j                  | «      }|D ]k  }d|v r0|j                  t        j                  j                  d	|› d
�dœ«       d|v sŒ<|j                  t        j                   j                  d	|› d�dœ«       Œm |S )zô
    Generate a list of lints for a given torch script module.

    Args:
        script_module: An instance of torch script module with type of ScriptModule.

    Returns:
        lint_map: A list of dictionary that contains modules lints
    r   r   Ú$_generate_bundled_inputs_for_forwardz”No bundled input for forward, please add bundled inputs before saving the module using torch.utils.bundled_inputs.augment_model_with_bundled_inputs.)ÚnameÚmessagezParam zw requires grad, please set torch.no_grad() to reduce memory usage and improve computation speed during inference phase.Údropoutz	Operator z� exists, remember to call eval() before saving the module.and call torch.utils.mobile_optimizer.optimize_for_mobile to drop dropout operator.Ú
batch_normz� exists, remember to call eval() before saving the module and call torch.utils.mobile_optimizer.optimize_for_mobile to drop batch_norm operator.)r'   r(   r)   r*   r+   r,   r    Úappendr   r   rC   Únamed_parametersÚrequires_gradr   Úexport_opnamesr   r   )r   Ú	lint_listrC   ÚparamÚop_namesÚop_names         r   Úgenerate_mobile_module_lintsrO   L   sv  € ô �m¤U§Y¡Y×%;Ñ%;Ô<ÜØ”4˜Ó&Ð'Ð'FÐGóIð 	Ið €Iä�=Ð"HÔIØ×Ñ¤(×"8Ñ"8×"=Ñ"=ð Kyñ zô 	{ð %×5Ñ5Ó7ò 3‰ˆˆeØ×ÓØ×Ñ¤h×&<Ñ&<×&AÑ&AÐPVÐW[ÐV\ð ]1ð O1ñ 2õ 3ð3ô �y‰y×'Ñ'¨Ó6€HØò 
,ˆØ˜ÑØ×Ñ¤h×&6Ñ&6×&;Ñ&;Ø+4°W°Ið >*ð **ñ+ô ,ð ˜7Ò"Ø×Ñ¤h×&8Ñ&8×&=Ñ&=Ø+4°W°Ið >*ð **ñ+õ ,ð
,ð Ðr   c                 óH  — g }t        | d«      r"|j                  d«       |j                  d«       t        | d«      re|j                  d«       | j                  «       }|D ]?  }||vr|j                  |«       |j                  d|z   «       |j                  d|z   «       ŒA |S )NÚget_all_bundled_inputsÚget_num_bundled_inputsÚ%get_bundled_inputs_functions_and_infoÚget_all_bundled_inputs_for_Ú_bundled_inputs_deflated_)r    rG   rS   )r   r   r=   Úall_infoÚfunction_names        r   r/   r/   u   s³   € à "Ðäˆ}Ð6Ô7Ø!×(Ñ(Ð)AÔBØ!×(Ñ(Ð)AÔBô ˆ}ÐEÔFØ!×(Ñ(Ð)PÔQØ ×FÑFÓHˆØ%ò 	ZˆMØÐ$5Ñ5Ø)×0Ñ0°Ô?Ø%×,Ñ,Ð-JÈ]Ñ-ZÔ[Ø%×,Ñ,Ð-HÈ=Ñ-XÕYð		Zð %Ð$r   )NNÚCPU)Ú__doc__r(   Úenumr   Útorch._Cr   ÚMobileOptimizerTypeÚtypingr   r   r   r)   r*   r-   r1   r.   ÚRecursiveScriptModuler@   rO   r/   r   r   r   ú<module>r_      sØ   ðá Qã Ý Ý @ß #ôˆtô ð FJØ48Øñ	:FØ—y‘y×-Ñ-ð:Fà (¨Ð-@Ñ)AÑ Bð:Fð $ D¨¡LÑ1ð:Fð ð	:Fð "'§¡×!@Ñ!@ó	:Fðz'°·	±	×0FÑ0Fó 'ðR%¸E¿I¹I×<RÑ<Rð %ÐgkÐloÑgpð %ÐuyÐz}Ñu~ô %r   