L i VdZddlZddlmZddlmZddlmZm Z GddeZ ddejjd ee ed eee d ed ejj f d ZdejjfdZdejjd eed eefdZy)zKThis module contains utility method for mobile model optimization and lint.N)Enum)_MobileOptimizerType)OptionalAnyStrceZdZdZdZdZdZy)LintCodeN)__name__ __module__ __qualname__ BUNDLED_INPUT REQUIRES_GRADDROPOUT BATCHNORMb/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/torch/utils/mobile_optimizer.pyrr sMMGIrr script_moduleoptimization_blocklistpreserved_methodsbackendreturncpttjjst dt d| t }|g}|Dcgc] }t|}}t|}tfd|Drtt ||z}|Dcgc]}t|r|}}|rtddj||j}|dk(r,tjj!j"||}nl|dk(r,tjj%j"||}n;|dk(r+tjj'j"|}n t d tjj(j+|Scc}wcc}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.c36K|]}t|yw)N)hasattr).0methodrs r z&optimize_for_mobile..1s Rf7=& ) RszAThe following methods to preserve do not exist in script_module: z, cpuvulkanmetalz:Unknown backend, must be one of 'CPU', 'Vulkan' or 'Metal') isinstancetorchjit ScriptModule TypeErrortypesetstr(_get_bundled_inputs_preserved_attributesalllistr AttributeErrorjoinlower_C_jit_pass_optimize_for_mobile_c$_jit_pass_vulkan_optimize_for_mobile#_jit_pass_metal_optimize_for_mobile _recursivewrap_cpp_module) rrrrr"preserved_methods_strbundled_inputs_attributesnon_exist_methodsoptimized_cpp_modules ` roptimize_for_mobiler@s$ mUYY%;%; <4 &''F GI I%!$  CT'TF 'T'T HXm n R8Q RR $S)>AZ)Z%[ \.CjF7S`bhKijjOPTPYPYZkPlOm np pmmoG%$xxEE    " ! # H $xxLL    " ! # G $xxKKML\L\^stTUU 99   / /0D EE7(U ksF.!F33F3ct|tjjst dt |dg}t |ds,|jtjjdd|jD]B\}}|js|jtjjd|ddDtjj|}|D]k}d|vr0|jtjjd |d dd |vs<|jtj jd |d dm|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 rr$_generate_bundled_inputs_for_forwardzNo bundled input for forward, please add bundled inputs before saving the module using torch.utils.bundled_inputs.augment_model_with_bundled_inputs.)namemessagezParam 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 appendrrrCnamed_parameters requires_gradrexport_opnamesrr)r lint_listrCparamop_namesop_names rgenerate_mobile_module_lintsrOLsv mUYY%;%; <4 &''F GI II ="H I("8"8"="=Kyz {%5573 e      h&<&<&A&APVW[V\]1O12 33 yy'' 6H ,     h&6&6&;&;+4WI>***+ , 7 "   h&8&8&=&=+4WI>***+ , , rcHg}t|dr"|jd|jdt|dre|jd|j}|D]?}||vr|j||jd|z|jd|zA|S)Nget_all_bundled_inputsget_num_bundled_inputs%get_bundled_inputs_functions_and_infoget_all_bundled_inputs_for__bundled_inputs_deflated_)r rGrS)rrr=all_info function_names rr/r/us "}67!(()AB!(()AB}EF!(()PQ FFH% ZM$55)00? % , ,-J]-Z [ % , ,-H=-X Y  Z %$r)NNCPU)__doc__r(enumrtorch._CrMobileOptimizerTypetypingrrrr)r*r-r1r.RecursiveScriptModuler@rOr/rrrr_sQ @#tFJ48 :Fyy--:F (-@)A B:F$DL1:F :F"'!@!@ :Fz' 0F0F'R%EII