+
    "Ý³j�6  ã                   ó  € ^ RI t ^ RIHtHt ^ RIHt ^ RIHtHt ^ RI	H
t
HtHt ^ RIHtHtHtHt ^RIHt ^RIHt ^R	IHt ^R
IHt . ROtR R ltR R lt] P4                  P6                  P8                  P:                  ] P4                  P6                  P8                  P<                  ] P4                  P6                  P>                  P:                  ] P4                  P@                  PB                  .t"R R lt#R t$RR R llt%R# )é    N)ÚGraphModuleÚNode)ÚPassManager)Ú_fold_conv_bn_qatÚ_fuse_conv_bn_qat)ÚDuplicateDQPassÚPortNodeMetaForQDQÚ	Quantizer)Ú_disallow_eval_trainÚ_fuse_conv_bn_Ú_fuse_linear_bn_Ú_get_node_name_to_scope)Úconstant_fold)Ú#_convert_to_reference_decomposed_fx)Úprepare)Ú reference_representation_rewritec                ó<   € V ^8„  d   QhR\         R\        R\         /# ©é   ÚmodelÚ	quantizerÚreturn©r   r
   )Úformats   "Úh/home/luca/screen-checking/.venv/lib/python3.14/site-packages/torchao/quantization/pt2e/quantize_pt2e.pyÚ__annotate__r   $   s+   € ÷ gñ gÜðgäðgô ñgó    c                ó‚  € \         P                  P                  R4       V P                  p\	        V 4      p\        V 4       \        V 4       VP                  V 4      p VP                  V 4       VP                  V 4       \        V VRVP                  R7      p V P                  P                  V4       \        V 4      p V P                  P                   Fæ  pVP                   R8X  g   K  VP"                  \         P$                  P&                  P(                  J g   KJ  VP*                  ^ ,          p\-        V\.        4      '       g   Q hVP                   R8X  g   Q h\-        VP"                  \0        4      '       g   Q hV P3                  VP"                  4      p\5        Wa4      p\7        WP"                  V4       Kè  	  V P                  P                   Fæ  pVP                   R8X  g   K  VP"                  \         P$                  P&                  P8                  J g   KJ  VP*                  ^,          p\-        V\.        4      '       g   Q hVP                   R8X  g   Q h\-        VP"                  \0        4      '       g   Q hV P3                  VP"                  4      p	\5        W‘4      p
\7        WP"                  V
4       Kè  	  V # )aò  Prepare a model for post training quantization

Args:
  * `model` (torch.fx.GraphModule): a model captured by `torch.export.export` API.
  * `quantizer`: A backend specific quantizer that conveys how user want the
    model to be quantized. Tutorial for how to write a quantizer can be found here:
    https://pytorch.org/tutorials/prototype/pt2e_quantizer.html

Return:
  A GraphModule with observer (based on quantizer annotation), ready for calibration

Example::

    import torch
    from torchao.quantization.pt2e.quantize_pt2e import prepare_pt2e
    from torchao.quantization.pt2e.quantizer import (
        XNNPACKQuantizer,
        get_symmetric_quantization_config,
    )

    class M(torch.nn.Module):
        def __init__(self) -> None:
            super().__init__()
            self.linear = torch.nn.Linear(5, 10)

       def forward(self, x):
           return self.linear(x)

    # initialize a floating point model
    float_model = M().eval()

    # define calibration function
    def calibrate(model, data_loader):
        model.eval()
        with torch.no_grad():
            for image, target in data_loader:
                model(image)

    # Step 1. program capture
    # NOTE: this API will be updated to torch.export API in the future, but the captured
    # result shoud mostly stay the same
    m = torch.export.export(m, *example_inputs).module()
    # we get a model with aten ops

    # Step 2. quantization
    # backend developer will write their own Quantizer and expose methods to allow
    # users to express how they
    # want the model to be quantized
    quantizer = XNNPACKQuantizer().set_global(get_symmetric_quantization_config())
    m = prepare_pt2e(m, quantizer)

    # run calibration
    # calibrate(m, sample_inference_data)
z&torchao.quantization.pt2e.prepare_pt2eF©Úis_qatÚobs_or_fq_callbackÚcall_functionÚget_attr)ÚtorchÚ_CÚ_log_api_usage_onceÚmetar   r   r   Útransform_for_annotationÚannotateÚvalidater   Úprepare_obs_or_fq_callbackÚupdater   ÚgraphÚnodesÚopÚtargetÚopsÚhigher_orderÚscanÚargsÚ
isinstancer   ÚstrÚget_submoduleÚprepare_pt2eÚsetattrÚ
while_loop)r   r   Úoriginal_graph_metaÚnode_name_to_scopeÚnodeÚscan_combine_fn_nodeÚscan_combine_fnÚprepared_scan_combine_fnÚwhile_loop_body_fn_nodeÚwhile_loop_body_fnÚprepared_while_loop_body_fns   &&         r   r8   r8   $   s0  € ôt 
‡H�H× Ñ Ð!IÔJØŸ*™*ÐÜ0°Ó7Ðô �5ÔÜ�UÔØ×.Ñ.¨uÓ5€EØ×Ñ�uÔØ×Ñ�uÔÜØØØØ$×?Ñ?ô	€Eð 
‡J�J×ÑÐ)Ô*Ü  Ó'€Eð
 —‘×!Ô!ˆØ�7‰7�oÖ%¨$¯+©+¼¿¹×9OÑ9O×9TÑ9TÕ*TØ#'§9¡9¨Q¥<Ð ÜÐ2´D×9Ò9Ð9Ð9Ø'×*Ñ*¨jÔ8Ð8Ð8ÜÐ2×9Ñ9¼3×?Ò?Ð?Ð?Ø#×1Ñ1Ð2F×2MÑ2MÓNˆOÜ'3°OÓ'OÐ$Ü�E×6Ñ6Ð8PÖQñ "ð —‘×!Ô!ˆà�G‰G�Ö&Ø—‘œuŸy™y×5Ñ5×@Ñ@Õ@à&*§i¡i°¥lÐ#ÜÐ5´t×<Ò<Ð<Ð<Ø*×-Ñ-°Ô;Ð;Ð;ÜÐ5×<Ñ<¼c×BÒBÐBÐBØ!&×!4Ñ!4Ð5L×5SÑ5SÓ!TÐÜ*6Ð7IÓ*UÐ'Ü�E×9Ñ9Ð;VÖWñ "ð €Lr   c                ó<   € V ^8„  d   QhR\         R\        R\         /# r   r   )r   s   "r   r   r   Ž   s+   € ÷ Jñ JÜðJäðJô ñJr   c                ól  € \         P                  P                  R4       V P                  p\	        V 4      pVP                  V 4      p VP                  V 4       VP                  V 4       \        V 4       \        V VRVP                  R7      p V P                  P                  V4       \        V 4      p V # )aœ  Prepare a model for quantization aware training

Args:
  * `model` (torch.fx.GraphModule): see :func:`~torchao.quantization.pt2e.quantize_pt2e.prepare_pt2e`
  * `quantizer`: see :func:`~torchao.quantization.pt2e.quantize_pt2e.prepare_pt2e`

Return:
  A GraphModule with fake quant modules (based on quantizer annotation), ready for
  quantization aware training

Example::
    import torch
    from torchao.quantization.pt2e.quantize_pt2e import prepare_qat_pt2e
    from torchao.quantization.pt2e.quantizer import (
        XNNPACKQuantizer,
        get_symmetric_quantization_config,
    )

    class M(torch.nn.Module):
        def __init__(self) -> None:
            super().__init__()
            self.linear = torch.nn.Linear(5, 10)

       def forward(self, x):
           return self.linear(x)

    # initialize a floating point model
    float_model = M().eval()

    # define the training loop for quantization aware training
    def train_loop(model, train_data):
        model.train()
        for image, target in data_loader:
            ...

    # Step 1. program capture
    # NOTE: this API will be updated to torch.export API in the future, but the captured
    # result shoud mostly stay the same
    m = torch.export.export(m, *example_inputs).module()
    # we get a model with aten ops

    # Step 2. quantization
    # backend developer will write their own Quantizer and expose methods to allow
    # users to express how they
    # want the model to be quantized
    quantizer = XNNPACKQuantizer().set_global(get_symmetric_quantization_config())
    m = prepare_qat_pt2e(m, quantizer)

    # run quantization aware training
    train_loop(prepared_model, train_loop)

z*torchao.quantization.pt2e.prepare_qat_pt2eTr   )r$   r%   r&   r'   r   r(   r)   r*   r   r   r+   r,   r   )r   r   r;   r<   s   &&  r   Úprepare_qat_pt2erF   Ž   s£   € ôp 
‡H�H× Ñ Ð!MÔNØŸ*™*ÐÜ0°Ó7ÐØ×.Ñ.¨uÓ5€EØ×Ñ�uÔØ×Ñ�uÔô �eÔÜØØØØ$×?Ñ?ô	€Eð 
‡J�J×ÑÐ)Ô*Ü  Ó'€EØ€Lr   c                ó0   € V ^8„  d   QhR\         R\        /# )r   Únr   )r   Úbool)r   s   "r   r   r   ã   s   € ÷ >ñ >œdð >¤tñ >r   c                óV   € V P                   R8H  ;'       d    V P                  \        9   # )a@  If there is any pure ops between get_attr and quantize op they will be const propagated
e.g. get_attr(weight) -> transpose -> quantize -> dequantize*
(Note: dequantize op is not going to be constant propagated)

This filter is added because we don't want to constant fold the things that are not
related to quantization
r"   )r/   r0   Ú
_QUANT_OPS)rH   s   &r   Ú_quant_node_constraintrL   ã   s$   € ð �4‰4�?Ñ"×=Ð= q§x¡x´:Ñ'=Ð=r   c                 ó¦  € ^ RI Hp ^ RIHp ^ RIHp RpRpV P                  4        Fø  w  rg\        V\        P                  P                  P                  P                  4      '       g}   \        V\        P                  P                  P                  P                  4      '       g?   \        V\        P                  P                  P                  P                  4      '       d   Rp\        Wq4      '       g%   \        Ws4      '       g   \        Wr4      '       g   Kö  RpKú  	  V'       d   V'       d   Q R4       hV'       d   V'       d   Q R4       hV# )r   )ÚFakeQuantize)ÚAffineQuantizedObserverBase)ÚObserverBaseFTz2Cannot be prepared using both torch.ao and torchao)Ú'torchao.quantization.pt2e.fake_quantizerN   Ú"torchao.quantization.pt2e.observerrO   rP   Únamed_modulesr5   r$   ÚaoÚquantizationÚfake_quantizeÚobserver)r   Útorchao_FakeQuantizeÚ#torchao_AffineQuantizedObserverBaseÚtorchao_ObserverBaseÚis_torch_ao_preparedÚis_torchao_preparedÚ_Úms   &       r   Ú1_is_torchao_prepared_do_not_use_outside_this_filer_   î   s  € õõõ Xà ÐØÐØ×#Ñ#Ö%‰ˆä�qœ%Ÿ(™(×/Ñ/×=Ñ=×JÑJ×KÒKÜ˜!œUŸX™X×2Ñ2×;Ñ;×HÑH×IÒIÜ˜!œUŸX™X×2Ñ2×;Ñ;×WÑW×XÒXà#'Ð ä�q×/Ò/Ü˜!×2Ò2Ü˜!×AÔAà"&Òñ &÷ ß&ð 	
Ø@ó	
Ð&÷ ß'ð 	
Ø@ó	
Ð'ð Ðr   c                óH   € V ^8„  d   QhR\         R\        R\        R\         /# )r   r   Úuse_reference_representationÚfold_quantizer   )r   rI   )r   s   "r   r   r     s6   € ÷ Sñ SÜðSä"&ðSô ðSô ñ	Sr   c                ó  € \         P                  P                  R4       \        V\        4      '       g   \        RV R24      hV P                  pV P                  P                   Fé  pVP                  R8X  g   K  VP                  \         P                  P                  P                  J g   KJ  VP                  ^ ,          p\        V\        4      '       g   Q hVP                  R8X  g   Q h\        VP                  \         4      '       g   Q hV P#                  VP                  4      p\%        VVVR7      p\'        WP                  V4       Kë  	  V P                  P                   Fé  pVP                  R8X  g   K  VP                  \         P                  P                  P(                  J g   KJ  VP                  ^,          p\        V\        4      '       g   Q hVP                  R8X  g   Q h\        VP                  \         4      '       g   Q hV P#                  VP                  4      p	\%        V	VVR7      p
\'        WP                  V
4       Kë  	  \+        V 4      p \-        V 4      p \/        \1        4       .4      pV! V 4      P2                  p \/        \5        4       .4      pV! V 4      P2                  p V'       d   \7        V \8        4       V'       d   \;        V 4      p V P                  P=                  V4       \?        V 4      p V # )aŸ  Convert a calibrated/trained model to a quantized model

Args:
  * `model` (torch.fx.GraphModule): calibrated/trained model
  * `use_reference_representation` (bool): boolean flag to indicate whether to produce referece representation or not
  * `fold_quantize` (bool): boolean flag for whether fold the quantize op or not

Returns:
    quantized model, either in q/dq representation or reference representation

Example::

    # prepared_model: the model produced by `prepare_pt2e`/`prepare_qat_pt2e` and calibration/training
    # `convert_pt2e` produces a quantized model that represents quantized computation with
    # quantize dequantize ops and fp32 ops by default.
    # Please refer to
    # https://pytorch.org/tutorials/prototype/pt2e_quant_ptq_static.html#convert-the-calibrated-model-to-a-quantized-model
    # for detailed explanation of output quantized model
    quantized_model = convert_pt2e(prepared_model)

z&torchao.quantization.pt2e.convert_pt2ezjUnexpected argument type for `use_reference_representation`, please make sure you intend to pass argument z to convert_pt2er"   r#   )ra   rb   ) r$   r%   r&   r5   rI   Ú
ValueErrorr'   r-   r.   r/   r0   r1   r2   r3   r4   r   r6   r7   Úconvert_pt2er9   r:   r   r   r   r   Úgraph_moduler	   r   rL   r   r,   r   )r   ra   rb   r;   r=   r>   r?   Úconverted_scan_combine_fnrA   rB   Úconverted_while_loop_body_fnÚpms   &&&         r   re   re     s|  € ô4 
‡H�H× Ñ Ð!IÔJÜÐ2´D×9Ò9Üð<Ø<XÐ;YÐYiðkó
ð 	
ð  Ÿ*™*Ðð —‘×!Ô!ˆØ�7‰7�oÖ%¨$¯+©+¼¿¹×9OÑ9O×9TÑ9TÕ*TØ#'§9¡9¨Q¥<Ð ÜÐ2´D×9Ò9Ð9Ð9Ø'×*Ñ*¨jÔ8Ð8Ð8ÜÐ2×9Ñ9¼3×?Ò?Ð?Ð?Ø#×1Ñ1Ð2F×2MÑ2MÓNˆOÜ(4ØØ-IØ+ô)Ð%ô
 �E×6Ñ6Ð8QÖRñ "ð —‘×!Ô!ˆà�G‰G�Ö&Ø—‘œuŸy™y×5Ñ5×@Ñ@Õ@à&*§i¡i°¥lÐ#ÜÐ5´t×<Ò<Ð<Ð<Ø*×-Ñ-°Ô;Ð;Ð;ÜÐ5×<Ñ<¼c×BÒBÐBÐBØ!&×!4Ñ!4Ð5L×5SÑ5SÓ!TÐÜ+7Ø"Ø-IØ+ô,Ð(ô
 �E×9Ñ9Ð;WÖXñ "ô  0°Ó6€EÜ˜eÓ$€Eä	”oÓ'Ð(Ó	)€BÙˆu‹I×"Ñ"€Eä	Ô(Ó*Ð+Ó	,€BÙˆu‹I×"Ñ"€EçÜ�eÔ3Ô4ç#Ü0°Ó7ˆà	‡J�J×ÑÐ)Ô*Ü  Ó'€EØ€Lr   )r8   rF   re   )FT)&r$   Útorch.fxr   r   Ú"torch.fx.passes.infra.pass_managerr   Ú#torchao.quantization.pt2e.qat_utilsr   r   Ú#torchao.quantization.pt2e.quantizerr   r	   r
   Útorchao.quantization.pt2e.utilsr   r   r   r   r   Úconvertr   r   r   Ú__all__r8   rF   r1   Úquantized_decomposedÚquantize_per_tensorÚdefaultÚtensorÚquantize_per_channelÚtorchaoÚquantize_affinerK   rL   r_   re   © r   r   Ú<module>ry      sÈ   ðó ß &Ý :ç T÷ñ ÷
ó õ )Ý 8Ý Ý Nò€õgõTJð\ 
‡I�I×"Ñ"×6Ñ6×>Ñ>Ø	‡I�I×"Ñ"×6Ñ6×=Ñ=Ø	‡I�I×"Ñ"×7Ñ7×?Ñ?Ø	‡I�I×Ñ×%Ñ%ð	€
õ>ò"÷JSñ Sr   