§
    ‚Štj  ã                  óò   — d Z ddlmZ ddlmZ ddlmZ ddlmZm	Z	 ddl
mZmZ dd	lmZmZ dd
lmZmZ eeedœZeeedœZ ej        e¦  «        Z G d„ d¦  «        Z G d„ d¦  «        Zdd„Zdd„Zdd„ZdS )z0Auto exporter factory for HuggingFace exporters.é    )Úannotationsé   )Úloggingé   )Ú
HfExporter)ÚExportConfigMixinÚExportFormat)ÚDynamoConfigÚDynamoExporter)ÚExecutorchConfigÚExecutorchExporter)Ú
OnnxConfigÚOnnxExporter)Ú
executorchÚdynamoÚonnxc                  ó*   — e Zd ZdZedd„¦   «         ZdS )ÚAutoExportConfigz¦
    The Auto-HF export config class that takes care of automatically dispatching to the correct
    export config given an export config stored in a dictionary.
    Úexport_config_dictÚdictc           	     óT  — |                      d¦  «        }|€t          d¦  «        ‚t          |t          ¦  «        r|j        }n|}|t
          vr9t          d|› dt          t
                               ¦   «         ¦  «        › �¦  «        ‚t
          |         }|                     |¦  «        S )NÚexport_formatzHexport_config_dict must contain key 'export_format' set to exporter namezUnknown exporter type, got z - supported exporters are: )	ÚgetÚ
ValueErrorÚ
isinstancer	   ÚvalueÚAUTO_EXPORT_CONFIG_MAPPINGÚlistÚkeysÚ	from_dict)Úclsr   r   ÚnameÚ
target_clss        úY/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/transformers/exporters/auto.pyr    zAutoExportConfig.from_dict0   sµ   € à*×.Ò.¨Ñ?Ô?ˆàÐ ÝÐgÑhÔhÐhõ �m¥\Ñ2Ô2ð 	!Ø Ô&ˆDˆDà ˆDàÕ1Ð1Ð1ÝØy¨dÐyÐyÕPTÕUo×UtÒUtÑUvÔUvÑPwÔPwÐyÐyñô ð õ 0°Ô5ˆ
Ø×#Ò#Ð$6Ñ7Ô7Ð7ó    N)r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úclassmethodr    © r%   r$   r   r   *   s>   € € € € € ðð ð
 ð8ð 8ð 8ñ „[ð8ð 8ð 8r%   r   c                  óZ   — e Zd ZdZedd„¦   «         Zedd„¦   «         Zedd„¦   «         ZdS )ÚAutoHfExporterzŽ
    The Auto-HF expoerter class that takes care of automatically instantiating to the correct
    `HfExporter` given the `ExportConfig`.
    Úexport_configúExportConfigMixin | dictÚreturnr   c                óB  — t          |t          ¦  «        r|                     ¦   «         n|}|                      |¦  «        s(t	          d|›dt          t          ¦  «        › d�¦  «        ‚|d         }t          |t          ¦  «        r|j        n|}t          |         di |¤ŽS )NzUnsupported export config: z. Registered exporters: ú.r   r+   )	r   r   Úto_dictÚsupports_export_formatr   ÚsortedÚAUTO_EXPORTER_MAPPINGr	   r   )r!   r.   Úkwargsr   r   r"   s         r$   Úfrom_configzAutoHfExporter.from_configL   sË   € õ 9CÀ=ÕRcÑ8dÔ8dÐw˜]×2Ò2Ñ4Ô4Ð4ÐjwÐØ×)Ò)Ð*<Ñ=Ô=ð 	ÝðJÐ.@ð Jð JÝ)/Õ0EÑ)FÔ)FðJð Jð Jñô ð ð
 +¨?Ô;ˆÝ&0°ÅÑ&MÔ&MÐ`ˆ}Ô"Ð"ÐS`ˆÝ$ TÔ*Ð4Ð4¨VÐ4Ð4Ð4r%   úHfExporter | Nonec                ó    — t          d¦  «        ‚)uC  
        Load an exporter instance from a pretrained model/checkpoint that ships an export config.

        **Not implemented yet** â€” placeholder for a first-class "export recipe" workflow.

        The idea: model owners publish an ``export_config.json`` (or an ``export_config`` field in
        ``config.json``) alongside their weights on the Hub. That file captures the settings the
        owner has already validated for their architecture â€” the target format (``dynamo`` /
        ``onnx`` / ``executorch``), exact dynamic-shape specs (e.g. ``text_ids`` dynamic to 4096,
        image tiles fixed at 448, ``batch=1`` for edge deployment), ``strict`` flag, ONNX opset,
        prefill vs. decode layout, ExecuTorch backend choice, and any other knob that today lives
        as tribal knowledge in a README or a private notebook.

        Consumers then get the owner-validated export in one call::

            exporter = AutoHfExporter.from_pretrained("org/model-name")
            program = exporter.export(model, inputs)

        Composes with the [`register_export_input_preparer`] registry: the owner supplies the
        shape spec via ``export_config.json``, transformers supplies the data-dependent
        precomputations (``cu_seqlens``, vision position ids, window indices, â€¦) for that
        architecture. Together they cover the two hard parts of exporting new models â€” knowing
        the right shape contract and preparing the right inputs â€” so downstream users don't
        re-derive either from scratch (and don't break in production when they get it wrong).
        z‡AutoHfExporter.from_pretrained is not implemented yet. Load/export configs explicitly and call AutoHfExporter.from_config(...) instead.)ÚNotImplementedError)r!   Úpretrained_model_name_or_pathr7   s      r$   Úfrom_pretrainedzAutoHfExporter.from_pretrainedZ   s   € õ6 "ð_ñ
ô 
ð 	
r%   r   r   Úboolc                óB  — |                       d¦  «        }|€2t                               dt          t          ¦  «        › d�¦  «         dS t          |t          ¦  «        r|j        n|}|t          v }|t          v }|sY|sWt                               d|›dt          t          t          ¦  «        t          t          ¦  «        z  ¦  «        › d�¦  «         dS |s#t                               d|›d	|›d
�¦  «         dS |s#t                               d|›d|›d
�¦  «         dS dS )a   Return True if the provided dict describes an ``export_format`` that has both a
        registered config class and a registered exporter class. Warns with an actionable message
        when the format is missing entirely, unknown, or only half-registered.r   NuB   No 'export_format' key in export config â€” supported values are: z. Skipping.FzUnknown export format u    â€” supported values are: zExport format z[ has a registered exporter but no config class. Register one via ``@register_export_config(z)``. Skipping.zV has a registered config class but no exporter. Register one via ``@register_exporter(T)
r   ÚloggerÚwarningr5   r6   r   r	   r   r   Úset)r   Ú
export_fmtr"   Ú
has_configÚhas_exporters        r$   r4   z%AutoHfExporter.supports_export_formatz   s¡  € ð
 (×+Ò+¨OÑ<Ô<ˆ
ØÐÝ�NŠNð>ÝÕ/Ñ0Ô0ð>ð >ð >ñô ð ð �5å#-¨j½,Ñ#GÔ#GÐWˆzÔÐÈZˆØÕ7Ð7ˆ
ØÕ4Ð4ˆàð 	 ,ð 	Ý�NŠNðe¨ð eð eÝ�#Õ3Ñ4Ô4µsÕ;UÑ7VÔ7VÑVÑWÔWðeð eð eñô ð ð �5Øð 	Ý�NŠNðU ð Uð UØ>BðUð Uð Uñô ð ð �5Øð 	Ý�NŠNðP ð Pð PØ9=ðPð Pð Pñô ð ð �5Øˆtr%   N)r.   r/   r0   r   )r0   r9   )r   r   r0   r>   )	r&   r'   r(   r)   r*   r8   r=   Ústaticmethodr4   r+   r%   r$   r-   r-   F   s~   € € € € € ðð ð
 ð5ð 5ð 5ñ „[ð5ð ð
ð 
ð 
ñ „[ð
ð> ð"ð "ð "ñ „\ð"ð "ð "r%   r-   r"   Ústrc                ó   ‡ — ˆ fd„}|S )Nc                ó²   •— ‰t           v rt                               d‰› d�¦  «         t          | t          ¦  «        st          d¦  «        ‚| t           ‰<   | S )Nz
Exporter 'ú0' is already registered and will be overwritten.zExporter must extend HfExporter)r6   r@   rA   Ú
issubclassr   Ú	TypeError©r!   r"   s    €r$   Úregister_exporter_fnz/register_exporter.<locals>.register_exporter_fn¡   s^   ø€ ØÕ(Ð(Ð(Ý�NŠNÐ^¨Ð^Ð^Ð^Ñ_Ô_Ð_Ý˜#�zÑ*Ô*ð 	?ÝÐ=Ñ>Ô>Ð>Ø&)Õ˜dÑ#Øˆ
r%   r+   )r"   rN   s   ` r$   Úregister_exporterrO       s$   ø€ ðð ð ð ð ð  Ðr%   c                ó   ‡ — ˆ fd„}|S )Nc                ó²   •— ‰t           v rt                               d‰› d�¦  «         t          | t          ¦  «        st          d¦  «        ‚| t           ‰<   | S )NzExport config 'rJ   z+Export config must extend ExportConfigMixin)r   r@   rA   rK   r   rL   rM   s    €r$   Úregister_export_config_fnz9register_export_config.<locals>.register_export_config_fn­   s`   ø€ ØÕ-Ð-Ð-Ý�NŠNÐc¨TÐcÐcÐcÑdÔdÐdÝ˜#Õ0Ñ1Ô1ð 	KÝÐIÑJÔJÐJØ+.Õ" 4Ñ(Øˆ
r%   r+   )r"   rR   s   ` r$   Úregister_export_configrS   ¬   s$   ø€ ðð ð ð ð ð %Ð$r%   r0   r   c                ó6   — t                                | ¦  «        S )N)r-   r8   )r.   s    r$   Úget_hf_exporterrU   ¸   s   € Ý×%Ò% mÑ4Ô4Ð4r%   N)r"   rG   )r0   r   )r)   Ú
__future__r   Úutilsr   Úbaser   Úconfigsr   r	   Úexporter_dynamor
   r   Úexporter_executorchr   r   Úexporter_onnxr   r   r6   r   Ú
get_loggerr&   r@   r   r-   rO   rS   rU   r+   r%   r$   ú<module>r^      s†  ðð 7Ð 6à "Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ø 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ø EÐ EÐ EÐ EÐ EÐ EÐ EÐ EØ 3Ð 3Ð 3Ð 3Ð 3Ð 3Ð 3Ð 3ð %ØØðð Ð ð #ØØðð Ð ð 
ˆÔ	˜HÑ	%Ô	%€ð8ð 8ð 8ð 8ð 8ñ 8ô 8ð 8ð8Wð Wð Wð Wð Wñ Wô Wð Wðt	 ð 	 ð 	 ð 	 ð	%ð 	%ð 	%ð 	%ð5ð 5ð 5ð 5ð 5ð 5r%   