§
    :zniž  ã                   ó:  — d Z ddlZddlmZ ddlmZ ddlmZm	Z	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dS )zM
This module contains utility method for mobile model optimization and lint.
é    N)ÚEnum)Ú_MobileOptimizerType)ÚOptionalÚSetÚListÚAnyStrc                   ó   — e Zd ZdZdZdZdZdS )ÚLintCodeé   é   é   é   N)Ú__name__Ú
__module__Ú__qualname__ÚBUNDLED_INPUTÚREQUIRES_GRADÚDROPOUTÚ	BATCHNORM© ó    ú|/var/www/html/cool-property-finder/image-detection-backend/venv/lib/python3.11/site-packages/torch/utils/mobile_optimizer.pyr
   r
   
   s"   € € € € € Ø€MØ€MØ€GØ€I€I€Ir   r
   ÚCPUÚscript_moduleÚoptimization_blocklistÚpreserved_methodsÚbackendÚreturnc                 ó–  ‡ — t          ‰ t          j        j        ¦  «        s t	          dt          ‰ ¦  «        › d�¦  «        ‚|€t          ¦   «         }|€g }d„ |D ¦   «         }t          ‰ |¦  «        }t          ˆ fd„|D ¦   «         ¦  «        rt          t          ||z   ¦  «        ¦  «        }g }|D ]'}t          ‰ |¦  «        s|                     |¦  «         Œ(|r%t          dd                     |¦  «        › �¦  «        ‚|                     ¦   «         }|dk    r't          j                             ‰ j        ||¦  «        }nh|d	k    r't          j                             ‰ j        ||¦  «        }n;|d
k    r&t          j                             ‰ j        |¦  «        }nt	          d¦  «        ‚t          j        j                             |¦  «        S )a�  
    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.Nc                 ó,   — g | ]}t          |¦  «        ‘ŒS r   )Ústr)Ú.0Úmethods     r   ú
<listcomp>z'optimize_for_mobile.<locals>.<listcomp>-   s   € Ð'TÐ'TÐ'T¸­¨F©¬Ð'TÐ'TÐ'Tr   c              3   ó8   •K  — | ]}t          ‰|¦  «        V — Œd S )N)Úhasattr)r$   r%   r   s     €r   ú	<genexpr>z&optimize_for_mobile.<locals>.<genexpr>0   s-   øè è € Ð
RÐ
R¨f�7�= &Ñ)Ô)Ð
RÐ
RÐ
RÐ
RÐ
RÐ
Rr   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Ú(_get_bundled_inputs_preserved_attributesÚallÚlistr(   ÚappendÚ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   Úpreserved_methods_strÚbundled_inputs_attributesÚnon_exist_methodsr%   Úoptimized_cpp_modules	   `        r   Úoptimize_for_mobilerF      s  ø€ õ  �m¥U¤YÔ%;Ñ<Ô<ð IÝØG•4˜Ñ&Ô&ÐGÐGÐGñIô Ið 	Ið Ð%Ý!$¡¤ÐàÐ ØÐð
 (UÐ'TÐBSÐ'TÑ'TÔ'TÐå HÈÐXmÑ nÔ nÐÝ
Ð
RÐ
RÐ
RÐ
RÐ8QÐ
RÑ
RÔ
RÑRÔRð ]Ý $¥SÐ)>ÐAZÑ)ZÑ%[Ô%[Ñ \Ô \ÐàÐØ'ð -ð -ˆÝ�} fÑ-Ô-ð 	-Ø×$Ò$ VÑ,Ô,Ð,øØð pÝØnÐPT×PYÒPYÐZkÑPlÔPlÐnÐnñpô pð 	pð �mŠm‰oŒo€GØ�%ÒÐÝ$œx×EÒEØÔØ"Ø!ñ #ô  #ÐÐð 
�HÒ	Ð	Ý$œx×LÒLØÔØ"Ø!ñ #ô  #ÐÐð 
�GÒ	Ð	Ý$œx×KÒKÈMÔL\Ð^sÑtÔtÐÐåÐTÑUÔUÐUåŒ9Ô×/Ò/Ð0DÑEÔEÐEr   c                 óÎ  — t          | t          j        j        ¦  «        s t	          dt          | ¦  «        › d�¦  «        ‚g }t          | d¦  «        s'|                     t          j	        j
        ddœ¦  «         |                      ¦   «         D ]7\  }}|j        r+|                     t          j        j
        d|› d�dœ¦  «         Œ8t          j                             | ¦  «        }|D ]~}d|v r:|                     t          j        j
        d	                     |¦  «        dœ¦  «         d
|v r:|                     t          j        j
        d                     |¦  «        dœ¦  «         Œ|S )z´
    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 {} exists, remember to call eval() before saving the module.and call torch.utils.mobile_optimizer.optimize_for_mobile to drop dropout operator.Ú
batch_normz›Operator {} 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/   r0   r1   r2   r(   r7   r
   r   rI   Únamed_parametersÚrequires_gradr   Úexport_opnamesr   Úformatr   )r   Ú	lint_listrI   ÚparamÚop_namesÚop_names         r   Úgenerate_mobile_module_lintsrU   N   sÇ  € õ �m¥U¤YÔ%;Ñ<Ô<ð IÝØG•4˜Ñ&Ô&ÐGÐGÐGñIô Ið 	Ið €Iå�=Ð"HÑIÔIð {Ø×Ò¥(Ô"8Ô"=ð Kyð zð zñ 	{ô 	{ð 	{ð %×5Ò5Ñ7Ô7ð 3ð 3‰ˆˆeØÔð 	3Ø×Ò¥hÔ&<Ô&Að O1ÐW[ð O1ð O1ð O1ð 2ð 2ñ 3ô 3ð 3øõ Œy×'Ò'¨Ñ6Ô6€HØð <ð <ˆØ˜ÐÐØ×Ò¥hÔ&6Ô&;ð I*ç*0ª&°©/¬/ð;ð ;ñ <ô <ð <ð ˜7Ð"Ð"Ø×Ò¥hÔ&8Ô&=ð K*ç*0ª&°©/¬/ð;ð ;ñ <ô <ð <øð Ðr   c                 óŒ  — g }t          | d¦  «        r*|                     d¦  «         |                     d¦  «         t          | d¦  «        rw|                     d¦  «         |                      ¦   «         }|D ]K}||vr|                     |¦  «         |                     d|z   ¦  «         |                     d|z   ¦  «         ŒL|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(   r7   rY   )r   r   rC   Úall_infoÚfunction_names        r   r4   r4   s   sð   € à "Ðåˆ}Ð6Ñ7Ô7ð CØ!×(Ò(Ð)AÑBÔBÐBØ!×(Ò(Ð)AÑBÔBÐBõ ˆ}ÐEÑFÔFð ZØ!×(Ò(Ð)PÑQÔQÐQØ ×FÒFÑHÔHˆØ%ð 	Zð 	ZˆMØÐ$5Ð5Ð5Ø)×0Ò0°Ñ?Ô?Ð?Ø%×,Ò,Ð-JÈ]Ñ-ZÑ[Ô[Ð[Ø%×,Ò,Ð-HÈ=Ñ-XÑYÔYÐYÐYà$Ð$r   )NNr   )Ú__doc__r.   Úenumr   Útorch._Cr   ÚMobileOptimizerTypeÚtypingr   r   r   r   r
   r/   r0   r#   ÚRecursiveScriptModulerF   rU   r4   r   r   r   ú<module>rd      sp  ððð ð €€€Ø Ð Ð Ð Ð Ð Ø @Ð @Ð @Ð @Ð @Ð @Ø .Ð .Ð .Ð .Ð .Ð .Ð .Ð .Ð .Ð .Ð .Ð .ðð ð ð ð ˆtñ ô ð ð FJØ48Øð	;Fð ;FØ”yÔ-ð;Fà (¨Ð-@Ô)AÔ Bð;Fð $ D¨¤LÔ1ð;Fð ð	;Fð "'¤Ô!@ð	;Fð ;Fð ;Fð ;Fð|#°´	Ô0Fð #ð #ð #ð #ðJ%¸E¼IÔ<Rð %ÐgkÐloÔgpð %ÐuyÐz}Ôu~ð %ð %ð %ð %ð %ð %r   