+
    ˜°³jœ©  ã            	       óâ  a € RR tc0 t R t^ RIHt ^ RIt^ RIt^ RIHtHtH	t	 ^RI
Ht ^ RIHtHt ^ RIHt ^ RIHt ^ RIHt ^ R	IHt ^ R
IHt ^ RIHt ^ RIHt ^ RItRR.t]! R4      t]! R4      t]P@                  ! ]!4      t" ^ RI#H$t% ]PR                  PT                  t*R t+/ t,] ^ k R t-RTR R llt.].! ]*P^                  4      RR/R R ll4       t0].! ]*Pb                  4      R R l4       t2].! ]*Pf                  4      R R  l4       t4].! ]*Pj                  4      R! R" l4       t6].! ]*Pn                  4      RUR# R$ ll4       t8RTR% R& llt9].! ]*Pt                  ]*Pv                  ]*Px                  ]*Pz                  ]*P|                  .4      RR/R' R( ll4       t?].! ]*P€                  4      R) R* l4       tAR+ tB].! ]*P†                  ]*Pˆ                  ]*PŠ                  .4      RR/R, R- ll4       tFR. tGR/R/R0 R1 lltHR/R/R2 R3 lltI].! ]*P”                  RR47      RR/R5 R6 ll4       tK].! ]*P˜                  RR47      R7 R8 l4       tMR9 tN].! ]*Pž                  ]*P                   ]*P¢                  .4      RR/R: R; ll4       tR].! ]*P¦                  RR47      R< R= l4       tT].! ]*Pª                  RR47      R> R? l4       tVR@ RA ltWRBR/RC RD lltXRBR/RE RF lltYRBR/RG RH lltZ/ ]*P^                  ]0b]*Pb                  ]2b]*Pf                  ]4b]*Pj                  ]6b]*Pn                  ]8b]*Pt                  ]?b]*Pv                  ]?b]*Px                  ]?b]*P|                  ]?b]*Pz                  ]?b]*P€                  ]Ab]*P†                  ]Fb]*Pˆ                  ]Fb]*PŠ                  ]Fb]*Pž                  ]Rb]*P                   ]Rb]*P¢                  ]Rb]*P”                  ]K]*P˜                  ]M]*P¦                  ]T]*Pª                  ]V/Ct,]W! 4        RI t[. RVOt\RJ t]RK t^RL RM lt_RN t` ! RO R4      ta ! RP RQ]4      tbR#   ]& dN    ]';QJ d    R RS 4       F  '       g   K   RM	  RM! R RS 4       4      '       d   ]"PQ                  R4       ]t% ELãi ; i)WaE  Utilities for counting theoretical floating point operations.

``FlopCounterMode`` is a context manager that intercepts PyTorch operators and
adds up their registered FLOP formulas. The result is a shape-based,
theoretical FLOP count for the operators that ran inside the context, not a
hardware performance measurement.

The counter is useful when comparing model graphs, activation checkpointing
plans, or shape changes with a stable FLOP accounting rule. It should not be
read as kernel instructions, wall-clock time, memory bandwidth, achieved
FLOP/s, Tensor Core utilization, or the exact work done by a fused kernel.

Counting semantics
------------------

* Counts are produced by formulas in ``flop_registry``. Operators without a
  formula may be decomposed into registered operators; otherwise they add zero
  FLOPs.
* Formula inputs have tensor arguments replaced by their shapes by default.
  Non-tensor arguments pass through unchanged. Use
  ``register_flop_formula(..., get_raw=True)`` only when the formula needs the
  original tensor arguments or metadata.
* Forward and backward operations are counted only if they execute while the
  context manager is active.
* The default formulas use dense, naive mathematical definitions. For example,
  matrix multiplication counts ``2 * m * n * k`` FLOPs.
* Counts do not automatically adjust for dtype-specific throughput, Tensor
  Cores, sparsity, quantization, masking, skipped elements, memory movement, or
  data-dependent early exits. A formula must explicitly model those semantics.
  For example, the built-in attention formulas are upper bounds for causal or
  otherwise masked attention unless the formula explicitly models the mask.
* Higher-order operators and ``torch.compile`` may expose decomposed or fused
  work differently from eager execution. Custom operators and custom Triton
  kernels need a formula or a decomposition if they should contribute FLOPs.
* Module attribution is tracked through ``ModuleTracker``. Totals are always
  available under ``"Global"``; submodule rows are best-effort attribution for
  module calls observed during the context.
* The workload still executes normally. Use this mode for a few representative
  iterations rather than long training runs if overhead or memory use matters.

Example
-------

.. code-block:: python

    import torch
    from torch.utils.flop_counter import FlopCounterMode

    model = torch.nn.Linear(16, 32)
    x = torch.randn(4, 16)

    with FlopCounterMode(display=False) as mode:
        model(x).sum().backward()

    print(mode.get_total_flops())
    print(mode.get_flop_counts()["Global"])

Registering a formula for a custom op
-------------------------------------

Register custom FLOP formulas before constructing ``FlopCounterMode``. The
mode snapshots the global registry during initialization.

.. code-block:: python

    from math import prod

    import torch
    from torch.utils.flop_counter import FlopCounterMode, register_flop_formula

    @torch.library.custom_op("example::scale", mutates_args=())
    def scale(x: torch.Tensor) -> torch.Tensor:
        return x * 2

    @register_flop_formula(torch.ops.example.scale)
    def scale_flops(x_shape, *, out_shape=None) -> int:
        return prod(x_shape)

    x = torch.randn(8)
    with FlopCounterMode(display=False) as mode:
        scale(x)

    assert mode.get_total_flops() == 8
)ÚNoneTypeN)Útree_mapÚtree_flattenÚtree_unflatten)ÚModuleTracker)ÚAnyÚTypeVar)ÚCallable)ÚIterator)Ú	ParamSpec)Údefaultdict)ÚTorchDispatchMode©Úprod©ÚwrapsÚFlopCounterModeÚregister_flop_formulaÚ_TÚ_P©ÚJITFunctionc              #   ó\   "  € T F"  p\        \        P                  VR 4      R Jx € K$  	  R # 5i©N)ÚgetattrÚtorchÚversion)Ú.0Úattrs   & ÚY/home/luca/screen-checking/.venv/lib/python3.14/site-packages/torch/utils/flop_counter.pyÚ	<genexpr>r    p   s$   é € Ð
]ÑF\¸dŒ7”5—=‘= $¨Ó-°TÕ9ÓF\ùs   ‚*,TFz@triton not found; flop counting will not work for triton kernelsc                 ó^   € \        V \        P                  4      '       d   V P                  # V # r   )Ú
isinstancer   ÚTensorÚshape)Úis   &r   Ú	get_shaper&   w   s!   € Ü�!”U—\‘\×"Ò"Ø�w‰wˆØ€Hó    c                 ó8   a € \        S 4      R R/V 3R ll4       pV# )Úout_valNc                 óB   <€ \        \        WV 34      w  rpS! VR V/VB # )Ú	out_shape)r   r&   )r)   ÚargsÚkwargsr+   Úfs   $*, €r   ÚnfÚshape_wrapper.<locals>.nf   s.   ø€ ä"*¬9°tÀWÐ6MÓ"NÑˆ�iÙ�$Ð6 )Ð6¨vÑ6Ð6r'   r   ©r.   r/   s   f r   Úshape_wrapperr2   ~   s'   ø€ Ü
ˆ1ƒXð7˜$ö 7ó ð7ð €Ir'   c                óŒ   € V ^8„  d   QhR\         \         \        \        3,          .\         \        \        3,          3,          /# ©é   Úreturn©r	   r   r   )Úformats   "r   Ú__annotate__r9   …   s6   € ÷ ñ ´X¼xÌÌBÈÕ?OÐ>PÔRZÔ[]Ô_aÐ[aÕRbÐ>bÕ5cñ r'   c                 ó   a a€ R  VV 3R llpV# )c                ót   € V ^8„  d   QhR\         \        \        3,          R\         \        \        3,          /# )r5   Úflop_formular6   r7   )r8   s   "r   r9   Ú+register_flop_formula.<locals>.__annotate__‡   s,   € ÷ ñ ¤8¬B´¨FÕ#3ð ¼ÄÄRÀÕ8Hñ r'   c                 ó–   <a € S'       g   \        S 4      o R  V 3R llp\        P                  P                  P	                  VS4       S # )c                ó   € V ^8„  d   QhRR/# ©r5   r6   N© )r8   s   "r   r9   ÚAregister_flop_formula.<locals>.register_fun.<locals>.__annotate__‹   s   € ÷ 	1ñ 	1 ñ 	1r'   c                 óî   <€ ^ RI Hp \        V \        P                  P
                  \        V34      '       g   \        RV  R\        V 4       24      hV \        9   d   \        RV  24      hS\        V &   R# )é    )ÚHigherOrderOperatorz‘register_flop_formula(targets): expected each target to be OpOverloadPacket (i.e. torch.ops.mylib.foo), JitFunction, or HigherOrderOperator, got z which is of type zduplicate registrations for N)Ú
torch._opsrE   r"   r   Ú_opsÚOpOverloadPacketÚ_JITFunctionÚ
ValueErrorÚtypeÚflop_registryÚRuntimeError)ÚtargetrE   r<   s   & €r   ÚregisterÚ=register_flop_formula.<locals>.register_fun.<locals>.register‹   sx   ø€ Ý6ä˜v¬¯
©
×(CÑ(CÄ\ÐSfÐ'g×hÒhÜ ðð $˜HÐ$6´t¸F³|°nðFóGð Gð
 œÔ&Ü"Ð%AÀ&ÀÐ#JÓKÐKØ$0ŒM˜&Ó!r'   )r2   r   ÚutilsÚ_pytreeÚ	tree_map_)r<   rO   Úget_rawÚtargetss   f €€r   Úregister_funÚ+register_flop_formula.<locals>.register_fun‡   s<   ù€ ßÜ(¨Ó6ˆL÷	1ð 	1ô 	�‰×Ñ×%Ñ% h°Ô8àÐr'   rA   )rU   rT   rV   s   ff r   r   r   …   s   ù€ ÷ñ ð, Ðr'   r+   c                ó$   € V ^8„  d   QhR\         /# r4   ©Úint)r8   s   "r   r9   r9       s   € ÷ 	ñ 	Ä#ñ 	r'   c               ól   € V w  rVVw  rxWg8w  d   \        RV RV 24      hWX,          ^,          V,          # )zCount flops for matmul.z3matmul: inner dimensions must match (k == k2), got ú and ©ÚAssertionError)	Úa_shapeÚb_shaper+   r,   r-   ÚmÚkÚk2Úns	   &&$*,    r   Úmm_flopre   Ÿ   sE   € ð
 �D€AØ�E€BØ„wÜÐRÐSTÐRUÐUZÐ[]ÐZ^Ð_Ó`Ð`à�5�1�9�q�=Ðr'   c                ó$   € V ^8„  d   QhR\         /# r4   rY   )r8   s   "r   r9   r9   ¬   s   € ÷ %ñ %Äñ %r'   c                ó   € \        W4      # )zCount flops for addmm.©re   ©Ú
self_shaper_   r`   r,   r-   s   &&&*,r   Ú
addmm_floprk   «   s   € ô �7Ó$Ð$r'   c                ó$   € V ^8„  d   QhR\         /# r4   rY   )r8   s   "r   r9   r9   ±   s   € ÷ ñ ´3ñ r'   c                ó°   € V w  rEpVw  rxp	WG8w  d   \        RV RV 24      hWh8w  d   \        RV RV 24      hWE,          V	,          ^,          V,          p
V
# )z"Count flops for the bmm operation.z0bmm: batch dimensions must match (b == b2), got r\   z0bmm: inner dimensions must match (k == k2), got r]   )r_   r`   r,   r-   Úbra   rb   Úb2rc   rd   Úflops   &&*,       r   Úbmm_floprq   °   ss   € ð
 �G€Aˆ!Ø�I€BˆAØ„wÜÐOÐPQÈsÐRWÐXZÐW[Ð\Ó]Ð]Ø„wÜÐOÐPQÈsÐRWÐXZÐW[Ð\Ó]Ð]à�5�1�9�q�=˜1Õ€DØ€Kr'   c                ó$   € V ^8„  d   QhR\         /# r4   rY   )r8   s   "r   r9   r9   À   s   € ÷ &ñ &Ä3ñ &r'   c                ó   € \        W4      # )z&Count flops for the baddbmm operation.)rq   ri   s   &&&*,r   Úbaddbmm_floprt   ¿   s   € ô
 �GÓ%Ð%r'   c                ó$   € V ^8„  d   QhR\         /# r4   rY   )r8   s   "r   r9   r9   Ç   s   € ÷ %ñ %ô 	ñ%r'   c	                ó   € \        W4      # )zCount flops for _scaled_mm.rh   )
r_   r`   Úscale_a_shapeÚscale_b_shapeÚ
bias_shapeÚscale_result_shapeÚ	out_dtypeÚuse_fast_accumr+   r-   s
   &&&&&&&&&,r   Ú_scaled_mm_flopr}   Æ   s   € ô �7Ó$Ð$r'   c          
      ó–   € V ^8„  d   QhR\         \        ,          R\         \        ,          R\         \        ,          R\        R\        /# )r5   Úx_shapeÚw_shaper+   Ú
transposedr6   )ÚlistrZ   Úbool)r8   s   "r   r9   r9   ×   sF   € ÷ $ñ $Ü”#�Yð$ä”#�Yð$ô ”C�yð$ô ð	$ô
 	ñ$r'   c                ó¶   € V ^ ,          pV'       d   T MTR,          pVvrgp \        V4      \        V4      ,          V,          V,          V,          ^,          p	V	# )aÖ  Count flops for convolution.

Note only multiplication is
counted. Computation for bias are ignored.
Flops for a transposed convolution are calculated as
flops = (x_shape[2:] * prod(w_shape) * batch_size).
Args:
    x_shape (list(int)): The input shape before convolution.
    w_shape (list(int)): The filter shape.
    out_shape (list(int)): The output shape after convolution.
    transposed (bool): is the convolution transposed
Returns:
    int: the number of flops
ºr5   NNr   )
r   r€   r+   r�   Ú
batch_sizeÚ
conv_shapeÚc_outÚc_inÚfilter_sizerp   s
   &&&&      r   Úconv_flop_countr‹   ×   sY   € ð( ˜•€Jß'‘'¨Y¸Õ;€JØ 'Ð€E�+ðô �
Óœd ;Ó/Õ/°*Õ<¸uÕDÀtÕKÈaÕO€DØ€Kr'   c                ó$   € V ^8„  d   QhR\         /# r4   rY   )r8   s   "r   r9   r9     s   € ÷ Oñ OÔuxñ Or'   c               ó   € \        WWvR7      # )zCount flops for convolution.©r�   )r‹   )
r   r€   Ú_biasÚ_strideÚ_paddingÚ	_dilationr�   r+   r,   r-   s
   &&&&&&&$*,r   Ú	conv_flopr“   ý   s   € ô ˜7¨YÔNÐNr'   c                ó$   € V ^8„  d   QhR\         /# r4   rY   )r8   s   "r   r9   r9   	  s   € ÷ fñ fô ñfr'   c                 óz  € R  p^ p V
^ ,          '       d+   \        V^ ,          4      pV\        WW÷'       * 4      ,          pV
^,          '       dm   \        V^,          4      pV'       d+   V\        V! V 4      V! V4      V! V4      RR7      ,          pV# V\        V! V4      V! V 4      V! V4      RR7      ,          pV# )c                 óT   € V ^,          V ^ ,          .\        V R,          4      ,           # )é   r…   )r‚   )r$   s   &r   ÚtÚconv_backward_flop.<locals>.t  s"   € Ø�a•˜% �(Ð#¤d¨5°­9£oÕ5Ð5r'   FrŽ   )r&   r‹   )Úgrad_out_shaper   r€   r�   r�   r‘   r’   r�   Ú_output_paddingÚ_groupsÚoutput_maskr+   r-   r˜   Ú
flop_countÚgrad_input_shapeÚgrad_weight_shapes   &&&&&&&&&&&&,    r   Úconv_backward_flopr¡     s·   € ò 6à€JðDðL �1‡~„~Ü$ Y¨q¥\Ó2ÐØ”o nÐ?OÔQ_Ó`Õ`ˆ
à�1‡~„~Ü% i°¥lÓ3Ðßàœ/©!¨NÓ*;¹Q¸w»ZÉÐK\ÓI]ÐjoÔpÕpˆJð
 Ðð œ/©!¨G«*±a¸Ó6GÉÐK\ÓI]ÐjoÔpÕpˆJàÐr'   c                ól  € V w  r4rVVw  rxršVw  r¼rÞY7u;8X  d   V8X  d   M MWŒ8X  d   Wj8X  d   W�8X  g   \        RV  RV RV 24      hWH8  g   WH,          ^ 8w  d   \        RV RV R24      h^ pV\        W4,          WV3W4,          Wi34      ,          pV\        W4,          WY3W4,          Wž34      ,          pV# )z¯
Count flops for self-attention.

Supports GQA (grouped-query attention) where key/value have fewer heads
than the query. The kernel broadcasts KV heads to match query heads.
z<sdpa_flop_count: query/key/value shapes are incompatible: q=z, k=z, v=zsdpa_flop_count: query heads (ú)) must be a multiple of key/value heads (Ú)©r^   rq   )Úquery_shapeÚ	key_shapeÚvalue_shapern   Úh_qÚs_qÚd_qÚ_b2Úh_kvÚs_kÚ_d2Ú_b3Ú_h3Ú_s3Úd_vÚtotal_flopss   &&&             r   Úsdpa_flop_countrµ   q  sÞ   € ð #Ñ€AˆCØ#Ñ€CˆsØ$Ñ€CˆcØŽO˜�O ¤°´
¸s¼zÜðØ�˜T ) ¨D°°ð?ó
ð 	
ð „z�S•Z 1”_ÜØ,¨S¨Eð 2 Ø $˜v Qð(ó
ð 	
ð €Kà”8˜Q�W cÐ/°!µ'¸3Ð1DÓEÕE€Kà”8˜Q�W cÐ/°!µ'¸3Ð1DÓEÕE€KØÐr'   c                ó$   € V ^8„  d   QhR\         /# r4   rY   )r8   s   "r   r9   r9   �  s   € ÷ @ñ @ÔWZñ @r'   c               ó   € \        WV4      # )úCount flops for self-attention.©rµ   )r¦   r§   r¨   r+   r,   r-   s   &&&$*,r   Ú	sdpa_floprº   �  s   € ô ˜;°;Ó?Ð?r'   c                ó
  € ^ RI Hp ^ RIHp V! V 4      '       gK   \	        W4      '       g:   V P
                  P                  R8w  d   V P                  4       P                  4       # V.V P                  ^ 4      ^,
          ,          # )z“
If the offsets tensor is fake, then we don't know the actual lengths.
In that case, we can just assume the worst case; each batch has max length.
)Úis_fake_tensor)ÚFunctionalTensorÚmeta)
Útorch._subclasses.fake_tensorr¼   Ú#torch._subclasses.functional_tensorr½   r"   ÚdevicerK   ÚdiffÚtolistÚsize)ÚoffsetsÚmax_lenr¼   r½   s   &&  r   Ú_offsets_to_lengthsrÇ   –  sc   € õ
 =ÝDÙ˜7×#Ò#¤z°'×'LÒ'LÐRY×R`ÑR`×ReÑReÐioÔRoØ�|‰|‹~×$Ñ$Ó&Ð&Øˆ9˜Ÿ™ Q›¨!Õ+Õ,Ð,r'   Úgrad_outc          	      óæ   € V ^8„  d   QhR\         \        \        \        R3,          \        \        R3,          \        \        R3,          \        \        R3,          R,          3,          ,          /# ©r5   r6   .N©r
   ÚtuplerZ   )r8   s   "r   r9   r9   ¢  sS   € ÷ 1`ñ 1`ô Œe”Eœ#˜s˜(•O¤U¬3°¨8¥_´e¼CÀ¸HµoÄuÌSÐRUÈXÅÐY]ÕG]Ð]Õ^Õ_ñ1`r'   c              #  óò  "  € VEe8   \        VP                  4      ^8w  d   \        R4      h\        VP                  4      ^8w  d   \        R4      hVe'   VP                  V P                  8w  d   \        R4      hV P                  w  r‰p
VP                  w  r‹pVP                  w  r�pVf   \        R4      hVf   \        R4      hVP                  VP                  8w  d   \        R4      h\        WF4      p\        WW4      p\	        VVRR	7       F(  w  pp^V	VV
3p^VVV3p^VVV3pVe   TMRpVVVV3x € K*  	  R# V P                  VP                  VP                  Ve   VP                  MR3x € R# 5i)
a'  
Given inputs to a flash_attention_(forward|backward) kernel, this will handle behavior for
NestedTensor inputs by effectively unbinding the NestedTensor and yielding the shapes for
each batch element.

In the case that this isn't a NestedTensor kernel, then it just yields the original shapes.
Nz7sdpa_flop_count: expected key.shape to be 3-dimensionalz9sdpa_flop_count: expected value.shape to be 3-dimensionalzDsdpa_flop_count: grad_out.shape must match query.shape when providedz+sdpa_flop_count: cum_seq_q must not be Nonez+sdpa_flop_count: cum_seq_k must not be NonezAsdpa_flop_count: cum_seq_q and cum_seq_k must have the same shapeT©Ústrict©Úlenr$   r^   rÇ   Úzip)ÚqueryÚkeyÚvaluerÈ   Ú	cum_seq_qÚ	cum_seq_kÚmax_qÚmax_kÚ_r©   r«   Úh_kÚd_kÚh_vr³   Úseq_q_lengthsÚseq_k_lengthsÚ	seq_q_lenÚ	seq_k_lenÚnew_query_shapeÚnew_key_shapeÚnew_value_shapeÚnew_grad_out_shapes   $$$$$$$$               r   Ú%_unpack_flash_attention_nested_shapesræ   ¢  sp  é € ð$ Óô ˆs�y‰y‹>˜QÔÜ Ð!ZÓ[Ð[Üˆu�{‰{Ó˜qÔ Ü Ð!\Ó]Ð]ØÒ H§N¡N°e·k±kÔ$AÜ Ð!gÓhÐhØ—k‘k‰ˆ�Ø—i‘i‰ˆ�Ø—k‘k‰ˆ�ØÒÜ Ð!NÓOÐOØÒÜ Ð!NÓOÐOØ�?‰?˜iŸo™oÔ-Ü Ð!dÓeÐeÜ+¨IÓ=ˆÜ+¨IÓ=ˆÜ&)¨-¸Èt×&TÑ"ˆY˜	Ø  # y°#Ð6ˆOØ  Y°Ð4ˆMØ  # y°#Ð6ˆOØ4<Ò4H¡ÈdÐØ! =°/ÐCUÐUÔUñ 'Uñ 	à
�+‰+�s—y‘y %§+¡+ÀÒAU¨x¯~ª~Ð[_Ð
_Ô_ùs   ‚E5E7c          	      óæ   € V ^8„  d   QhR\         \        \        \        R3,          \        \        R3,          \        \        R3,          \        \        R3,          R,          3,          ,          /# rÊ   rË   )r8   s   "r   r9   r9   Ö  sS   € ÷ 4`ñ 4`ô Œe”Eœ#˜s˜(•O¤U¬3°¨8¥_´e¼CÀ¸HµoÄuÌSÐRUÈXÅÐY]ÕG]Ð]Õ^Õ_ñ4`r'   c              #  óø  "  € VEe;   \        VP                  4      ^8w  d   \        R4      h\        VP                  4      ^8w  d   \        R4      hVe'   VP                  V P                  8w  d   \        R4      hV P                  w   r‰p
VP                  w   r‹pVP                  w   r�pVf   \        R4      hVf   \        R4      hVP                  VP                  8w  d   \        R4      h\        WF4      p\        WW4      p\	        VVRR	7       F(  w  pp^V	VV
3p^VVV3p^VVV3pVe   TMRpVVVV3x € K*  	  R# V P                  VP                  VP                  Ve   VP                  MR3x € R# 5i)
a+  
Given inputs to a efficient_attention_(forward|backward) kernel, this will handle behavior for
NestedTensor inputs by effectively unbinding the NestedTensor and yielding the shapes for
each batch element.

In the case that this isn't a NestedTensor kernel, then it just yields the original shapes.
NzQ_unpack_efficient_attention_nested_shapes: expected key.shape to be 4-dimensionalzS_unpack_efficient_attention_nested_shapes: expected value.shape to be 4-dimensionalz^_unpack_efficient_attention_nested_shapes: grad_out.shape must match query.shape when providedzH_unpack_efficient_attention_nested_shapes: cu_seqlens_q must not be NonezH_unpack_efficient_attention_nested_shapes: cu_seqlens_k must not be Noneza_unpack_efficient_attention_nested_shapes: cu_seqlens_q and cu_seqlens_k must have the same shapeTrÎ   rÐ   )rÓ   rÔ   rÕ   rÈ   Úcu_seqlens_qÚcu_seqlens_kÚmax_seqlen_qÚmax_seqlen_krÚ   r©   r«   rÛ   rÜ   rÝ   r³   Ú	seqlens_qÚ	seqlens_kÚlen_qÚlen_krâ   rã   rä   rå   s   $$$$$$$$               r   Ú)_unpack_efficient_attention_nested_shapesrñ   Ö  s‹  é € ð$ Óô ˆs�y‰y‹>˜QÔÜ Ð!tÓuÐuÜˆu�{‰{Ó˜qÔ Ü Ð!vÓwÐwØÒ H§N¡N°e·k±kÔ$AÜ ð  "Bó  Cð  CØŸ™‰ˆˆ1�3ØŸ™‰ˆˆ1�3ØŸ™‰ˆˆ1�3ØÒÜ Ð!kÓlÐlØÒÜ Ð!kÓlÐlØ×Ñ ×!3Ñ!3Ô3Ü ð "Zó [ð [ä'¨ÓCˆ	Ü'¨ÓCˆ	Ü 	¨9¸T×B‰LˆE�5Ø  # u¨cÐ2ˆOØ  U¨CÐ0ˆMØ  # u¨cÐ2ˆOØ4<Ò4H¡ÈdÐØ! =°/ÐCUÐUÔUñ Cñ 	à
�+‰+�s—y‘y %§+¡+ÀÒAU¨x¯~ª~Ð[_Ð
_Ô_ùs   ‚E8E:©rT   c                ó$   € V ^8„  d   QhR\         /# r4   rY   )r8   s   "r   r9   r9     s   € ÷  ñ  ô 	ñ r'   c          
     óà   € VfH   V P                   ^8X  d7   V P                  RR4      p VP                  RR4      pVP                  RR4      p\        V VVVVVVR7      p
\        R V
 4       4      # )r¸   ©rÓ   rÔ   rÕ   rÖ   r×   rØ   rÙ   c              3   ó@   "  € T F  w  rr4\        WV4      x € K  	  R # 5ir   r¹   ©r   r¦   r§   r¨   rÚ   s   &    r   r    Ú0_flash_attention_forward_flop.<locals>.<genexpr>+  ó&   é € ð á6;Ñ2ˆK Kô 	˜°×<Ð<Û6;ùó   ‚éþÿÿÿéýÿÿÿ©ÚndimÚ	transposeræ   Úsum)rÓ   rÔ   rÕ   rÖ   r×   rØ   rÙ   r+   r,   r-   Úsizess   &&&&&&&$*, r   Ú_flash_attention_forward_flopr    s�   € ð Ò˜UŸZ™Z¨1œ_Ø—‘  BÓ'ˆØ�m‰m˜B Ó#ˆØ—‘  BÓ'ˆô 2ØØØØØØØô€Eô ñ á6;óó ð r'   c                ó$   € V ^8„  d   QhR\         /# r4   rY   )r8   s   "r   r9   r9   2  s   € ÷ ñ ô 	ñr'   c           
     óJ   € \        V VVVVVVR7      p
\        R V
 4       4      # )r¸   )rÓ   rÔ   rÕ   ré   rê   rë   rì   c              3   ó@   "  € T F  w  rr4\        WV4      x € K  	  R # 5ir   r¹   r÷   s   &    r   r    Ú4_efficient_attention_forward_flop.<locals>.<genexpr>K  rù   rú   ©rñ   r   )rÓ   rÔ   rÕ   Úbiasré   rê   rë   rì   r,   r-   r  s   &&&&&&&&*, r   Ú!_efficient_attention_forward_flopr	  1  s?   € ô" 6ØØØØ!Ø!Ø!Ø!ô€Eô ñ á6;óó ð r'   c                 óŠ  € Vw  rErgVw  r‰r«Vw  rÍrïV w  ppppYHu;8X  d   Tu;8X  d   V8X  d   M MW�8X  d   VV8X  g   \        R 4      hWY8  g   WY,          ^ 8w  d   \        RV RV	 R24      hW{8X  d   VV8X  d   W®8X  d   VV8X  g   \        R4      h^ pV\        WE,          Wg3WE,          Wz34      ,          pV\        WE,          Wo3WE,          Wú34      ,          pV\        WE,          W¦3WE,          Wo34      ,          pV\        WE,          Wj3WE,          W§34      ,          pV\        WE,          Wv3WE,          Wj34      ,          pV# )z<sdpa_backward_flop_count: batch/heads mismatch among tensorsz'sdpa_backward_flop_count: query heads (r£   r¤   zJsdpa_backward_flop_count: grad_out/value/key/query shapes are incompatibler¥   )rš   r¦   r§   r¨   rn   r©   rª   r«   r¬   r­   r®   r¯   r°   r±   r²   r³   Ú_b4Ú_h4Ú_s4Ú_d4r´   s   &&&&                 r   Úsdpa_backward_flop_countr  Q  sa  € Ø"Ñ€AˆCØ#Ñ€CˆsØ$Ñ€CˆcØ'Ñ€Cˆˆc�3ØÖ"˜Ö"˜s×" t¤{°s¸c´zÜØJó
ð 	
ð „z�S•Z 1”_ÜØ5°c°Uð ; Ø $˜v Qð(ó
ð 	
ð ŒJ˜3 #œ:¨#¬*¸À¼ÜØXó
ð 	
ð €Kð ”8˜Q�W cÐ/°!µ'¸3Ð1DÓEÕE€Kð ”8˜Q�W cÐ/°!µ'¸3Ð1DÓEÕE€Kà”8˜Q�W cÐ/°!µ'¸3Ð1DÓEÕE€Kð ”8˜Q�W cÐ/°!µ'¸3Ð1DÓEÕE€Kà”8˜Q�W cÐ/°!µ'¸3Ð1DÓEÕE€KØÐr'   c                ó$   € V ^8„  d   QhR\         /# r4   rY   )r8   s   "r   r9   r9   y  s   € ÷ Yñ YÔpsñ Yr'   c               ó   € \        WW#4      # )z(Count flops for self-attention backward.©r  )rš   r¦   r§   r¨   r+   r,   r-   s   &&&&$*,r   Úsdpa_backward_flopr  v  s   € ô
 $ NÀÓXÐXr'   c                ó$   € V ^8„  d   QhR\         /# r4   rY   )r8   s   "r   r9   r9   ~  s   € ÷ "ñ "ô 	ñ"r'   c
                 ó  € VfZ   VP                   ^8X  dI   V P                  RR4      p VP                  RR4      pVP                  RR4      pVP                  RR4      p\        VVVV VVVV	R7      p\        R V 4       4      # )N©rÓ   rÔ   rÕ   rÈ   rÖ   r×   rØ   rÙ   c              3   ó@   "  € T F  w  rr4\        WAW#4      x € K  	  R # 5ir   r  ©r   r¦   r§   r¨   rš   s   &    r   r    Ú1_flash_attention_backward_flop.<locals>.<genexpr>�  ó&   é € ð áCIÑ?ˆK Kô 	! ¸i×UÐUÛCIùrú   rû   rü   rý   )rÈ   rÓ   rÔ   rÕ   ÚoutÚ	logsumexprÖ   r×   rØ   rÙ   r,   r-   Úshapess   &&&&&&&&&&*, r   Ú_flash_attention_backward_flopr  }  s–   € ð Ò˜UŸZ™Z¨1œ_Ø×%Ñ% b¨"Ó-ˆØ—‘  BÓ'ˆØ�m‰m˜B Ó#ˆØ—‘  BÓ'ˆô 3ØØØØØØØØô	€Fô ñ áCIóó ð r'   c                ó$   € V ^8„  d   QhR\         /# r4   rY   )r8   s   "r   r9   r9   ¤  s   € ÷ ñ ô 	ñr'   c
                 óL   € \        VVVV VVVV	R 7      p\        R V 4       4      # ))rÓ   rÔ   rÕ   rÈ   ré   rê   rë   rì   c              3   ó@   "  € T F  w  rr4\        WAW#4      x € K  	  R # 5ir   r  r  s   &    r   r    Ú5_efficient_attention_backward_flop.<locals>.<genexpr>¾  r  rú   r  )rÈ   rÓ   rÔ   rÕ   r  r  ré   rê   rë   rì   r,   r-   r  s   &&&&&&&&&&*, r   Ú"_efficient_attention_backward_flopr#  £  sB   € ô" 7ØØØØØ!Ø!Ø!Ø!ô	€Fô ñ áCIóó ð r'   c                ó   € V ^8„  d   QhRR/# r@   rA   )r8   s   "r   r9   r9   Ä  s   € ÷  Hñ  H¨ñ  Hr'   c                  ó˜   a€ ^ RI Hp Hp R R lo\        V RR7      RR/R V3R	 lll4       p\        VRR7      RR/R
 V3R lll4       pR# )rD   )Úflex_attentionÚflex_attention_backwardc                óR   € V ^8„  d   QhR\         \        \        3,          R\        /# )r5   r-   r6   )ÚdictÚstrr   Úfloat)r8   s   "r   r9   Ú4_register_flex_attention_flops.<locals>.__annotate__Ê  s&   € ÷ Dñ D¤4¬¬S¨¥>ð D´eñ Dr'   c           
      óª   € V P                  R 4      pVf   R# VP                  R4      pVf   R# \        R\        RVP                  RR4      4      4      # )Ú
_node_metag        Úcustomç      ð?Úsparsity_hint)ÚgetÚmaxÚmin)r-   Ú	node_metar/  s   &  r   Ú_get_sparsity_hintÚ:_register_flex_attention_flops.<locals>._get_sparsity_hintÊ  sN   € Ø—J‘J˜|Ó,ˆ	ØÒÙØ—‘˜xÓ(ˆØŠ>ÙÜ�3œ˜C §¡¨O¸SÓ!AÓBÓCÐCr'   Trò   r)   Nc                ó$   € V ^8„  d   QhR\         /# r4   rY   )r8   s   "r   r9   r,  Ô  s   € ÷ Hñ Hä	ñHr'   c                ó®   <€ \        V P                  VP                  VP                  4      pS! V4      pV^ 8”  d   \        VRV,
          ,          4      # T# )rD   r0  )rµ   r$   rZ   )	rÓ   rÔ   rÕ   r)   r,   r-   ÚflopsÚsparsityr6  s	   &&&$*,  €r   Úflex_attention_forward_flopÚC_register_flex_attention_flops.<locals>.flex_attention_forward_flopÓ  sH   ø€ ô   §¡¨S¯Y©Y¸¿¹ÓDˆÙ% fÓ-ˆØ08¸1´Œs�5˜C (�NÕ+Ó,ÐGÀ%ÐGr'   c                ó$   € V ^8„  d   QhR\         /# r4   rY   )r8   s   "r   r9   r,  Ü  s   € ÷ Hñ Hä	ñHr'   c                óæ   <€ Ve   VP                   MVP                   p	\        W�P                   VP                   VP                   4      p
S! V4      pV^ 8”  d   \        V
RV,
          ,          4      # T
# )Nr0  )r$   r  rZ   )rÓ   rÔ   rÕ   r  r  rÈ   r)   r,   r-   rš   r:  r;  r6  s   &&&&&&$*,   €r   Úflex_attention_backward_flopÚD_register_flex_attention_flops.<locals>.flex_attention_backward_flopÛ  sa   ø€ ð ,4Ò+?˜ŸšÀSÇYÁYˆÜ(ØŸK™K¨¯©°E·K±Kó
ˆñ & fÓ-ˆØ08¸1´Œs�5˜C (�NÕ+Ó,ÐGÀ%ÐGr'   )Ú&torch._higher_order_ops.flex_attentionr&  r'  r   )r&  r'  r<  r@  r6  s       @r   Ú_register_flex_attention_flopsrC  Ä  sh   ø€ ÷õ
Dô ˜>°4Ô8ðHØ*.÷Hñ Hó 9ðHô Ð2¸DÔAðHØDH÷Hñ Hó BòHr'   r)   c                ó$   € V ^8„  d   QhR\         /# r4   rY   )r8   s   "r   r9   r9   ç  s   € ÷ ñ ô 	ñr'   c          
     óV   € \        T TTTVe   TMTVVR7      p
\        R V
 4       4      # )z$Count flops for varlen_attn forward.rõ   c              3   ó@   "  € T F  w  rr4\        WV4      x € K  	  R # 5ir   r¹   r÷   s   &    r   r    Ú,_varlen_attn_forward_flop.<locals>.<genexpr>ý  rù   rú   ©ræ   r   )rÓ   rÔ   rÕ   Úcu_seq_qÚcu_seq_krØ   rÙ   r)   r,   r-   r  s   &&&&&&&$*, r   Ú_varlen_attn_forward_floprK  ç  sF   € ô 2ØØØØØ&Ò2‘(¸ØØô€Eô ñ á6;óó ð r'   c                ó$   € V ^8„  d   QhR\         /# r4   rY   )r8   s   "r   r9   r9     s   € ÷ ñ ô 	ñr'   c          	     ó   € \        WW4WVV4      # )z(Count flops for varlen_attn_out forward.)rK  )r  rÓ   rÔ   rÕ   rI  rJ  rØ   rÙ   r)   r,   r-   s   &&&&&&&&$*,r   Ú_varlen_attn_out_floprN    s   € ô %Ø�E X°eóð r'   c                ó$   € V ^8„  d   QhR\         /# r4   rY   )r8   s   "r   r9   r9     s   € ÷ ñ ô 	ñr'   c
               óL   € \        VVVV VVVV	R7      p\        R V 4       4      # )z%Count flops for varlen_attn backward.r  c              3   ó@   "  € T F  w  rr4\        WAW#4      x € K  	  R # 5ir   r  r  s   &    r   r    Ú-_varlen_attn_backward_flop.<locals>.<genexpr>0  s&   é € ð áCHÑ?ˆK Kô 	! ¸i×UÐUÛCHùrú   rH  )rÈ   rÓ   rÔ   rÕ   r  ÚlserI  rJ  rØ   rÙ   r)   r,   r-   r  s   &&&&&&&&&&$*, r   Ú_varlen_attn_backward_floprT    sB   € ô  2ØØØØØØØØô	€Eô ñ áCHóó ð r'   c                 ó8   € \        V \        4      '       g   V 3# V # r   )r"   rÌ   )Úxs   &r   Únormalize_tuplerW  Q  s   € Ü�aœ×ÒØˆtˆØ€Hr'   c                 ó°   € \        ^ \        \        \        4      ^,
          \        \	        V 4      4      ^,
          ^,          4      4      p\        V,          # )rD   )r3  r4  rÑ   Úsuffixesr*  )ÚnumberÚindexs   & r   Úget_suffix_strr\  Z  s=   € ô �”3”sœ8“} qÕ(¬3¬s°6«{Ó+;¸aÕ+?ÀAÕ*EÓFÓG€EÜ�E�?Ðr'   c                 óx   € \         P                  V4      pV R V,          ,          R pV\         V,          ,           # )iè  z.3f)rY  r[  )rZ  Úsuffixr[  rÕ   s   &&  r   Úconvert_num_with_suffixr_  a  s2   € Ü�N‰N˜6Ó"€Eà˜ �Õ% cÐ*€Eà”8˜E•?Õ"Ð"r'   c                ó$   € V ^8„  d   QhR\         /# r4   )r*  )r8   s   "r   r9   r9   h  s   € ÷  ñ  ¬#ñ  r'   c                 ó(   € V^ 8X  d   R# W,          R # )rD   ú0%z.2%rA   )ÚnumÚdenoms   &&r   Úconvert_to_percent_strre  h  s   € Ø�„zÙØ�k˜#ÐÐr'   c                 ó0   a € \        S 4      V 3R  l4       pV# )c                 ó@   <€ \        V 4      w  rS! V!  p\        W24      # r   )r   r   )r,   Ú	flat_argsÚspecr  r.   s   &   €r   r/   Ú)_pytreeify_preserve_structure.<locals>.nfn  s#   ø€ ä& tÓ,‰ˆ	Ù�‰mˆÜ˜cÓ(Ð(r'   r   r1   s   f r   Ú_pytreeify_preserve_structurerk  m  s    ø€ Ü
ˆ1ƒXô)ó ð)ð
 €Ir'   c                   ó†   a a€ ] tR tRt oRtRV3R lV 3R llltV3R lR ltV3R lR ltRR	 ltR
 t	R t
R tRtVtV ;t# )r   iw  aó  Count theoretical FLOPs for operators that run inside the context.

``FlopCounterMode`` uses ``TorchDispatchMode`` to intercept operations and
apply registered FLOP formulas. Counts are shape-based and formula-defined;
unsupported operations contribute zero FLOPs unless they decompose into
supported operations.

The optional ``mods`` argument is no longer needed for module attribution.
When ``display`` is true, exiting the context prints a table. Use
``get_total_flops()`` or ``get_flop_counts()`` to read the same information
programmatically.

Example usage:

.. code-block:: python

    mod = ...
    inp = ...

    with FlopCounterMode(display=False) as flop_counter:
        mod(inp).sum().backward()

    total = flop_counter.get_total_flops()

c          
      óØ   <€ V ^8„  d   QhRS[ P                  P                  S[S[ P                  P                  ,          ,          R,          RS[RS[RS[S[S[3,          R,          RR/# )r5   ÚmodsNÚdepthÚdisplayÚcustom_mappingr6   )r   ÚnnÚModuler‚   rZ   rƒ   r)  r   )r8   Ú__classdict__s   "€r   r9   ÚFlopCounterMode.__annotate__’  sj   ø€ ÷ +ñ +á—(‘(—/‘/¡D©¯©¯©Õ$9Õ9¸DÕ@ð+ñ ð+ñ ð	+ñ
 !¡¡c �N¨TÕ1ð+ð
 >Bñ+r'   c                óz  <€ \         SV `  4        \        R  4      V n        W n        W0n        RV n        Vf   / pVe   \        P                  ! R^R7       / \        CVP                  4        UUu/ uF&  w  rVT\        VRR4      '       d   TM
\        V4      bK(  	  uppCV n	        \        4       V n        R# u uppi )c                  ó    € \        \        4      # r   )r   rZ   rA   r'   r   Ú<lambda>Ú*FlopCounterMode.__init__.<locals>.<lambda>™  s
   € Ì+ÔVYÔJZr'   Nz<mods argument is not needed anymore, you can stop passing it)Ú
stacklevelÚ_get_rawF)ÚsuperÚ__init__r   Úflop_countsro  rp  ÚmodeÚwarningsÚwarnrL   Úitemsr   r2   r   Úmod_tracker)Úselfrn  ro  rp  rq  rb   ÚvÚ	__class__s   &&&&&  €r   r}  ÚFlopCounterMode.__init__’  s²   ø€ ô 	‰ÑÔÜ6AÑBZÓ6[ˆÔØŒ
ØŒØ-1ˆŒ	ØÒ!ØˆNØÒÜ�MŠMÐXÐefÕgð
Üð
àWe×WkÑWkÔWmÔnÑWmÉtÈqˆq”w˜q *¨e×4Ò4‘!¼-ÈÓ:JÒJÑWmÒnð
ˆÔô )›?ˆÖùó os   Á0,B7c                ó    <€ V ^8„  d   QhRS[ /# r4   rY   )r8   rt  s   "€r   r9   ru  §  s   ø€ ÷ 8ñ 8¡ñ 8r'   c                óV   € \        V P                  R ,          P                  4       4      # )ÚGlobal)r   r~  Úvalues©r„  s   &r   Úget_total_flopsÚFlopCounterMode.get_total_flops§  s!   € Ü�4×#Ñ# HÕ-×4Ñ4Ó6Ó7Ð7r'   c                óL   <€ V ^8„  d   QhRS[ S[S[ S[S[3,          3,          /# r4   )r)  r*  r   rZ   )r8   rt  s   "€r   r9   ru  ª  s)   ø€ ÷ 
Añ 
A¡¡c©4±±S°­>Ð&9Õ!:ñ 
Ar'   c                ó~   € V P                   P                  4        UUu/ uF  w  rV\        V4      bK  	  upp# u uppi )zæReturn the flop counts as a dictionary of dictionaries.

The outer
dictionary is keyed by module name, and the inner dictionary is keyed by
operation name.

Returns:
    Dict[str, Dict[Any, int]]: The flop counts as a dictionary.
)r~  r‚  r)  )r„  rb   r…  s   &  r   Úget_flop_countsÚFlopCounterMode.get_flop_countsª  s7   € ð (,×'7Ñ'7×'=Ñ'=Ô'?Ô@Ñ'?™t˜q�”4˜“7’
Ñ'?Ò@Ð@ùÓ@s   ž9c                ód  a a
aa€ Vf   S P                   pVf   Rp^ R IpRVn        . R	Op. pS P                  4       o
\	        S
4      oRoV
VVV 3R lp\        S P                  P                  4       4       FL  pVR8X  d   K  VP                  R4      ^,           pWq8”  d   K,  V! Wg^,
          4      pVP                  V4       KN  	  RS P                  9   d5   S'       g-   V F  p	RV	^ ,          ,           V	^ &   K  	  V! R^ 4      V,           p\        V4      ^ 8X  d   . R
O.pVP                  WCRR7      # )Ni?B TFc           	      ó¸  <€ \        S
P                  V ,          P                  4       4      pS	VS8¬  ,          o	R V,          p. pVP                  W0,           \	        VS4      \        VS4      .4       S
P                  V ,          P                  4        FD  w  rVVP                  VR,           \        V4      ,           \	        VS4      \        VS4      .4       KF  	  V# )Ú z - )r   r~  r‹  Úappendr_  re  r‚  r*  )Úmod_namero  r´   Úpaddingr‹  rb   r…  Úglobal_flopsÚglobal_suffixÚis_global_subsumedr„  s   &&     €€€€r   Úprocess_modÚ.FlopCounterMode.get_table.<locals>.process_modÆ  sÊ   ø€ ô ˜d×.Ñ.¨xÕ8×?Ñ?ÓAÓBˆKà +°Ñ"=Õ=Ðà˜E•kˆGØˆFØ�M‰MØÕ"Ü'¨°]ÓCÜ& {°LÓAðô ð
 ×(Ñ(¨Õ2×8Ñ8Ö:‘�Ø—‘Ø˜e•O¤c¨!£fÕ,Ü+¨A¨}Ó=Ü*¨1¨lÓ;ðö ñ ;ð ˆMr'   rŠ  Ú.r•  )ÚheadersÚcolalign)rs  ÚFLOPz% Total)rŠ  Ú0rb  )ÚleftÚrightr¤  )ro  ÚtabulateÚPRESERVE_WHITESPACEr�  r\  Úsortedr~  ÚkeysÚcountÚextendrÑ   )r„  ro  r¥  Úheaderr‹  rœ  ÚmodÚ	mod_depthÚ
cur_valuesrÕ   r™  rš  r›  s   f&        @@@r   Ú	get_tableÚFlopCounterMode.get_table¶  s%  û€ ØŠ=Ø—J‘JˆEØŠ=ØˆEó 	à'+ˆÔ$Ú.ˆØˆØ×+Ñ+Ó-ˆÜ& |Ó4ˆØ"Ð÷	ð 	ô, ˜$×*Ñ*×/Ñ/Ó1Ö2ˆCØ�hŒÙØŸ	™	 #›¨Õ*ˆIØÔ Ùá$ S°a­-Ó8ˆJØ�M‰M˜*Ö%ñ 3ð �t×'Ñ'Ô'×0BÛ�Ø  q¥�>��a“ñ  ñ ! ¨1Ó-°Õ6ˆFäˆv‹;˜!ÔÚ+Ð,ˆFà× Ñ  ÐB\Ð Ó]Ð]r'   c                óÂ   € V P                   P                  4        V P                  P                  4        \	        V 4      V n        V P
                  P                  4        V # r   )r~  Úclearrƒ  Ú	__enter__Ú_FlopCounterModer  rŒ  s   &r   r³  ÚFlopCounterMode.__enter__õ  sG   € Ø×Ñ×ÑÔ Ø×Ñ×"Ñ"Ô$Ü$ TÓ*ˆŒ	Ø�	‰	×ÑÔØˆr'   c                ó  € V P                   f   \        R4      hV P                   P                  ! V!  pR V n         V P                  P                  4        V P                  '       d%   \        V P                  V P                  4      4       V# )Nz<Internal error: FlopCounter.__exit__ called but mode is None)r  r^   Ú__exit__rƒ  rp  Úprintr¯  ro  )r„  r,   rn   s   &* r   r·  ÚFlopCounterMode.__exit__ü  sh   € Ø�9‰9ÒÜ Ð!_Ó`Ð`Ø�I‰I×Ò Ñ%ˆØˆŒ	Ø×Ñ×!Ñ!Ô#Ø�<�<ˆ<Ü�$—.‘. §¡Ó,Ô-Øˆr'   c                óü   € WP                   9   dl   V P                   V,          pV! V/ VBR V/B p\        V P                  P                  4       F)  pV P                  V,          V;;,          V,          uu&   K+  	  V# )r)   )rL   Úsetrƒ  Úparentsr~  )r„  Úfunc_packetr  r,   r-   Úflop_count_funcrž   Úpars   &&&&&   r   Ú_count_flopsÚFlopCounterMode._count_flops  sm   € Ø×,Ñ,Ô,Ø"×0Ñ0°Õ=ˆOÙ(¨$ÐF°&ÑFÀ#ÒFˆJÜ˜4×+Ñ+×3Ñ3Ö4�Ø× Ñ  Õ% k×2°jÕ@Õ2ñ 5àˆ
r'   )ro  rp  r~  rL   rƒ  r  )Nr5   TNr   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r}  r�  r‘  r¯  r³  r·  rÀ  Ú__static_attributes__Ú__classdictcell__Ú__classcell__)r†  rt  s   @@r   r   r   w  sE   ù‡ € ñ÷4+õ +÷*8ð 8÷
Að 
Aô<^ò~ò÷ò r'   c                   óL   a € ] tR tRt o RtV 3R lR ltR tR tR
R ltR	t	V t
R# )r´  i  Tc                ó$   <€ V ^8„  d   QhRS[ RR/# )r5   Úcounterr6   N)r   )r8   rt  s   "€r   r9   Ú_FlopCounterMode.__annotate__  s   ø€ ÷ ñ ¡ð °Dñ r'   c                ó   € Wn         R # r   ©rÌ  )r„  rÌ  s   &&r   r}  Ú_FlopCounterMode.__init__  s   € ØŽr'   c                ó  € ^ RI pVP                  V P                  P                  4      pV ;_uu_ 4        V! V!  pRRR4       VP                  V P                  P                  4      pW@P                  n        XV3#   + '       g   i     LI; i)a]  Execute a branch function and capture its FLOP counts without
affecting self.counter.flop_counts

Args:
    branch_fn: The branch function to execute
    operands: Arguments to pass to the branch function

Returns:
    Tuple of (result, flop_counts) where result is the branch output
    and flop_counts is a copy of the FLOP counts after execution
N)ÚcopyrÌ  r~  )r„  Ú	branch_fnÚoperandsrÒ  Úcheckpointed_flop_countsÚresultr~  s   &&&    r   Ú$_execute_with_isolated_flop_countingÚ5_FlopCounterMode._execute_with_isolated_flop_counting  si   € ó 	Ø#'§9¡9¨T¯\©\×-EÑ-EÓ#FÐ ßŠTÙ Ñ)ˆF÷ à—i‘i §¡× 8Ñ 8Ó9ˆØ#;�‰Ô Ø�{Ð"Ð"÷	 �Tús   ´A<Á<B	c                óž  € V\         P                  P                  P                  \         P                  P                  P                  09   pV'       dk   ^ RIHp ^ RIHp V! VR,          4      p\        W‡4      '       g"   \        VR4      '       d   VP                  pK1   V P                  P                  VRW44      # V\         P                  P                  P                  J Edc   Vw  ršr¼V P                  W¬4      w  rÞV\         J d   \         # V P                  W¼4      w  ppV\         J d   \         # \#        VP%                  4       4      \#        VP%                  4       4      ,          p/ pV F�  pVV,          pVV,          p/ p\#        VP%                  4       4      \#        VP%                  4       4      ,          pV F6  pVP'                  V^ 4      pVP'                  V^ 4      p\)        VV4      VV&   K8  	  VVV&   K‘  	  VP+                  4        F2  w  ppV P                  P,                  V,          P/                  V4       K4  	  V# \         # )rD   )Ú
get_kernelr   Ú
kernel_idxÚfnN)r   ÚopsÚhigher_orderÚtriton_kernel_wrapper_mutationÚ triton_kernel_wrapper_functionalÚ*torch._higher_order_ops.triton_kernel_wraprÚ  Útriton.runtime.jitr   r"   ÚhasattrrÜ  rÌ  rÀ  Úcondr×  ÚNotImplementedr»  r¨  r2  r3  r‚  r~  Úupdate)r„  ÚfuncÚtypesr,   r-   Ú	is_tritonrÚ  r   Úkernel_nameÚpredÚtrue_branchÚfalse_branchrÔ  Útrue_outÚtrue_flop_countsÚ	false_outÚfalse_flop_countsÚall_mod_keysÚmerged_flop_countsÚ	outer_keyÚtrue_func_countsÚfalse_func_countsÚmerged_func_countsÚall_func_keysÚfunc_keyÚtrue_valÚ	false_valÚ
inner_dicts   &&&&&                       r   Ú_handle_higher_order_opsÚ)_FlopCounterMode._handle_higher_order_ops(  s  € ØœUŸY™Y×3Ñ3×RÑRÜ"ŸY™Y×3Ñ3×TÑTðVñ Vˆ	çÝMå6Ù$ V¨LÕ%9Ó:ˆKä  ×:Ò:Ü˜;¨×-Ò-Ø"-§.¡.’KàØ—<‘<×,Ñ,¨[¸$ÀÓMÐMØ”U—Y‘Y×+Ñ+×0Ñ0Ô0ð
 9=Ñ5ˆD˜|à)-×)RÑ)RØó*Ñ&ˆHð œ>Ó)Ü%Ð%à+/×+TÑ+TØó,Ñ(ˆIÐ(ð œNÓ*Ü%Ð%ô Ð/×4Ñ4Ó6Ó7¼#Ð>O×>TÑ>TÓ>VÓ:WÕWˆLØ!#ÐÛ)�	Ø#3°IÕ#>Ð Ø$5°iÕ$@Ð!à%'Ð"Ü #Ð$4×$9Ñ$9Ó$;Ó <¼sÐCT×CYÑCYÓC[Ó?\Õ \�ã -�HØ/×3Ñ3°H¸aÓ@�HØ 1× 5Ñ 5°hÀÓ B�IÜ36°xÀÓ3KÐ& xÓ0ñ !.ð
 1CÐ" 9Ó-ñ *ð *<×)AÑ)AÖ)CÑ%�	˜:Ø—‘×(Ñ(¨Õ3×:Ñ:¸:ÖFñ *Dð
 ˆOä!Ð!r'   Nc                ó†  € V'       d   TM/ pV\         P                  P                  P                  P                  \         P                  P                  P
                  P                  \         P                  P                  P
                  P                  \         P                  P                  P                  P                  \         P                  P                  P                  P                  \         P                  P                  P                  P                  \         P                  P                  P                  P                  \         P                  P                  P                  P                  \         P                  P                  P                  P                  \         P                  P                  P                  P                  \         P                  P                  P                  P                  \         P                  P                  P                  P                  \         P                  P                  P                   P                  \         P                  P                  P"                  P                  \         P                  P$                  P&                  P                  09   d   \(        # \+        V\         P,                  P.                  4      '       d   V P1                  WW44      # WP2                  P4                  9  do   V\         P                  P$                  P6                  P                  Jd=   T ;_uu_ 4        VP8                  ! V/ VB pV\(        Jd   VuuR R R 4       #  R R R 4       V! V/ VB pV P2                  P;                  VP<                  WcV4      #   + '       g   i     L?; ir   )r   rÝ  ÚatenÚsym_is_contiguousÚdefaultÚis_contiguousÚmemory_formatÚis_strides_like_formatÚis_non_overlapping_and_denserÄ   Úsym_sizeÚstrideÚ
sym_strideÚstorage_offsetÚsym_storage_offsetÚnumelÚ	sym_numelÚdimÚprimÚlayoutrå  r"   rG   rE   rý  rÌ  rL   rÁ   Ú	decomposerÀ  Ú_overloadpacket)r„  rç  rè  r,   r-   Úrr  s   &&&&&  r   Ú__torch_dispatch__Ú#_FlopCounterMode.__torch_dispatch__e  s;  € ß!‘ rˆð ”E—I‘I—N‘N×4Ñ4×<Ñ<Ü—I‘I—N‘N×0Ñ0×8Ñ8Ü—I‘I—N‘N×0Ñ0×>Ñ>Ü—I‘I—N‘N×9Ñ9×AÑAÜ—I‘I—N‘N×?Ñ?×GÑGÜ—I‘I—N‘N×'Ñ'×/Ñ/Ü—I‘I—N‘N×+Ñ+×3Ñ3Ü—I‘I—N‘N×)Ñ)×1Ñ1Ü—I‘I—N‘N×-Ñ-×5Ñ5Ü—I‘I—N‘N×1Ñ1×9Ñ9Ü—I‘I—N‘N×5Ñ5×=Ñ=Ü—I‘I—N‘N×(Ñ(×0Ñ0Ü—I‘I—N‘N×,Ñ,×4Ñ4Ü—I‘I—N‘N×&Ñ&×.Ñ.Ü—I‘I—N‘N×)Ñ)×1Ñ1ð3ô 3ô  "Ð!ä�dœEŸJ™J×:Ñ:×;Ò;Ø×0Ñ0°¸dÓKÐKð —|‘|×1Ñ1Ô1°dÄ%Ç)Á)Ç.Á.×BWÑBW×B_ÑB_Ó6_ß’Ø—N’N DÐ3¨FÑ3�ØœNÓ*Ø÷ ’à*÷ ñ �DÐ#˜FÑ#ˆØ�|‰|×(Ñ(¨×)=Ñ)=¸sÈ&ÓQÐQ÷ —ús   ÍN0Î0O 	rÏ  )rA   N)rÂ  rÃ  rÄ  rÅ  Úsupports_higher_order_operatorsr}  r×  rý  r  rÇ  rÈ  )rt  s   @r   r´  r´    s,   ø‡ € Ø&*Ð#÷ð ò#ò(;"÷z"Rò "Rr'   r´  c                ób   € V ^8„  d   Qh/ ^ \         9   d   \        \        \        3,          ;R&   # )r5   rL   )Ú__conditional_annotations__r)  r   )r8   s   "r   r9   r9      s+   € ÷ Sñ S÷t #Ò "Œt”Cœ�H�~Ñ "òuSr'   )ÚcudaÚhipÚxpu)F)NNNFN)Ú ÚKÚMÚBÚT)dr  rÆ  rè  r   Úloggingr   Útorch.utils._pytreer   r   r   Úmodule_trackerr   Útypingr   r   Úcollections.abcr	   r
   Útyping_extensionsr   Úcollectionsr   Útorch.utils._python_dispatchr   Úmathr   Ú	functoolsr   r€  Ú__all__r   r   Ú	getLoggerrÂ  Úlogrâ  r   rI   ÚImportErrorÚanyÚwarningrÝ  r   r&   rL   r2   r   Úmmre   Úaddmmrk   Úbmmrq   Úbaddbmmrt   Ú
_scaled_mmr}   r‹   ÚconvolutionÚ_convolutionÚcudnn_convolutionÚ_slow_conv2d_forwardÚconvolution_overrideabler“   Úconvolution_backwardr¡   rµ   Ú'_scaled_dot_product_efficient_attentionÚ#_scaled_dot_product_flash_attentionÚ#_scaled_dot_product_cudnn_attentionrº   rÇ   ræ   rñ   Ú_flash_attention_forwardr  Ú_efficient_attention_forwardr	  r  Ú0_scaled_dot_product_efficient_attention_backwardÚ,_scaled_dot_product_flash_attention_backwardÚ,_scaled_dot_product_cudnn_attention_backwardr  Ú_flash_attention_backwardr  Ú_efficient_attention_backwardr#  rC  rK  rN  rT  rW  rY  r\  r_  re  rk  r   r´  r9   )r  s   @r   Ú<module>rF     s(  øðöSõh Û Û ß FÑ FÝ )ß Ý $Ý $Ý 'Ý #Ý :Ý Ý Û àÐ5Ð
6€áˆTƒ]€Ùˆtƒ_€à×Ò˜Ó!€ðÝ>ð ‡y�y‡~�~€òð
 !#€Ó "ò÷ñ4 �t—w‘wÓð	¨tö 	ó  ð	ñ �t—z‘zÓ"ô%ó #ð%ñ �t—x‘xÓ ôó !ðñ �t—|‘|Ó$ô&ó %ð&ñ �t—‘Ó'ö%ó (ð%÷ $ñL ˜×(Ñ(Ø×)Ñ)Ø×.Ñ.Ø×1Ñ1Ø×5Ñ5ð	7ó 8ð
OÐbfö Oó8ð
Oñ �t×0Ñ0Ó1ôfó 2ðfòPñ8 ˜×DÑDØ×@Ñ@Ø×@Ñ@ðBó Cð@ÀDö @óCð@ò	-ð1`ð
 ÷1`ðh4`ð
 ÷4`ñn �t×4Ñ4¸dÔCð ð ö ó Dð ñF �t×8Ñ8À$ÔGôó Hðò>"ñJ ˜×MÑMØ×IÑIØ×IÑIðKó LðYÐ]aö YóLðYñ �t×5Ñ5¸tÔDô"ó Eð"ñJ �t×9Ñ9À4ÔHôó Iðõ@ HðFð ÷ð8ð ÷ð&ð ÷ð@Ø‡G�GˆWðà‡J�J�
ðð 	‡H�Hˆhðð 	‡L�L�,ð	ð
 	‡O�O�_ðð 	×Ñ�iðð 	×Ñ�yðð 	×Ñ˜Iðð 	×!Ñ! 9ðð 	×Ñ˜yðð 	×ÑÐ1ðð 	×0Ñ0°)ðð 	×,Ñ,¨iðð 	×,Ñ,¨iðð 	×9Ñ9Ð;Mðð  	×5Ñ5Ð7Ið!ð" 	×5Ñ5Ð7Ið#ð$ 	×!Ñ!Ð#@Ø×%Ñ%Ð'HØ×"Ñ"Ð$BØ×&Ñ&Ð(Jñ+€ñ0 Ô  òò $€òò#õ ò
÷Uñ UônyRÐ(ö yRøð ô ß
Ñ
]ÑF\Ó
]‡s‡s‚sÑ
]ÑF\Ó
]×]Ò]Ø�‰ÐVÔWØƒLðús$   ÂP ÐQ.Ð(Q.Ð<Q.ÑQ.Ñ-Q.