§
    �Štj  ã                   ó"  — d Z ddlZddlmZ ddlmZ ddlmZ  G d„ de¦  «        Z		 	 	 dd	ej
        j        d
ee         dz  dee         dz  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 )zKThis module contains utility method for mobile model optimization and lint.é    N)ÚEnum)Ú_MobileOptimizerType)Ú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© ó    úZ/var/www/html/CA-Chatbot/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                 óZ  ‡ — t          ‰ t          j        j        ¦  «        s t	          dt          ‰ ¦  «        › d�¦  «        ‚|€t          ¦   «         }|€g }d„ |D ¦   «         }t          ‰ |¦  «        }t          ˆ fd„|D ¦   «         ¦  «        rt          t          ||z   ¦  «        ¦  «        }ˆ fd„|D ¦   «         }|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È  
    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.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>1   s-   øè è € Ð
RÐ
R¨f�7�= &Ñ)Ô)Ð
RÐ
RÐ
RÐ
RÐ
RÐ
Rr   c                 ó4   •— g | ]}t          ‰|¦  «        °|‘ŒS r   r%   r'   s     €r   r#   z'optimize_for_mobile.<locals>.<listcomp>4   s*   ø€ ÐjÐjÐj FÍ7ÐS`ÐbhÑKiÔKiÐj˜ÐjÐjÐjr   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ÚlistÚ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_methodsÚoptimized_cpp_modules   `       r   Úoptimize_for_mobilerE      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Ñ%[Ô%[Ñ \Ô \ÐàjÐjÐjÐjÐ.CÐjÑjÔjÐØð 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œ¦  «         d|v r+|                     t          j        j
        d	|› d�dœ¦  «         Œa|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/   r0   r1   r2   r&   Úappendr   r   rH   Únamed_parametersÚrequires_gradr   Úexport_opnamesr   r   )r   Ú	lint_listrH   ÚparamÚop_namesÚop_names         r   Úgenerate_mobile_module_lintsrT   L   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Ô&;ð**°Wð **ð **ð **ð+ð +ñ ,ô ,ð ,ð ˜7Ð"Ð"Ø×Ò¥hÔ&8Ô&=ð**°Wð **ð **ð **ð+ð +ñ ,ô ,ð ,øð
 Ð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&   rL   rX   )r   r   rB   Úall_infoÚfunction_names        r   r4   r4   u   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/   r0   r3   r6   r    ÚRecursiveScriptModulerE   rT   r4   r   r   r   ú<module>rc      sX  ðà QÐ Qà €€€Ø Ð Ð Ð Ð Ð Ø @Ð @Ð @Ð @Ð @Ð @Ø Ð Ð Ð Ð Ð ðð ð ð ð ˆtñ ô ð ð CGØ15Øð	:Fð :FØ”yÔ-ð:Fà #Ð$7Ô 8¸4Ñ ?ð:Fð   œ<¨$Ñ.ð:Fð ð	:Fð "'¤Ô!@ð	:Fð :Fð :Fð :Fðz'°´	Ô0Fð 'ð 'ð 'ð 'ðR%¸E¼IÔ<Rð %ÐgkÐloÔgpð %ÐuyÐz}Ôu~ð %ð %ð %ð %ð %ð %r   