Ë
    g^(h‡(  ã                   ó.  — U d dl Z d dlmZmZmZmZ d dlmc mc m	Z
 d dlmZ d dlmZmZmZ g d¢Zd„ Zd„ Zd„ Zd„ Zd	„ Zi ej,                  ej.                  fe“ej,                  ej.                  ej0                  fe“ej2                  ej4                  fe“ej2                  ej4                  ej0                  fe“ej6                  ej8                  fe“ej6                  ej8                  ej0                  fe“ej,                  ej0                  f ee
j:                  «      “ej2                  ej0                  f ee
j<                  «      “ej6                  ej0                  f ee
j>                  «      “ej@                  ej.                  fe“ej@                  ej0                  f ee
jB                  «      “ej4                  ej0                  f ee
jD                  «      “ej8                  ej0                  f ee
jF                  «      “ejH                  ej.                  fe“ejJ                  ej4                  fe“ejL                  ej8                  fe“Z'e(e)eejT                  ef   f   e+d
<   dd„Z,d„ Z-d„ Z.d„ Z/dede(eeejT                  ef   f   fd„Z0y)é    N)ÚAnyÚCallableÚOptionalÚUnion)Úget_combined_dictÚMatchAllNodeÚPattern)Úfuse_conv_bnÚfuse_conv_bn_reluÚfuse_linear_bnÚfuse_convtranspose_bnÚget_fuser_methodÚget_fuser_method_newc                 ó6  — |j                   |j                   k(  sJ d«       ‚t        j                  t        j                  t        j
                  t        j                  t        j                  t        j                  i}| r||j                  |j                  k(  sJ d«       ‚|j                  sJ d«       ‚|j                  sJ d«       ‚|j                  t        |«      d«      }|�	 |||«      S t        d||f› �«      ‚t        j                   j#                  ||«      S )a  Return the fused the conv and bn modules.
    Given the conv and bn modules, fuses them and returns the fused module

    Args:
        is_qat: a flag for whether we are using quantization aware training fusion
        or post training quantization fusion
        conv: Module instance of type conv2d/conv3d
        bn: Spatial BN instance that needs to be fused with the conv

    Examples::

        >>> m1 = nn.Conv2d(10, 20, 3)
        >>> b1 = nn.BatchNorm2d(20)
        >>> # xdoctest: +SKIP
        >>> m2 = fuse_conv_bn(m1, b1)
    ú:Conv and BN both must be in the same mode (train or eval).z?Output channel of Conv2d must match num_features of BatchNorm2dz7Only support fusing BatchNorm2d with affine set to TruezGOnly support fusing BatchNorm2d with tracking_running_stats set to TrueNúCannot fuse train modules: )ÚtrainingÚnnÚConv1dÚnniÚConvBn1dÚConv2dÚConvBn2dÚConv3dÚConvBn3dÚnum_featuresÚout_channelsÚaffineÚtrack_running_statsÚgetÚtypeÚNotImplementedErrorÚutilsÚfuse_conv_bn_eval)Úis_qatÚconvÚbnÚfused_module_class_mapÚfused_module_classs        úi/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/torch/ao/quantization/fuser_method_mappings.pyr
   r
      s  € ð$ 	�‰˜Ÿ™Ò$ðDàCóDØ$ô 	�	‰	”3—<‘<Ü
�	‰	”3—<‘<Ü
�	‰	”3—<‘<ðÐñ à�O‰O˜t×0Ñ0Ò0ð	MàLó	MØ0à�yŠyÐSÐSÓSˆyà×"Ò"ð	UàTó	UØ"à3×7Ñ7¼¸d»ÀdÓKÐØÐ)Ù% d¨BÓ/Ð/ä%Ð(CÀTÈ2ÀJÀ<Ð&PÓQÐQä�x‰x×)Ñ)¨$°Ó3Ð3ó    c                 ó¨  — |j                   |j                   cxk(  r|j                   k(  sJ d«       ‚ J d«       ‚d}| rÚt        j                  t        j                  t        j
                  t        j                  t        j                  t        j                  i}|j                  |j                  k(  sJ d«       ‚|j                  sJ d«       ‚|j                  sJ d«       ‚|j                  t        |«      d«      }|�
 ||||«      S t        d|||f› �«      ‚t        j                  t        j                   t        j
                  t        j"                  t        j                  t        j$                  i}|j                  t        |«      d«      }|�3t        j&                  j(                  j+                  ||«      } |||«      S t        d|||f› �«      ‚)aJ  Return the fused conv and bv modules.

    Given the conv and bn modules, fuses them and returns the fused module

    Args:
        is_qat: a flag for whether we are using quantization aware training fusion
        or post training quantization fusion
        conv: Module instance of type conv2d/conv3d
        bn: Spatial BN instance that needs to be fused with the conv

    Examples::

        >>> m1 = nn.Conv2d(10, 20, 3)
        >>> b1 = nn.BatchNorm2d(20)
        >>> r1 = nn.ReLU(inplace=False)
        >>> # xdoctest: +SKIP
        >>> m2 = fuse_conv_bn_relu(m1, b1, r1)
    r   Nz;Output channel of Conv must match num_features of BatchNormz5Only support fusing BatchNorm with affine set to TruezEOnly support fusing BatchNorm with tracking_running_stats set to Truer   zCannot fuse eval modules: )r   r   r   r   ÚConvBnReLU1dr   ÚConvBnReLU2dr   ÚConvBnReLU3dr   r   r   r   r    r!   r"   Ú
ConvReLU1dÚ
ConvReLU2dÚ
ConvReLU3dr#   Úfusionr$   )r%   r&   r'   ÚreluÚfused_moduleÚmap_to_fused_module_trainÚmap_to_fused_module_evalÚ
fused_convs           r*   r   r   @   s¨  € ð( 	�‰˜Ÿ™Ô5¨¯©Ò5ðDàCóDÙ5ðDàCóDØ5à26€LÙä�I‰I”s×'Ñ'Ü�I‰I”s×'Ñ'Ü�I‰I”s×'Ñ'ð%
Ð!ð �O‰O˜t×0Ñ0Ò0ð	IàHó	IØ0à�yŠyÐQÐQÓQˆyà×"Ò"ð	SàRó	SØ"à0×4Ñ4´T¸$³ZÀÓFˆØÐ#Ù  b¨$Ó/Ð/ä%Ð(CÀTÈ2ÈtÐDTÐCUÐ&VÓWÐWô �I‰I”s—~‘~Ü�I‰I”s—~‘~Ü�I‰I”s—~‘~ð$
Ð ð
 0×3Ñ3´D¸³JÀÓEˆØÐ#ÜŸ™Ÿ™×:Ñ:¸4ÀÓDˆJÙ 
¨DÓ1Ð1ä%Ð(BÀDÈ"ÈdÐCSÐBTÐ&UÓVÐVr+   c                 óR  — |j                   |j                   k(  sJ d«       ‚| r\|j                  |j                  k(  sJ d«       ‚|j                  sJ d«       ‚|j                  sJ d«       ‚t        j                  ||«      S t        j                  j                  j                  ||«      S )a  Return the fused linear and bn modules.
    Given the linear and bn modules, fuses them and returns the fused module

    Args:
        is_qat: a flag for whether we are using quantization aware training fusion
        or post training quantization fusion
        linear: Module instance of type Linear
        bn: BatchNorm1d instance that needs to be fused with the linear layer

    Examples::

        >>> m1 = nn.Linear(20, 10)
        >>> b1 = nn.BatchNorm1d(10)
        >>> # xdoctest: +SKIP
        >>> m2 = fuse_linear_bn(m1, b1)
    z<Linear and BN both must be in the same mode (train or eval).z@Output features of Linear must match num_features of BatchNorm1dz7Only support fusing BatchNorm1d with affine set to TruezGOnly support fusing BatchNorm1d with tracking_running_stats set to True)r   r   Úout_featuresr   r   r   Ú
LinearBn1dr   r#   r3   Úfuse_linear_bn_eval)r%   Úlinearr'   s      r*   r   r   w   s¨   € ð$ 	�‰˜2Ÿ;™;Ò&ðFàEóFØ&ñ à�O‰O˜v×2Ñ2Ò2ð	NàMó	NØ2à�yŠyÐSÐSÓSˆyà×"Ò"ð	UàTó	UØ"ä�~‰~˜f bÓ)Ð)ä�x‰x�‰×2Ñ2°6¸2Ó>Ð>r+   c                 ó´   — |j                   |j                   k(  sJ d«       ‚| rt        d«      ‚t        j                  j                  j                  ||d¬«      S )aÿ  Return the fused ConvTranspose and bn modules.
    Given ConvTranspose and bn modules, fuses them and returns the fused module

    Args:
        convt: Module instance of type ConvTransposeNd
        bn: BatchNormNd instance that needs to be fused with the linear layer.
            batch norm N should match the ConvTranspose N

    Examples::

        >>> m1 = nn.ConvTranspose2d(10, 20, 3)
        >>> b1 = nn.BatchNorm2d(20)
        >>> # xdoctest: +SKIP
        >>> m2 = fuse_convtranspose_bn(m1, b1)
    zCConvTranspose and BN both must be in the same mode (train or eval).z8Fusing ConvTranspose+BatchNorm not yet supported in QAT.T)Ú	transpose)r   Ú	Exceptionr   r#   r3   r$   )r%   Úconvtr'   s      r*   r   r   ™   s]   € ð" 	�‰˜"Ÿ+™+Ò%ðMàLóMØ%ñ ÜØFó
ð 	
ô �x‰x�‰×0Ñ0°¸ÀdÐ0ÓKÐKr+   c                 ó   ‡ — ˆ fd„}|S )a!  Return a sequential wrapped that for is_qat and two modules.
    Given a sequential class for two modules, return a function that takes
    is_qat, and then two modules as argument, that ignores the is_qat flag
    and always returns the sequential that combines the two input modules
    c                 ó   •—  ‰||«      S ©N© )r%   Úm1Úm2Ú
sequentials      €r*   Úfuser_methodz*_sequential_wrapper2.<locals>.fuser_method¼   s   ø€ Ù˜"˜bÓ!Ð!r+   rE   )rH   rI   s   ` r*   Ú_sequential_wrapper2rJ   µ   s   ø€ ô"ð Ðr+   Ú _DEFAULT_OP_LIST_TO_FUSER_METHODc                 ól   — |€i }t        t        |«      }|j                  | d«      }|€J d| › d�«       ‚|S )z¢Get fuser method for the given list of module types.

    Get fuser method for the given list of module types,
    return None if fuser method does not exist
    Núdid not find fuser method for: ú )r   rK   r    )Úop_listÚadditional_fuser_method_mappingÚall_mappingsrI   s       r*   r   r   Ö   sU   € ð 'Ð.Ø*,Ð'Ü$Ü(Ð*Ió€Lð  ×#Ñ# G¨TÓ2€LØÐ#ÐQÐ'FÀwÀiÈqÐ%QÓQÐ#ØÐr+   c                 ó   ‡ — ˆ fd„}|S )Nc                 ó   •—  ‰| ||«      S rD   rE   )r%   ÚxÚyÚfs      €r*   Úreversedz_reverse2.<locals>.reversedç   s   ø€ Ù�˜˜A‹Ðr+   rE   ©rV   rW   s   ` r*   Ú	_reverse2rY   æ   s   ø€ ôð €Or+   c                 ó   ‡ — ˆ fd„}|S )Nc                 ó$   •— |\  }} ‰| |||«      S rD   rE   )r%   rT   ÚwrU   ÚzrV   s        €r*   rW   z_reverse3.<locals>.reversedî   s   ø€ Ø‰ˆˆ1Ù�˜˜A˜qÓ!Ð!r+   rE   rX   s   ` r*   Ú	_reverse3r^   í   s   ø€ ô"ð €Or+   c                 ó¶   — t        | t        t        f«      r5| D �cg c]  }t        |«      ‘Œ }}t        t	        j
                  |Ž «      }|S | t        g}|S c c}w )aQ  Return a list of valid patterns generated from the op_pattern.

    Returns a list of valid patterns generated from the op_pattern,
    since MatchAllNode can match all types of nodes,
    e.g. pattern (torch.nn.Conv2d, torch.add) should also be able to match keys like
    (MatchAllNode, torch.add) and (torch.nn.Conv2d, MatchAllNode)

    Example Input:
    (torch.add, (torch.nn.ReLU, torch.nn.Conv2d))

    Example Output:
    [(torch.add, (torch.nn.ReLU, torch.nn.Conv2d)),
     (torch.add, (torch.nn.ReLU, MatchAllNode)),
     (torch.add, (MatchAllNode, torch.nn.Conv2d)),
     (torch.add, (MatchAllNode, MatchAllNode)),
     (MatchAllNode, (torch.nn.ReLU, torch.nn.Conv2d)),
     (MatchAllNode, (torch.nn.ReLU, MatchAllNode)),
     (MatchAllNode, (MatchAllNode, torch.nn.Conv2d)),
     (MatchAllNode, (MatchAllNode, MatchAllNode)),
    ]
    )Ú
isinstanceÚtupleÚlistÚ_get_valid_patternsÚ	itertoolsÚproductr   )Ú
op_patternÚsub_patternÚ	sub_combsÚresults       r*   rc   rc   õ   s^   € ô. �*œu¤d˜mÔ,ØISÖT¸+Ô(¨Õ5ÐTˆ	ÐTÜ”i×'Ñ'¨Ð3Ó4ˆð €Mð œlÐ+ˆØ€Mùò	 Us   ›Arf   Úfuser_method_mappingc                 ót   — t        | «      }d}|D ]  } |j                  | d«      }|€Œ n |€J d| › d�«       ‚|S )z«Get fuser method.

    This will be made default after we deprecate the get_fuser_method
    Would like to implement this first and have a separate PR for deprecation
    NrM   rN   )rc   r    )rf   rj   Úop_patternsrI   s       r*   r   r     sa   € ô & jÓ1€KØ€LØ!ò ˆ
Ø+×/Ñ/°
¸DÓAˆØÑ#Ùðð Ð#ÐTÐ'FÀzÀlÐRSÐ%TÓTÐ#ØÐr+   rD   )1rd   Útypingr   r   r   r   Útorch.ao.nn.intrinsicÚaor   Ú	intrinsicr   Útorch.nnÚtorch.ao.quantization.utilsr   r   r	   Ú__all__r
   r   r   r   rJ   r   ÚBatchNorm1dÚReLUr   ÚBatchNorm2dr   ÚBatchNorm3dr0   r1   r2   ÚLinearÚ
LinearReLUÚBNReLU2dÚBNReLU3dÚConvTranspose1dÚConvTranspose2dÚConvTranspose3drK   Údictra   Ú
SequentialÚ__annotations__r   rY   r^   rc   r   rE   r+   r*   ú<module>r‚      s¡  ðä ß 1Ó 1ç #Ó #Ý ß PÑ Pò€ò)4òX4Wòn?òDLò8
ðQØ‡Y�Y�—‘Ð ðQà‡Y�Y�—‘ §¡Ð(Ð*;ðQð ‡Y�Y�—‘Ð ðQð ‡Y�Y�—‘ §¡Ð(Ð*;ð	Qð
 ‡Y�Y�—‘Ð ðQð ‡Y�Y�—‘ §¡Ð(Ð*;ðQð ‡Y�Y�—‘ÐÑ.¨s¯~©~Ó>ðQð ‡Y�Y�—‘ÐÑ.¨s¯~©~Ó>ðQð ‡Y�Y�—‘ÐÑ.¨s¯~©~Ó>ðQð ‡Y�Y�—‘Ð ðQð ‡Y�Y�—‘ÐÑ.¨s¯~©~Ó>ðQð ‡^�^�R—W‘WÐÑ3°C·L±LÓAðQð ‡^�^�R—W‘WÐÑ3°C·L±LÓAðQð ×Ñ˜Ÿ™Ð(Ð*?ðQð ×Ñ˜Ÿ™Ð(Ð*?ðQð  ×Ñ˜Ÿ™Ð(Ð*?ð!QÐ   $ u¨e°B·M±MÀ8Ð4KÑ.LÐ'LÑ"Mó ó(ò òòð>Øðà˜w¨¨b¯m©m¸XÐ.EÑ(FÐFÑGôr+   