
    ^j                         d dl Z d dlmZ d dlmZ d dlmZ d dlmZ ddl	m
Z
  e
j                  e      Z G d d	e      Ze G d
 d             Ze G d de             Ze G d de             Ze G d de             Zy)    N)	dataclass)Enum)PathLike)Any   )loggingc                       e Zd ZdZdZdZdZy)ExportFormatz]Identifies the export backend. Stored in [`ExportConfigMixin`] for serialisation round-trips.
executorchdynamoonnxN)__name__
__module____qualname____doc__
EXECUTORCHDYNAMOONNX     i/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/transformers/exporters/configs.pyr
   r
      s    gJFDr   r
   c                   H    e Zd ZU dZeed<   ed        Zdee	e
f   fdZd Zy)ExportConfigMixina  
    Base class for all export configuration dataclasses.

    Provides `to_dict` / `from_dict` serialisation so configs can be saved and round-tripped
    without knowing the concrete subclass. The `export_format` field identifies the subclass
    during deserialisation.
    export_formatc                      | di |}|S )aa  
        Instantiates a [`ExportConfigMixin`] from a Python dictionary of parameters.

        Args:
            config_dict (`dict[str, Any]`):
                Dictionary that will be used to instantiate the configuration object.

        Returns:
            [`ExportConfigMixin`]: The configuration object instantiated from those parameters.
        r   r   )clsconfig_dictconfigs      r   	from_dictzExportConfigMixin.from_dict/   s     #{#r   returnc                 @    t        j                  | j                        S )z
        Serializes this instance to a Python dictionary.

        Returns:
            `dict[str, Any]`: Dictionary of all the attributes that make up this configuration instance.
        )copydeepcopy__dict__selfs    r   to_dictzExportConfigMixin.to_dict>   s     }}T]]++r   c              #   T   K   | j                   j                         E d {    y 7 w)N)r$   itemsr%   s    r   __iter__zExportConfigMixin.__iter__G   s     ==&&(((s   (&(N)r   r   r   r   r
   __annotations__classmethodr   dictstrr   r'   r*   r   r   r   r   r   #   s:       ,c3h ,)r   r   c                   |    e Zd ZU dZej
                  Zeed<   dZe	ed<   dZ
e	ed<   dZeeef   dz  ed<   dZe	ed<   y)	DynamoConfigao  
    Configuration class for exporting models via `torch.export`.

    Args:
        dynamic (`bool`, *optional*, defaults to `False`):
            Whether to export with dynamic (symbolic) shapes. When `True` and
            `dynamic_shapes` is not set, all tensor dimensions are set to
            `Dim.AUTO` automatically.
        strict (`bool`, *optional*, defaults to `False`):
            Whether to enable strict mode in `torch.export`. Runs the full
            symbolic trace and catches more errors, but is slower and more
            likely to fail on complex models.
        dynamic_shapes (`dict[str, Any]`, *optional*):
            Explicit per-input dynamic shape specifications passed to
            `torch.export`. Takes precedence over `dynamic`.
        prefer_deferred_runtime_asserts_over_guards (`bool`, *optional*, defaults to `False`):
            When `True`, data-dependent shape guards are emitted as runtime asserts in the exported
            graph instead of failing the export at trace time when a guard wouldn't hold across the
            full symbolic shape range. Most transformer LLMs need this set to `True` when using
            fine-grained ``Dim(min=, max=)`` bounds. Not needed with ``dynamic=True`` / ``Dim.AUTO``,
            where ``torch.export`` infers shape relations instead of verifying them against the
            user-stated bounds.
    r   FdynamicstrictNdynamic_shapes+prefer_deferred_runtime_asserts_over_guards)r   r   r   r   r
   r   r   r+   r1   boolr2   r3   r-   r.   r   r4   r   r   r   r0   r0   K   sO    0 #/"5"5M<5GTFD,0NDcNT)08=/=r   r0   c                       e Zd ZU dZej
                  Zeed<   dZe	e
z  dz  ed<   dZee	ef   dz  ed<   dZedz  ed<   dZeed<   dZeed	<   dZeed
<   dZeed<   y)
OnnxConfigu>  
    Configuration class for exporting models to ONNX via `torch.onnx.export`.

    Inherits all fields from [`DynamoConfig`] (`dynamic`, `strict`,
    `dynamic_shapes`, `prefer_deferred_runtime_asserts_over_guards`).

    Args:
        output_path (`str` or `PathLike`, *optional*):
            Output path for the `.onnx` file. When `None` (default) the
            exported model is kept in memory as an `ONNXProgram` and not
            written to disk.
        opset_version (`int`, *optional*):
            ONNX opset version to target. Defaults to the latest opset
            supported by the installed `onnxscript` version.
        external_data (`bool`, *optional*, defaults to `True`):
            Store large weight tensors in a separate `.onnx_data` sidecar
            file instead of embedding them in the protobuf. Required for
            models whose weights exceed the 2 GB protobuf limit.
        optimize (`bool`, *optional*, defaults to `True`):
            Run `onnxscript` optimisation passes (constant folding, dead-code
            elimination, …) on the exported graph. Disable for models that
            hit upstream `onnxscript` optimiser bugs.
        export_params (`bool`, *optional*, defaults to `True`):
            Embed model weights in the ONNX graph. Set to `False` to export
            a weight-free graph (weights must be supplied at runtime).
        keep_initializers_as_inputs (`bool`, *optional*, defaults to `False`):
            Expose weight initializers as explicit graph inputs. Required by
            some older ONNX runtimes (opset < 9).
    r   Noutput_pathr3   opset_versionTexternal_dataoptimizeexport_paramsFkeep_initializers_as_inputs)r   r   r   r   r
   r   r   r+   r8   r.   r   r3   r-   r   r9   intr:   r5   r;   r<   r=   r   r   r   r7   r7   m   sz    < #/"3"3M<3)-Kx$&-,0NDcNT)0 $M3:$M4HdM4(--r   r7   c                   B    e Zd ZU dZej
                  Zeed<   dZe	ed<   y)ExecutorchConfigu  
    Configuration class for exporting models to ExecuTorch format.

    Inherits all fields from [`DynamoConfig`] (`dynamic`, `strict`,
    `dynamic_shapes`, `prefer_deferred_runtime_asserts_over_guards`).

    Args:
        backend (`str`, *optional*, defaults to `"xnnpack"`):
            Target ExecuTorch backend. Supported values:

            - `"xnnpack"` — CPU inference via the XNNPACK library (default; runs anywhere).
            - `"cuda"` — GPU inference via the ExecuTorch CUDA backend.
    r   xnnpackbackendN)
r   r   r   r   r
   r   r   r+   rB   r.   r   r   r   r@   r@      s#     #/"9"9M<9GSr   r@   )r"   dataclassesr   enumr   osr   typingr   utilsr   
get_loggerr   loggerr
   r   r0   r7   r@   r   r   r   <module>rJ      s     !     
		H	%4  $) $) $)N >$ > >B '. '. '.T |  r   