Ë
    ÛÓ^j  ã                  óè   — 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y)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y)Ú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.
    c           	     ó  — |j                  d«      }|€t        d«      ‚t        |t        «      r|j                  }n|}|t
        vr,t        d|› dt        t
        j                  «       «      › �«      ‚t
        |   }|j                  |«      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)ÚclsÚexport_config_dictr   ÚnameÚ
target_clss        úf/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/transformers/exporters/auto.pyr   zAutoExportConfig.from_dict0   s–   € à*×.Ñ.¨Ó?ˆàÐ ÜÐgÓhÐhô �m¤\Ô2Ø ×&Ñ&‰Dà ˆDàÔ1Ñ1ÜØ-¨d¨VÐ3OÔPTÔUo×UtÑUtÓUvÓPwÐOxÐyóð ô 0°Ñ5ˆ
Ø×#Ñ#Ð$6Ó7Ð7ó    N)r    Údict)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úclassmethodr   © r$   r#   r   r   *   s   „ ñð
 ò8ó ñ8r$   r   c                  óF   — e Zd ZdZedd„«       Zedd„«       Zedd„«       Zy)	ÚAutoHfExporterzŽ
    The Auto-HF expoerter class that takes care of automatically instantiating to the correct
    `HfExporter` given the `ExportConfig`.
    c                ó  — t        |t        «      r|j                  «       n|}| j                  |«      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   Úexport_configÚkwargsr    r   r!   s         r#   Úfrom_configzAutoHfExporter.from_configL   s–   € ô 9CÀ=ÔRcÔ8d˜]×2Ñ2Ô4ÐjwÐØ×)Ñ)Ð*<Ô=ÜØ-Ð.@Ð-Cð D)Ü)/Ô0EÓ)FÐ(GÀqðJóð ð
 +¨?Ñ;ˆÜ&0°ÄÔ&Mˆ}×"Ò"ÐS`ˆÜ$ TÑ*Ñ4¨VÑ4Ð4r$   c                ó   — 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_pathr5   s      r#   Úfrom_pretrainedzAutoHfExporter.from_pretrainedZ   s   € ô6 "ð_ó
ð 	
r$   c                óÞ  — | j                  d«      }|€'t        j                  dt        t        «      › d�«       yt        |t        «      r|j                  n|}|t        v }|t        v }|sE|sCt        j                  d|›dt        t        t        «      t        t        «      z  «      › d�«       y|st        j                  d|›d|›d	�«       y|st        j                  d|›d
|›d	�«       yy)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   uB   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Úwarningr2   r3   r   r	   r   r   Úset)r    Ú
export_fmtr!   Ú
has_configÚhas_exporters        r#   r1   z%AutoHfExporter.supports_export_formatz   s  € ð
 (×+Ñ+¨OÓ<ˆ
ØÐÜ�N‰NØTÜÔ/Ó0Ð1°ð>ôð ä#-¨j¼,Ô#Gˆz×ÒÈZˆØÔ7Ð7ˆ
ØÔ4Ð4ˆá¡,Ü�N‰NØ(¨¨Ð6QÜœ#Ô3Ó4´sÔ;UÓ7VÑVÓWÐXÐXcðeôð ÙÜ�N‰NØ   ð )>Ø>B¸XÀ^ðUôð ÙÜ�N‰NØ   ð )9Ø9=¸ÀðPôð Ør$   N)r4   zExportConfigMixin | dictÚreturnr   )rB   zHfExporter | None)r    r%   rB   Úbool)	r&   r'   r(   r)   r*   r6   r:   Ústaticmethodr1   r+   r$   r#   r-   r-   F   sC   „ ñð
 ò5ó ð5ð ò
ó ð
ð> ò"ó ñ"r$   r-   c                ó   ‡ — ˆ fd„}|S )Nc                ó’   •— ‰t         v rt        j                  d‰› d�«       t        | t        «      st        d«      ‚| t         ‰<   | S )Nz
Exporter 'ú0' is already registered and will be overwritten.zExporter must extend HfExporter)r3   r<   r=   Ú
issubclassr   Ú	TypeError©r   r!   s    €r#   Úregister_exporter_fnz/register_exporter.<locals>.register_exporter_fn¡   sH   ø€ ØÔ(Ñ(Ü�N‰N˜Z¨ vÐ-]Ð^Ô_Ü˜#œzÔ*ÜÐ=Ó>Ð>Ø&)Ô˜dÑ#Øˆ
r$   r+   )r!   rK   s   ` r#   Úregister_exporterrL       s   ø€ ôð  Ðr$   c                ó   ‡ — ˆ fd„}|S )Nc                ó’   •— ‰t         v rt        j                  d‰› d�«       t        | t        «      st        d«      ‚| t         ‰<   | S )NzExport config 'rG   z+Export config must extend ExportConfigMixin)r   r<   r=   rH   r   rI   rJ   s    €r#   Úregister_export_config_fnz9register_export_config.<locals>.register_export_config_fn­   sI   ø€ ØÔ-Ñ-Ü�N‰N˜_¨T¨FÐ2bÐcÔdÜ˜#Ô0Ô1ÜÐIÓJÐJØ+.Ô" 4Ñ(Øˆ
r$   r+   )r!   rO   s   ` r#   Úregister_export_configrP   ¬   s   ø€ ôð %Ð$r$   c                ó,   — t         j                  | «      S )N)r-   r6   )r4   s    r#   Úget_hf_exporterrR   ¸   s   € Ü×%Ñ% mÓ4Ð4r$   N)r!   Ústr)rB   r   )r)   Ú
__future__r   Úutilsr   Úbaser   Úconfigsr   r	   Úexporter_dynamor
   r   Úexporter_executorchr   r   Úexporter_onnxr   r   r3   r   Ú
get_loggerr&   r<   r   r-   rL   rP   rR   r+   r$   r#   ú<module>r\      s   ðñ 7å "å Ý ß 4ß 9ß Eß 3ð %ØØñÐ ð #ØØñÐ ð 
ˆ×	Ñ	˜HÓ	%€÷8ñ 8÷8Wñ Wót	 ó	%ô5r$   