+
     °³j
m  ã                   óZ  € ^ RI t ^ RIt^ RIt^ RIt^ RIt^ RIHt ^ RI Ht ^ RIH	t	 ^ RI
HtHtHtHt ^ RIt^ RIt^ RIHtHt ^ RIHtHtHt RR	.t ! R
 R]P0                  4      t ! R R]4      tR tR R ltR R ltR R ltRR R llt ! R R]P@                  4      t!RR R llt"R# )é    N)ÚOrderedDict)Údeepcopy)Úchain)ÚAnyÚCallableÚOptionalÚUnion)ÚfxÚnn)Ú_CodeOnlyModuleÚ
_copy_attrÚ_USER_PRESERVED_ATTRIBUTES_KEYÚcreate_feature_extractorÚget_graph_node_namesc                   óN   a a€ ] tR t^t oRtV 3R ltV3R lV 3R lltRtVtV ;t	# )ÚLeafModuleAwareTracerzÝ
An fx.Tracer that allows the user to specify a set of leaf modules, i.e.
modules that are not to be traced through. The resulting graph ends up
having single nodes referencing calls to the leaf modules' forward methods.
c                ór   <€ / V n         R V9   d   VP                  R 4      pW0n         \        SV `  ! V/ VB  R# )Úleaf_modulesN)r   ÚpopÚsuperÚ__init__)ÚselfÚargsÚkwargsr   Ú	__class__s   &*, €Úf/home/luca/screen-checking/.venv/lib/python3.14/site-packages/torchvision/models/feature_extraction.pyr   ÚLeafModuleAwareTracer.__init__   s9   ø€ ØˆÔØ˜VÔ#Ø!Ÿ:™: nÓ5ˆLØ ,ÔÜ‰Ò˜$Ð) &Ô)ó    c                ó@   <€ V ^8„  d   QhRS[ P                  RS[RS[/# )é   ÚmÚmodule_qualnameÚreturn)r   ÚModuleÚstrÚbool)ÚformatÚ__classdict__s   "€r   Ú__annotate__Ú"LeafModuleAwareTracer.__annotate__"   s&   ø€ ÷ :ñ :¡§	¡	ð :¹Cð :ÁDñ :r   c                óp   <€ \        V\        V P                  4      4      '       d   R # \        SV `  W4      # ©T)Ú
isinstanceÚtupler   r   Úis_leaf_module)r   r!   r"   r   s   &&&€r   r/   Ú$LeafModuleAwareTracer.is_leaf_module"   s.   ø€ Ü�aœ˜t×0Ñ0Ó1×2Ò2ÙÜ‰wÑ% aÓ9Ð9r   )r   )
Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r/   Ú__static_attributes__Ú__classdictcell__Ú__classcell__©r   r(   s   @@r   r   r      s   ù‡ € ñõ*÷:÷ :ó :r   r   c                   óv   a a€ ] tR t^(t oRtV 3R ltV3R lR ltR
V3R lV 3R llltV3R lR ltR	t	Vt
V ;t# )ÚNodePathTracera,  
NodePathTracer is an FX tracer that, for each operation, also records the
name of the Node from which the operation originated. A node name here is
a `.` separated path walking the hierarchy from top level module down to
leaf operation or leaf module. The name of the top level module is not
included as part of the node name. For example, if we trace a module whose
forward method applies a ReLU module, the name for that node will simply
be 'relu'.

Some notes on the specifics:
    - Nodes are recorded to `self.node_to_qualname` which is a dictionary
      mapping a given Node object to its node name.
    - Nodes are recorded in the order which they are executed during
      tracing.
    - When a duplicate node name is encountered, a suffix of the form
      _{int} is added. The counter starts from 1.
c                óT   <€ \         SV `  ! V/ VB  R V n        \        4       V n        R# )Ú N)r   r   Úcurrent_module_qualnamer   Únode_to_qualname)r   r   r   r   s   &*,€r   r   ÚNodePathTracer.__init__;   s)   ø€ Ü‰Ò˜$Ð) &Ò)à')ˆÔ$ô
 !,£ˆÖr   c                óN   <€ V ^8„  d   QhRS[ P                  P                  RS[/# )r    r!   Úforward)Útorchr   r$   r   )r'   r(   s   "€r   r)   ÚNodePathTracer.__annotate__E   s#   ø€ ÷ 8ñ 8™UŸX™XŸ_™_ð 8±xñ 8r   c                óà   € V P                   p V P                  V4      pW`n         V P                  W4      '       g   V! V/ VB pVWPn         # V P                  RWcV4      WPn         #   YPn         i ; i)a_  
Override of `fx.Tracer.call_module`
This override:
1) Stores away the qualified name of the caller for restoration later
2) Adds the qualified name of the caller to
   `current_module_qualname` for retrieval by `create_proxy`
3) Once a leaf module is reached, calls `create_proxy`
4) Restores the caller's qualified name into current_module_qualname
Úcall_module)r>   Úpath_of_moduler/   Úcreate_proxy)r   r!   rB   r   r   Úold_qualnamer"   Úouts   &&&&&   r   rF   ÚNodePathTracer.call_moduleE   sv   € ð ×3Ñ3ˆð	8Ø"×1Ñ1°!Ó4ˆOØ+:Ô(Ø×&Ñ& q×:Ò:Ù˜tÐ. vÑ.�Øð ,8Õ(ð ×$Ñ$ ]°OÈ6ÓRà+7Õ(ø¨<Õ(ús   Ž7A% ÁA% Á%A-c                ó|   <€ V ^8„  d   QhRS[ RS[P                  P                  RS[P                  P
                  /# )r    ÚkindÚtargetr#   )r%   r
   ÚnodeÚTargetÚproxyÚProxy)r'   r(   s   "€r   r)   rD   Z   s5   ø€ ÷ 
ñ 
Ùð
Ù!#§¡§¡ð
á	�‰�‰ñ
r   c                ó¤   <€ \         S	V `  WW4WV4      pV P                  V P                  VP                  4      V P
                  VP                  &   V# )z¯
Override of `Tracer.create_proxy`. This override intercepts the recording
of every operation and stores away the current traced module's qualified
name in `node_to_qualname`
)r   rH   Ú_get_node_qualnamer>   rO   r?   )
r   rM   rN   r   r   ÚnameÚ	type_exprÚ_rQ   r   s
   &&&&&&&* €r   rH   ÚNodePathTracer.create_proxyZ   sK   ø€ ô ‘Ñ$ T°4ÀÓQˆØ,0×,CÑ,CÀD×D`ÑD`Ðbg×blÑblÓ,mˆ×Ñ˜eŸj™jÑ)Øˆr   c                óT   <€ V ^8„  d   QhRS[ RS[P                  P                  RS[ /# )r    r"   rO   r#   )r%   r
   rO   ÚNode)r'   r(   s   "€r   r)   rD   f   s*   ø€ ÷ "ñ "±#ð "¹R¿W¹W¿\¹\ð "Écñ "r   c                ó  € TpVP                   R 8w  d,   \        V4      ^ 8”  d
   VR,          pV\        V4      ,          p\        P                  ! RV4      e   VP                  R^4      ^ ,          p\        V P                  P                  4       4       Fm  p\        P                  ! V R2V4      f   K!  VP                  VR4      p\        V4      '       d   \        VR,          4      ^,           pM^pVRV 2,          p V# 	  V# )rF   Ú.z
.+_[0-9]+$rW   z(_[0-9]+)?$r=   :é   NN)ÚopÚlenr%   ÚreÚmatchÚrsplitÚreversedr?   ÚvaluesÚreplaceÚint)r   r"   rO   Únode_qualnameÚexisting_qualnameÚpostfixÚ
next_indexs   &&&    r   rT   Ú!NodePathTracer._get_node_qualnamef   sø   € Ø'ˆà�7‰7�mÔ#ô �=Ó! AÔ%à Õ$�ØœS ›YÕ&ˆMô �8Š8�M =Ó1Ò=Ø)×0Ñ0°°aÓ8¸Õ;ˆMô "*¨$×*?Ñ*?×*FÑ*FÓ*HÖ!IÐô �xŠx˜M˜?¨+Ð6Ð8IÓJÔVØ+×3Ñ3°MÀ2ÓF�Ü�w—<’<ä!$ W¨R¥[Ó!1°AÕ!5‘Jð "#�JØ 1 Z LÐ!1Õ1�ØàÐñ "Jð Ðr   )r>   r?   )NN)r1   r2   r3   r4   r5   r   rF   rH   rT   r6   r7   r8   r9   s   @@r   r;   r;   (   s2   ù‡ € ñõ$.÷8ð 8÷*
õ 
÷"÷ "ð "r   r;   c                óŽ   a€ \        V 4      o\        ;QJ d    V3R lV 4       F  '       d   K   R# 	  R# ! V3R lV 4       4      # )zNCheck if y is a subsequence of x
https://stackoverflow.com/a/24017747/4391249
c              3   óš   <a"  € T F?  o\         ;QJ d    V3R  lS 4       F  '       g   K   RM	  RM! V3R  lS 4       4      x € KA  	  R# 5i)c              3   ó,   <"  € T F	  qS8H  x € K  	  R # 5i©N© )Ú.0Úx_itemÚy_items   & €r   Ú	<genexpr>Ú'_is_subseq.<locals>.<genexpr>.<genexpr>�   s   øé € Ð9±&¨˜VÖ#³&ùs   ƒTFN)Úany)rq   rs   Úiter_xs   &@€r   rt   Ú_is_subseq.<locals>.<genexpr>�   s/   ùé € ÐJÉ¸f�s‹sÔ9±&Ó9�s�sŠsÔ9±&Ó9×9Ð9Ëùs   „A”A« AFT)ÚiterÚall)ÚxÚyrw   s   &&@r   Ú
_is_subseqr}   ‹   s7   ø€ ô �!‹W€Fß‹3ÔJÉÓJ�3Œ3ÐJŠ3ÐJˆ3ÔJÉÓJÓJÐJr   c                ó0   € V ^8„  d   QhR\         R\         /# )r    Útrain_tracerÚeval_tracer)r;   )r'   s   "r   r)   r)   “   s   € ÷ (ñ (¬.ð (Ä~ñ (r   c                óð  € \        V P                  P                  4       4      p\        VP                  P                  4       4      p\        V4      \        V4      8X  dO   \        ;QJ d%    R \        W#4       4       F  '       d   K   RM	  RM! R \        W#4       4       4      '       d   R# Rp\        W#4      '       d   RpM\        W24      '       d   RpMRp\        P                  ! WT,           4       R# )	zx
Utility function for warning the user if there are differences between
the train graph nodes and the eval graph nodes.
c              3   ó.   "  € T F  w  rW8H  x € K  	  R # 5iro   rp   )rq   ÚtÚes   &  r   rt   Ú*_warn_graph_differences.<locals>.<genexpr>›   s   é € Ð2cÑFb¹d¸a°1¶6ÓFbùs   ‚FTNztWhen choosing nodes for feature extraction, you may need to specify output nodes for train and eval mode separately.znNOTE: The nodes obtained by tracing the model in eval mode are a subsequence of those obtained in train mode. znNOTE: The nodes obtained by tracing the model in train mode are a subsequence of those obtained in eval mode. zdThe nodes obtained by tracing the model in train mode are different to those obtained in eval mode. )	Úlistr?   rd   r_   rz   Úzipr}   ÚwarningsÚwarn)r   r€   Útrain_nodesÚ
eval_nodesÚsuggestion_msgÚmsgs   &&    r   Ú_warn_graph_differencesrŽ   “   sÅ   € ô
 �|×4Ñ4×;Ñ;Ó=Ó>€KÜ�k×2Ñ2×9Ñ9Ó;Ó<€Jä
ˆ;Óœ3˜z›?Ô*¯s«sÑ2cÄcÈ+ÔFbÓ2c¯s¯sªsÑ2cÄcÈ+ÔFbÓ2c×/cÒ/cÙð	;ð ô
 �+×*Ò*ðBñ 	ô 
�J×	,Ò	,ðAñ 	ð
 uˆÜ‡M‚M�#Õ&Ö'r   c                ó:   € V ^8„  d   QhR\         \        ,          /# ©r    r#   )r†   Útype)r'   s   "r   r)   r)   ²   s   € ÷ ñ ¤4¬¥:ñ r   c                  ó  € \         P                  ! \        P                  4      p . pV  F`  w  r#\         P                  ! V4      '       g   K#  \        V\        P                  P                  4      '       g   KO  VP                  V4       Kb  	  V# ro   )
ÚinspectÚ
getmembersÚtorchvisionÚopsÚisclassÚ
issubclassrC   r   r$   Úappend)ÚmembersÚresultrW   Úobjs       r   Ú_get_leaf_modules_for_opsr�   ²   s]   € Ü× Ò ¤§¡Ó1€GØ€FÛ‰ˆÜ�?Š?˜3×Ô¤J¨s´E·H±H·O±O×$DÔ$DØ�M‰M˜#Öñ ð €Mr   c                óŠ   € V ^8„  d   QhR\         \        \        \        3,          ,          R\        \        \        3,          /# )r    Úoriginal_tr_kwargsr#   )r   Údictr%   r   )r'   s   "r   r)   r)   »   s4   € ÷  ñ  ´8¼DÄÄcÀ½NÕ3Kð  ÔPTÔUXÔZ]ÐU]ÕP^ñ  r   c                 ó  € \         \        P                  3p\        4       pV f   / MT pRV9   d#   \	        \        VR,          V,           4      4      MTVR&   RV9   d#   \        \        VR,          V,           4      4      MTVR&   V# )NÚautowrap_modulesr   )Úmathr•   r–   r�   r.   Úsetr†   )rŸ   Údefault_autowrap_modulesÚdefault_leaf_modulesÚresult_tracer_kwargss   &   r   Ú_set_default_tracer_kwargsr¨   »   s˜   € Ü $¤k§o¡oÐ6ÐÜ4Ó6ÐØ!3Ò!;™2ÐASÐð Ð!5Ô5ô 	ŒcÐ&Ð'9Õ:Ð=UÕUÓVÔWà%ð Ð+Ñ,ð Ð1Ô1ô 	ŒSÐ% nÕ5Ð8LÕLÓMÔNà!ð ˜Ñ(ð
  Ðr   c                ó&  € V ^8„  d   QhR\         P                  R\        \        \        \
        3,          ,          R\        R\        \        \        \
        3,          ,          R\        \        \        ,          \        \        ,          3,          /# )r    ÚmodelÚtracer_kwargsÚsuppress_diff_warningÚconcrete_argsr#   )	r   r$   r   r    r%   r   r&   r.   r†   )r'   s   "r   r)   r)   Ì   sj   € ÷ >#ñ >#Ü�9‰9ð>#äœD¤¤c �NÕ+ð>#ô  ð>#ô œD¤¤c �NÕ+ð	>#ô
 Œ4”�9”dœ3•iÐÕ ñ>#r   c                óº  € \        V4      pV P                  p\        R/ VB pVP                  V P	                  4       VR7       \        R/ VB pVP                  V P                  4       VR7       \        VP                  P                  4       4      p\        VP                  P                  4       4      pV'       g   \        WV4       V P	                  V4       Wx3# )a‡  
Dev utility to return node names in order of execution. See note on node
names under :func:`create_feature_extractor`. Useful for seeing which node
names are available for feature extraction. There are two reasons that
node names can't easily be read directly from the code for a model:

    1. Not all submodules are traced through. Modules from ``torch.nn`` all
       fall within this category.
    2. Nodes representing the repeated application of the same operation
       or leaf module get a ``_{counter}`` postfix.

The model is traced twice: once in train mode, and once in eval mode. Both
sets of node names are returned.

For more details on the node naming conventions used here, please see the
:ref:`relevant subheading <about-node-names>` in the
`documentation <https://pytorch.org/vision/stable/feature_extraction.html>`_.

Args:
    model (nn.Module): model for which we'd like to print node names
    tracer_kwargs (dict, optional): a dictionary of keyword arguments for
        ``NodePathTracer`` (they are eventually passed onto
        `torch.fx.Tracer <https://pytorch.org/docs/stable/fx.html#torch.fx.Tracer>`_).
        By default, it will be set to wrap and make leaf nodes all torchvision ops:
        {"autowrap_modules": (math, torchvision.ops,),"leaf_modules": _get_leaf_modules_for_ops(),}
        WARNING: In case the user provides tracer_kwargs, above default arguments will be appended to the user
        provided dictionary.
    suppress_diff_warning (bool, optional): whether to suppress a warning
        when there are discrepancies between the train and eval version of
        the graph. Defaults to False.
    concrete_args (Optional[Dict[str, any]]): Concrete arguments that should
        not be treated as Proxies. According to the `Pytorch docs
        <https://pytorch.org/docs/stable/fx.html#torch.fx.Tracer.trace>`_,
        this parameter's API may not be guaranteed.

Returns:
    tuple(list, list): a list of node names from tracing the model in
    train mode, and another from tracing the model in eval mode.

Examples::

    >>> model = torchvision.models.resnet18()
    >>> train_nodes, eval_nodes = get_graph_node_names(model)
©r­   rp   )
r¨   Útrainingr;   ÚtraceÚtrainÚevalr†   r?   rd   rŽ   )	rª   r«   r¬   r­   Úis_trainingr   r€   rŠ   r‹   s	   &&&&     r   r   r   Ì   s¶   € ôd /¨}Ó=€MØ—.‘.€KÜ!Ñ2 MÑ2€LØ×Ñ�u—{‘{“}°MÐÔBÜ Ñ1 =Ñ1€KØ×Ñ�e—j‘j“l°-ÐÔ@Ü�|×4Ñ4×;Ñ;Ó=Ó>€KÜ�k×2Ñ2×9Ñ9Ó;Ó<€Jß Ü Ô:à	‡K�K�ÔØÐ"Ð"r   c                   ób   a a€ ] tR tRt oRtR	V3R lV 3R llltR
V 3R lltR tR tRt	Vt
V ;t# )ÚDualGraphModulei  a  
A derivative of `fx.GraphModule`. Differs in the following ways:
- Requires a train and eval version of the underlying graph
- Copies submodules according to the nodes of both train and eval graphs.
- Calling train(mode) switches between train graph and eval graph.
c                ó‚   <€ V ^8„  d   QhRS[ P                  P                  RS[P                  RS[P                  RS[/# )r    ÚrootÚtrain_graphÚ
eval_graphÚ
class_name)rC   r   r$   r
   ÚGraphr%   )r'   r(   s   "€r   r)   ÚDualGraphModule.__annotate__  s=   ø€ ÷ )6ñ )6Ù—H‘H—O‘Oð)6Ù24·(±(ð)6ÙHJÏÉð)6Ù^añ)6r   c                óŠ  <€ \         \        P                  V `  4        W@P                  n        W n        W0n        \        \        VP                  4      \        VP                  4      4       Fm  pVP                  R9   g   K  \        VP                  \        4      '       g"   \        R\!        VP                  4       24      h\#        WVP                  4       Ko  	  V P%                  4        W n        V P                  P(                  V P                  P(                  8w  d;   \        RV P                  P(                   RV P                  P(                   R24      hRV n        V P&                  P(                  '       dE   RV P&                  P(                  P*                  9  d   V P&                  P(                  V n        R# R# R# )zê
Args:
    root (nn.Module): module from which the copied module hierarchy is
        built
    train_graph (fx.Graph): the graph that should be used in train mode
    eval_graph (fx.Graph): the graph that should be used in eval mode
z-node.target should be of type str instead of zGTrain mode and eval mode should use the same tracer class. Instead got z for eval vs z
 for trainNz<locals>)Úget_attrrF   )r   r
   ÚGraphModuler   r   r1   r¹   rº   r   ry   Únodesr^   r-   rN   r%   Ú	TypeErrorr‘   r   r²   ÚgraphÚ_tracer_clsr3   )r   r¸   r¹   rº   r»   rO   r   s   &&&&& €r   r   ÚDualGraphModule.__init__  s~  ø€ ô 	Œb�n‰n˜dÑ,Ô.à",�‰Ôà&ÔØ$Œô œ$˜{×0Ñ0Ó1´4¸
×8HÑ8HÓ3IÖJˆDØ�w‰wÐ5Ö5Ü! $§+¡+¬s×3Ò3Ü#Ð&SÔTXÐY]×YdÑYdÓTeÐSfÐ$gÓhÐhÜ˜4 t§{¡{Ö3ñ	 Kð 	�
‰
ŒØ Œ
ð �?‰?×&Ñ&¨$×*:Ñ*:×*FÑ*FÔFÜØYÐZ^×ZiÑZi×ZuÑZuÐYvð  wDð  EI÷  EUñ  EU÷  Eañ  Eað  Dbð  blð  móð ð  ˆÔØ�:‰:×!×!Ð! j¸¿
¹
×8NÑ8N×8[Ñ8[Ô&[Ø#Ÿz™z×5Ñ5ˆDÖñ '\Ñ!r   c                óÒ   <€ V'       d%   V P                   '       g   V P                  V n        M+V'       g$   V P                   '       d   V P                  V n        \        SV `  VR7      # )z¡
Swap out the graph depending on the selected training mode.
NOTE this should be safe when calling model.eval() because that just
calls this with mode == False.
)Úmode)r°   r¹   rÃ   rº   r   r²   )r   rÇ   r   s   &&€r   r²   ÚDualGraphModule.train@  sD   ø€ ÷ ˜ŸŸ˜Ø×)Ñ)ˆD�Jß˜$Ÿ-Ÿ-˜-ØŸ™ˆDŒJÜ‰w‰} $ˆ}Ó'Ð'r   c                ó"   € \         P                  # ro   )r¶   r   )r   s   &r   Ú_deepcopy_initÚDualGraphModule._deepcopy_initN  s   € ä×'Ñ'Ð'r   c           	     ó¼  € \        V 4      P                  \        V 4      4      pW!\        V 4      &   \        \        P
                  ! V P                  V4      4      pV P                  4       ! W#VP                  R ,          VP                  R,          4       . ROpV FG  pWPP                  9   g   K  \        W%\        P
                  ! V P                  V,          V4      4       KI  	  \        P
                  ! \        V R/ 4      V4      Vn
        \        VP                  9   d;   VP                  \        ,          P                  4        F  w  re\        W&V4       K  	  V# )r¹   rº   Úmeta)Ú_state_dict_hooksÚ_load_state_dict_pre_hooksÚ_load_state_dict_post_hooksÚ_replace_hookÚ_create_node_hooksÚ_erase_node_hooks)r‘   Ú__new__Úidr   Úcopyr   Ú__dict__rÊ   ÚsetattrÚgetattrrÍ   r   Úitems)r   ÚmemoÚresÚfake_modÚextra_preserved_attrsÚattrÚ	attr_names   &&     r   Ú__deepcopy__ÚDualGraphModule.__deepcopy__R  s   € ô �4‹j× Ñ ¤ d£Ó,ˆØŒR�‹X‰Ü"¤4§=¢=°·±ÀÓ#EÓFˆØ×ÑÔ˜c¨X×->Ñ->¸}Õ-MÈx×O`ÑO`ÐamÕOnÔoò!
Ðó *ˆDØ—}‘}Ö$Ü˜¤4§=¢=°·±¸tÕ1DÀdÓ#KÖLñ *ô —=’=¤¨¨v°rÓ!:¸DÓAˆŒÜ)¨S¯X©XÔ5Ø#&§8¡8Ô,JÕ#K×#QÑ#QÖ#S‘�	Ü˜¨Ö-ñ $Tàˆ
r   )rÄ   rº   rÃ   r¹   )rÀ   r,   )r1   r2   r3   r4   r5   r   r²   rÊ   rá   r6   r7   r8   r9   s   @@r   r¶   r¶     s)   ù‡ € ñ÷)6õ )6÷V(ò(÷ò r   r¶   c                ó`  € V ^8„  d   QhR\         P                  R\        \        \        \
        ,          \        \
        \
        3,          3,          ,          R\        \        \        \
        ,          \        \
        \
        3,          3,          ,          R\        \        \        \
        ,          \        \
        \
        3,          3,          ,          R\        \        \
        \        3,          ,          R\        R\        \        \
        \        3,          ,          R\        P                  /# )	r    rª   Úreturn_nodesÚtrain_return_nodesÚeval_return_nodesr«   r¬   r­   r#   )r   r$   r   r	   r†   r%   r    r   r&   r
   rÀ   )r'   s   "r   r)   r)   q  sÕ   € ÷ nñ nÜ�9‰9ðnäœ5¤¤c¥¬D´´c°­NÐ!:Õ;Õ<ðnô !¤¤t¬C¥y´$´s¼C°xµ.Ð'@Õ!AÕBðnô  ¤¤d¬3¥i´´c¼3°hµÐ&?Õ @ÕAð	nô
 œD¤¤c �NÕ+ðnô  ðnô œD¤¤c �NÕ+ðnô ‡^�^ñnr   c                ó¸	  € \        V4      pV P                  p\        ;QJ d    R WV3 4       F  '       d   K   RM	  RM! R WV3 4       4      '       d   \        R4      hVRJ VRJ ,          '       d   \        R4      hVRJ VRJ ,          '       g   \        R4      hR R	 lpVf    V! V4      p\	        V4      p\	        V4      pMV! V4      pV! V4      p/ p	/ p
R
VRV/pR EFv  pVR
8X  d   V P                  4        MVR8X  d   V P                  4        \        R/ VB pVP                  WR7      p\        V \        P                  4      '       d   V P                  P                  MV P                  p\        P                  ! VP                   Wï4      p\#        VP$                  P'                  4       4      p\)        \+        V4      4      \)        V4      8w  d   \        R4      hW¼,          P-                  4        FN  p\/        V Uu. uF   p\0        P2                  ! RV R2V4      RJNK"  	  up4      '       d   KA  \        RV R24      h	  . p\5        VP6                  P8                  4       F'  pVP:                  R8X  g   K  VP=                  V4       K)  	  V'       g   \        R4      hV F  pVP6                  P?                  V4       K   	  VP6                  P8                   Uu. uF  pVNK  	  pp\A        4       p\5        V4       FŸ  pVP$                  PC                  V4      pVf   K$  W¼,           Fo  pVPE                  R4      pRPG                  VPI                  R4      RV^,            4      V8X  g   KE  VVW¼,          V,          &   W¼,          PK                  V4        K�  	  K¡  	  \A        \5        \#        VPM                  4       4      4      4      pVP6                  PO                  VR,          4      ;_uu_ 4        VP6                  PQ                  V4       RRR4       VP6                  PS                  4        VPU                  4        WÙV&   WêV&   EKy  	  V'       g   \W        V	R
,          V	R,          4       \Y        W
R
,          V
R,          XR7      pV P                  V4       VP                  V4       V# u upi u upi   + '       g   i     L³; i)aª  
Creates a new graph module that returns intermediate nodes from a given
model as dictionary with user specified keys as strings, and the requested
outputs as values. This is achieved by re-writing the computation graph of
the model via FX to return the desired nodes as outputs. All unused nodes
are removed, together with their corresponding parameters.

Desired output nodes must be specified as a ``.`` separated
path walking the module hierarchy from top level module down to leaf
operation or leaf module. For more details on the node naming conventions
used here, please see the :ref:`relevant subheading <about-node-names>`
in the `documentation <https://pytorch.org/vision/stable/feature_extraction.html>`_.

Not all models will be FX traceable, although with some massaging they can
be made to cooperate. Here's a (not exhaustive) list of tips:

    - If you don't need to trace through a particular, problematic
      sub-module, turn it into a "leaf module" by passing a list of
      ``leaf_modules`` as one of the ``tracer_kwargs`` (see example below).
      It will not be traced through, but rather, the resulting graph will
      hold a reference to that module's forward method.
    - Likewise, you may turn functions into leaf functions by passing a
      list of ``autowrap_functions`` as one of the ``tracer_kwargs`` (see
      example below).
    - Some inbuilt Python functions can be problematic. For instance,
      ``int`` will raise an error during tracing. You may wrap them in your
      own function and then pass that in ``autowrap_functions`` as one of
      the ``tracer_kwargs``.

For further information on FX see the
`torch.fx documentation <https://pytorch.org/docs/stable/fx.html>`_.

Args:
    model (nn.Module): model on which we will extract the features
    return_nodes (list or dict, optional): either a ``List`` or a ``Dict``
        containing the names (or partial names - see note above)
        of the nodes for which the activations will be returned. If it is
        a ``Dict``, the keys are the node names, and the values
        are the user-specified keys for the graph module's returned
        dictionary. If it is a ``List``, it is treated as a ``Dict`` mapping
        node specification strings directly to output names. In the case
        that ``train_return_nodes`` and ``eval_return_nodes`` are specified,
        this should not be specified.
    train_return_nodes (list or dict, optional): similar to
        ``return_nodes``. This can be used if the return nodes
        for train mode are different than those from eval mode.
        If this is specified, ``eval_return_nodes`` must also be specified,
        and ``return_nodes`` should not be specified.
    eval_return_nodes (list or dict, optional): similar to
        ``return_nodes``. This can be used if the return nodes
        for train mode are different than those from eval mode.
        If this is specified, ``train_return_nodes`` must also be specified,
        and `return_nodes` should not be specified.
    tracer_kwargs (dict, optional): a dictionary of keyword arguments for
        ``NodePathTracer`` (which passes them onto it's parent class
        `torch.fx.Tracer <https://pytorch.org/docs/stable/fx.html#torch.fx.Tracer>`_).
        By default, it will be set to wrap and make leaf nodes all torchvision ops:
        {"autowrap_modules": (math, torchvision.ops,),"leaf_modules": _get_leaf_modules_for_ops(),}
        WARNING: In case the user provides tracer_kwargs, above default arguments will be appended to the user
        provided dictionary.
    suppress_diff_warning (bool, optional): whether to suppress a warning
        when there are discrepancies between the train and eval version of
        the graph. Defaults to False.
    concrete_args (Optional[Dict[str, any]]): Concrete arguments that should
        not be treated as Proxies. According to the `Pytorch docs
        <https://pytorch.org/docs/stable/fx.html#torch.fx.Tracer.trace>`_,
        this parameter's API may not be guaranteed.

Examples::

    >>> # Feature extraction with resnet
    >>> model = torchvision.models.resnet18()
    >>> # extract layer1 and layer3, giving as names `feat1` and feat2`
    >>> model = create_feature_extractor(
    >>>     model, {'layer1': 'feat1', 'layer3': 'feat2'})
    >>> out = model(torch.rand(1, 3, 224, 224))
    >>> print([(k, v.shape) for k, v in out.items()])
    >>>     [('feat1', torch.Size([1, 64, 56, 56])),
    >>>      ('feat2', torch.Size([1, 256, 14, 14]))]

    >>> # Specifying leaf modules and leaf functions
    >>> def leaf_function(x):
    >>>     # This would raise a TypeError if traced through
    >>>     return int(x)
    >>>
    >>> class LeafModule(torch.nn.Module):
    >>>     def forward(self, x):
    >>>         # This would raise a TypeError if traced through
    >>>         int(x.shape[0])
    >>>         return torch.nn.functional.relu(x + 4)
    >>>
    >>> class MyModule(torch.nn.Module):
    >>>     def __init__(self):
    >>>         super().__init__()
    >>>         self.conv = torch.nn.Conv2d(3, 1, 3)
    >>>         self.leaf_module = LeafModule()
    >>>
    >>>     def forward(self, x):
    >>>         leaf_function(x.shape[0])
    >>>         x = self.conv(x)
    >>>         return self.leaf_module(x)
    >>>
    >>> model = create_feature_extractor(
    >>>     MyModule(), return_nodes=['leaf_module'],
    >>>     tracer_kwargs={'leaf_modules': [LeafModule],
    >>>                    'autowrap_functions': [leaf_function]})

c              3   ó(   "  € T F  qR J x € K
  	  R # 5iro   rp   )rq   Úargs   & r   rt   Ú+create_feature_extractor.<locals>.<genexpr>é  s   é € Ð
XÑ"W˜3�$�;Ó"Wùs   ‚FTzcEither `return_nodes` or `train_return_nodes` and `eval_return_nodes` together, should be specifiedNzcIf any of `train_return_nodes` and `eval_return_nodes` are specified, then both should be specifiedz\If `train_return_nodes` and `eval_return_nodes` are specified, then both should be specifiedc                óF   € V ^8„  d   QhR\         \        \        3,          /# r�   )r    r%   )r'   s   "r   r)   Ú.create_feature_extractor.<locals>.__annotate__ø  s   € ÷ 6ñ 6œœc¤3˜h�ñ 6r   c                 óü   € \        V \        4      '       d&   V  Uu/ uF  p\        V4      \        V4      bK  	  up# V P                  4        UUu/ uF  w  r#\        V4      \        V4      bK  	  upp# u upi u uppi ro   )r-   r†   r%   rÚ   )ÚnÚiÚkÚvs   &   r   Ú
to_strdictÚ,create_feature_extractor.<locals>.to_strdictø  sa   € Ü�aœ×ÒÙ,-Ó.©A q”C˜“FœC ›F’N©AÑ.Ð.Ø+,¯7©7¬9Ô5©9¡4 1”�A“œ˜A›’©9Ò5Ð5ùò /ùÛ5s   ›A3Á A8r²   r³   r¯   zYThere are duplicate nodes! Please raise an issue https://github.com/pytorch/vision/issuesÚ^z(\.|$)znode: 'z×' is not present in model. Hint: use `get_graph_node_names` to make sure the `return_nodes` you specified are present. It may even be that you need to specify `train_return_nodes` and `eval_return_nodes` separately.Úoutputz1No output nodes found in graph_module.graph.nodesr\   )r»   )r²   r³   rp   éÿÿÿÿ)-r¨   r°   rz   Ú
ValueErrorr   r²   r³   r;   r±   r-   r   r$   r   r1   r
   rÀ   r¸   r†   r?   rd   r_   r¤   Úkeysrv   r`   ra   rc   rÃ   rÁ   r^   r™   Ú
erase_noder   ÚgetÚcountÚjoinÚsplitr   rÚ   Úinserting_afterrõ   Úeliminate_dead_codeÚ	recompilerŽ   r¶   )rª   rä   rå   ræ   r«   r¬   r­   r´   rò   ÚtracersÚgraphsÚmode_return_nodesrÇ   ÚtracerrÃ   rU   Úgraph_moduleÚavailable_nodesÚqueryrî   Úorig_output_nodesrÁ   Úoutput_nodesr"   Údepths   &&&&&&&                  r   r   r   q  sR  € ôj /¨}Ó=€MØ—.‘.€Kç
ƒsÑ
X <ÐEVÑ"WÓ
X‡s‡s‚sÑ
X <ÐEVÑ"WÓ
X×XÒXäØqó
ð 	
ð 	˜dÐ"Ð'8¸DÐ'@×AÔAÜØqó
ð 	
ð ˜TÐ!Ð&8¸DÐ&@×AÔAÜÐwÓxÐxõ6ð
 Ò!Ù! ,Ó/ˆÜ% lÓ3ÐÜ$ \Ó2Ñá'Ð(:Ó;ÐÙ&Ð'8Ó9Ðð €GØ€FØ4;Ð=OÐQWÐYjÐ3kÐÜ!ˆØ�7Œ?Ø�K‰K�MØ�VŒ^Ø�J‰JŒLô  Ñ0 -Ñ0ˆØ—‘˜U�Ó@ˆä+5°e¼R¿Y¹Y×+GÒ+Gˆu�‰×'Ò'ÈUÏ^É^ˆÜ—~’~ f§k¡k°5Ó?ˆä˜v×6Ñ6×=Ñ=Ó?Ó@ˆäŒs�?Ó#Ó$¬¨OÓ(<Ô<ÜØkóð ð 'Õ,×1Ñ1Ö3ˆEô É_Ó]É_ÈœŸš A e W¨FÐ!3°QÓ7¸tÓCÉ_Ñ]×^Ô^Ü Ø˜e˜Wð %6ð 6óð ñ	 4ð ÐÜ˜,×,Ñ,×2Ñ2Ö3ˆAØ�t‰t�xÖØ!×(Ñ(¨Ö+ñ 4÷ !ÜÐPÓQÐQã"ˆAØ×Ñ×)Ñ)¨!Ö,ñ #ð )×.Ñ.×4Ò4Ó5Ñ4�q“Ñ4ˆÐ5Ü"“}ˆÜ˜%–ˆAØ$×5Ñ5×9Ñ9¸!Ó<ˆOØÒ&ñ
 Ø*×0Ð0�ØŸ™ CÓ(�Ø—8‘8˜O×1Ñ1°#Ó6°{¸À½ÐCÓDÈÖMØCD�LÐ!2Õ!8¸Õ!?Ñ@Ø%Õ+×/Ñ/°Ô6Úó 1ñ !ô #¤8¬D°×1CÑ1CÓ1EÓ,FÓ#GÓHˆð ×Ñ×/Ñ/°°bµ	×:Õ:Ø×Ñ×%Ñ% lÔ3÷ ;ð 	×Ñ×.Ñ.Ô0Ø×ÑÔ ð �‰ØˆtŒñQ "÷X !Ü ¨Õ 0°'¸&µ/ÔBô # 5°­/¸6À&½>ÐVZÔ[€Lð 
‡K�K�ÔØ×Ñ�{Ô#àÐùò ^ùò* 6÷& ;×:ús   È&R?Ë(SÐS	Ó	S)NFN)NNNNFN)#rÖ   r“   r£   r`   rˆ   Úcollectionsr   r   Ú	itertoolsr   Útypingr   r   r   r	   rC   r•   r
   r   Útorch.fx.graph_moduler   r   r   Ú__all__ÚTracerr   r;   r}   rŽ   r�   r¨   r   rÀ   r¶   r   rp   r   r   Ú<module>r     s™   ðÛ Û Û Û 	Û Ý #Ý Ý ß 1Ó 1ã Û ß ß ]Ñ ]ð &Ð'=Ð
>€ô:˜BŸI™Iô :ô(`Ð*ô `òFKõ(õ>õ ÷">#ôBa�b—n‘nô a÷Hnñ nr   