Ë
    f^(h¯  ã                   óü   — d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZ dej                  de
ej                     deej                  df   fd	„Zdd
ededefd„Zde
e   fd„Zdej                   j"                  fd„Zy)é    N)Úsymbolic_trace)ÚNode)Úlegalize_graphÚresultÚinputsÚreturn.c                 óØ   — t        | t        j                  j                  «      rdgt	        |«      z  }n|D �cg c]  }|j
                  d   ‘Œ }}t        j                  | |«      S c c}w )a‰  
    A free function for use in the merge_matmul graph transformation below that
    splits the output from a merged matmul into the individual results for each
    input tensor.

    Arguments:
        result: The merged matmul result tensor.
        inputs: The list of inputs that were merged into one for the matmul.

    Returns:
        List of matmul results for each input tensor.
    r   )Ú
isinstanceÚtorchÚfxÚProxyÚlenÚshapeÚsplit)r   r   ÚsplitsÚxs       ú`/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/torch/fx/experimental/merge_matmul.pyÚsplit_result_tensorsr      sW   € ô" �&œ%Ÿ(™(Ÿ.™.Ô)Ø�”s˜6“{Ñ"‰à&,Ö- �!—'‘'˜!“*Ð-ˆÐ-ä�;‰;�v˜vÓ&Ð&ùò .s   ¹A'ÚaÚbÚsearch_depthc                 ó”   — | |k(  ryt        | j                  «      dk(  ry|dk(  ry| j                  D ]  }t        |||dz
  «      sŒ y y)a^  
    Determine if one node depends on another in a torch.fx.Graph.

    Arguments:
        a: The node that may have a dependency on b.
        b: The node that a may have a dependency on.
        search_depth: In the case of an indirect dependency, this function
                        searches upto this many nodes away in search of a
                        data dependency. If none is found, the function
                        makes the conservative assumption that there is a
                        dependency.

    Returns:
        True if a may depend on b, False if it definitely does not.
    Tr   Fé   )r   Úall_input_nodesÚmay_depend_on)r   r   r   Úinps       r   r   r   $   sc   € ð" 	ˆA‚vØô ˆ1×ÑÓ Ò"Øð �qÒØð × Ñ ò ˆÜ˜˜a °Ñ!1Õ2Ùðð ó    Únodesc                 ót   — t        j                  | d«      D ]  \  }}t        ||«      st        ||«      sŒ y y)zØ
    Check if all of the given nodes are pairwise-data independent.

    Arguments:
        nodes: The nodes to check for data dependencies.

    Returns:
        True if any pair in nodes has a data dependency.
    é   FT)Ú	itertoolsÚcombinationsr   )r   ÚiÚjs      r   Úare_nodes_independentr%   I   s?   € ô ×&Ñ& u¨aÓ0ò ‰ˆˆ1Ü˜˜AÔ¤-°°1Õ"5Ùðð r   Úin_modc           	      óÐ  — t        | «      }i }i }|j                  j                  D ]¹  }|j                  dk7  s|j                  t
        j                  urŒ/|j                  \  }}|j                  dk(  r|j                  n|}|j                  dk(  r|j                  n|}|j                  |g «      j                  |«       |j                  |g «      j                  |«       Œ» |j                  «       D �]·  \  }}t        |«      dk  rŒt        |«      sŒ"|D �cg c]  }|j                  d   ‘Œ }	}|	D �
cg c]/  }
t        |
t        «      r|j                  j                  |
«      n|
‘Œ1 }}
t        |t        «      r|j                  j                  |«      n|}|j                  j!                  t
        j"                  |fi «      }|j                  j!                  t
        j                  ||fi «      }|j                  j!                  t$        ||fi «      }t'        t        |«      «      D �cg c]/  }|j                  j!                  t(        j*                  ||fi «      ‘Œ1 }}t-        ||«      D ]1  \  }}|j/                  |«       |j                  j1                  |«       Œ3 t3        |«       �Œº |j5                  «        |j                  j7                  «        |S c c}w c c}
w c c}w )aÚ  
    A graph transformation that merges matrix multiplication operations that share the same right-hand
    side operand into one large matrix multiplication.
               ____      _________        _________
      ----    |    |    |         |     M|  A * C  |
    M| A  |  T| B  | * K|    C    | =    |---------|
      ---- ,  |    |    |         |     T|  B * C  |
       K       ----      ---------        ---------
                K            R                R
    Úcall_functionÚget_attrr    r   )r   Úgraphr   ÚopÚtargetr   ÚmatmulÚargsÚ
setdefaultÚappendÚitemsr   r%   r
   Ústrr)   r(   Úcatr   ÚrangeÚoperatorÚgetitemÚzipÚreplace_all_uses_withÚ
erase_noder   Ú	recompileÚlint)r&   ÚgmÚ	rhs_usersÚ	lhs_usersÚnodeÚlhsÚrhsÚmmsÚmmÚlhs_valsÚlÚmerge_mm_catÚmerge_mmÚmerge_mm_splitÚoutÚmerge_mm_resÚoldÚnews                     r   Úmerge_matmulrM   [   sŽ  € ô 
˜Ó	€Bà(*€IØ(*€Ið —‘—‘ò 3ˆØ�7‰7�oÒ%¨¯©¼E¿L¹LÑ)HØà—9‘9‰ˆˆSð
  ŸF™F jÒ0ˆc�jŠj°cˆØŸF™F jÒ0ˆc�jŠj°cˆà×Ñ˜S "Ó%×,Ñ,¨TÔ2Ø×Ñ˜S "Ó%×,Ñ,¨TÕ2ð3ð —O‘OÓ%ó 1‰ˆˆSäˆs‹8�aŠ<Øô % SÔ)Øà),Ö- 2�B—G‘G˜A“JÐ-ˆÐ-ð KSÖSÀQ¤z°!´SÔ'9ˆr�x‰x× Ñ  Ô#¸qÑ@ÐSˆÐSÜ(2°3¼Ô(<ˆb�h‰h×Ñ Ô$À#ˆð —x‘x×-Ñ-¬e¯i©i¸#¸ÀÓDˆð
 —8‘8×)Ñ)Ü�L‰LàØðð ó
ˆð Ÿ™×/Ñ/Ü  8¨S /°2ó
ˆô
 œS ›X“ö
àð �H‰H×"Ñ"¤8×#3Ñ#3°nÀcÐ5JÈBÕOð
ˆð 
ô ˜C Ó.ò 	%‰HˆC�Ø×%Ñ% cÔ*Ø�H‰H×Ñ Õ$ð	%ô 	�rÖðc1ðf ‡L�L„NØ‡H�H‡M�M„OØ€IùòW .ùò Tùò.
s   ÄKÄ44KÈ)4K#)é   )r!   r5   r   Útorch.fx._symbolic_tracer   Útorch.fx.noder   Útorch.fx.passes.tools_commonr   ÚTensorÚlistÚtupler   Úintr   r%   ÚnnÚModulerM   © r   r   ú<module>rY      s�   ðã Û ã Ý 3Ý Ý 7ð'Ø�L‰Lð'Ø"& u§|¡|Ñ"4ð'à
ˆ5�<‰<˜ÐÑó'ñ2"�Tð "˜dð "°#ó "ðJ  d¡ó ð$V˜Ÿ™Ÿ™ô Vr   