+
    &j                     t    R t ^ RIt^ RIHt ^ RIHt ^ RIHt  ! R R]4      t	RR R llt
R	 R
 ltR R ltR# )zKThis module contains utility method for mobile model optimization and lint.N)Enum)_MobileOptimizerType)AnyStrc                   &    ] tR t^	t^t^t^t^tRtR# )LintCode N)	__name__
__module____qualname____firstlineno__BUNDLED_INPUTREQUIRES_GRADDROPOUT	BATCHNORM__static_attributes__r       t/Users/jameslopez/projects/CWCArchive/cwc-podcast/.venv/lib/python3.14/site-packages/torch/utils/mobile_optimizer.pyr   r   	   s    MMGIr   r   c          
          V ^8  d   QhR\         P                  P                  R\        \        ,          R,          R\
        \        ,          R,          R\        R\         P                  P                  /# )   script_moduleoptimization_blocklistNpreserved_methodsbackendreturn)	torchjitScriptModulesetMobileOptimizerTypelistr   strRecursiveScriptModule)formats   "r   __annotate__r#      si     :F :Fyy--:F #$7 84 ?:F  <$.:F 	:F "'!@!@	:Fr   c                  a  \        S \        P                  P                  4      '       g   \	        R\        S 4       R24      hVf   \        4       pVf   . pV Uu. uF  p\        V4      NK  	  pp\        S V4      p\        ;QJ d    V 3R lV 4       F  '       d   K   RM	  RM! V 3R lV 4       4      '       d   \        \        WV,           4      4      pV Uu. uF  p\        S V4      '       d   K  VNK  	  ppV'       d   \        RRP                  V4       24      hVP                  4       pVR8X  d-   \        P                  P!                  S P"                  VV4      pMpVR	8X  d-   \        P                  P%                  S P"                  VV4      pM=VR
8X  d,   \        P                  P'                  S P"                  V4      pM\	        R4      h\        P                  P(                  P+                  V4      # u upi u upi )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   <   <"   T F  p\        SV4      x  K  	  R # 5i)N)hasattr).0methodr   s   & r   	<genexpr>&optimize_for_mobile.<locals>.<genexpr>1   s     
R8Qf7=&))8Qs   FTzAThe following methods to preserve do not exist in script_module: z, cpuvulkanmetalz:Unknown backend, must be one of 'CPU', 'Vulkan' or 'Metal')
isinstancer   r   r   	TypeErrortyper   r    (_get_bundled_inputs_preserved_attributesallr   r(   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	   f&&&     r   optimize_for_mobilerC      s   $ mUYY%;%;<<4&''FGI 	I %!$ 
 CT'TBSFBS'T HXm n
s
R8Q
Rsss
R8Q
RRR $S)>)Z%[ \.Cj.CF7S`bhKi.CjOPTPYPYZkPlOmnp 	p mmoG%$xxEE"! # 
H	$xxLL"! # 
G	$xxKKML\L\^stTUU99//0DEE7 (U ks   G>H5Hc                L    V ^8  d   QhR\         P                  P                  /# )r   r   )r   r   r   )r"   s   "r   r#   r#   L   s     ' '		0F0F 'r   c           	        \        V \        P                  P                  4      '       g   \	        R\        V 4       R24      h. p\        V R4      '       g.   VP                  R\        P                  P                  RR/4       V P                  4        FJ  w  r#VP                  '       g   K  VP                  R\        P                  P                  RRV R2/4       KL  	  \        P                  P                  V 4      pV Fu  pR	V9   d2   VP                  R\        P                  P                  RR
V R2/4       RV9   g   KD  VP                  R\        P                   P                  RR
V R2/4       Kw  	  V# )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_forwardnamemessagezNo bundled input for forward, please add bundled inputs before saving the module using torch.utils.bundled_inputs.augment_model_with_bundled_inputs.z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.)r0   r   r   r   r1   r2   r(   appendr   r   rG   named_parametersrequires_gradr   export_opnamesr   r   )r   	lint_listrG   paramop_namesop_names   &     r   generate_mobile_module_lintsrS   L   s    mUYY%;%;<<4&''FGI 	I I="HII&("8"8"="=y Ky z 	{ %557fh&<&<&A&A9PVW[V\ ]1 O1 2 3 8 yy''6Hfh&6&6&;&;'9WI >* **+ , 7"fh&8&8&=&='9WI >* **+ ,  r   c                    V ^8  d   QhR\         P                  P                  R\        \        ,          R\        \        ,          /# )r   r   r   r   )r   r   r   r   r    )r"   s   "r   r#   r#   u   s9     % %EII<R<R %gklogp %uyz}u~ %r   c                 x   . p\        V R 4      '       d#   VP                  R 4       VP                  R4       \        V R4      '       dr   VP                  R4       V P                  4       pV FJ  pWA9  d   VP                  V4       VP                  RV,           4       VP                  RV,           4       KL  	  V# )get_all_bundled_inputsget_num_bundled_inputs%get_bundled_inputs_functions_and_infoget_all_bundled_inputs_for__bundled_inputs_deflated_)r(   rK   rX   )r   r   r@   all_infofunction_names   &&   r   r3   r3   u   s     "}677!(()AB!(()AB }EFF!(()PQ FFH%M5)00?%,,-J]-Z[%,,-H=-XY	 & %$r   )NNCPU)__doc__r   enumr   torch._Cr   r   typingr   r   rC   rS   r3   r   r   r   <module>rb      s2    Q   @ t :Fz'R%r   