import{s as De,o as Ie,n as Pe}from"../chunks/scheduler.5f3e6389.js";import{S as Fe,i as Ee,e as c,s as a,c as h,h as je,a as l,d as o,b as i,f as D,g as f,j as X,k as I,l as x,m as r,n as g,t as _,o as v,p as b}from"../chunks/index.373ab25c.js";import{C as Ae,H as ye}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.8071f002.js";import{D as Q}from"../chunks/Docstring.e14d4aef.js";import{C as Ce}from"../chunks/CodeBlock.c042848a.js";import{E as Xe}from"../chunks/ExampleCodeBlock.14c47b0c.js";function Ue(B){let s,w="Example usage:",m,d,p;return d=new Ce({props:{code:"ZnJvbSUyMG9wdGltdW0uZXhwb3J0ZXJzLm9ubnglMjBpbXBvcnQlMjBtYWluX2V4cG9ydCUwQSUwQW1haW5fZXhwb3J0KCUyMmdwdDIlMjIlMkMlMjBvdXRwdXQlM0QlMjJncHQyX29ubnglMkYlMjIp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> optimum.exporters.onnx <span class="hljs-keyword">import</span> main_export

<span class="hljs-meta">&gt;&gt;&gt; </span>main_export(<span class="hljs-string">&quot;gpt2&quot;</span>, output=<span class="hljs-string">&quot;gpt2_onnx/&quot;</span>)`,wrap:!1}}),{c(){s=c("p"),s.textContent=w,m=a(),h(d.$$.fragment)},l(t){s=l(t,"P",{"data-svelte-h":!0}),X(s)!=="svelte-1ni337v"&&(s.textContent=w),m=i(t),f(d.$$.fragment,t)},m(t,u){r(t,s,u),r(t,m,u),g(d,t,u),p=!0},p:Pe,i(t){p||(_(d.$$.fragment,t),p=!0)},o(t){v(d.$$.fragment,t),p=!1},d(t){t&&(o(s),o(m)),b(d,t)}}}function ze(B){let s,w="Example usage:",m,d,p;return d=new Ce({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvckNhdXNhbExNJTBBJTBBbW9kZWwlMjAlM0QlMjBBdXRvTW9kZWxGb3JDYXVzYWxMTS5mcm9tX3ByZXRyYWluZWQoJTIyZ3B0MiUyMiklMEElMjMlMjBBdCUyMHRoaXMlMjBwb2ludCUyQyUyMHdlJTIwY291bGQlMjBvdmVycmlkZSUyMHNvbWUlMjBzdWJtb2R1bGVzJTJDJTIwZm9yd2FyZCUyMG1ldGhvZHMlMkMlMjB3ZWlnaHRzJTJDJTIwZXRjLiUyMGZyb20lMjB0aGUlMjBtb2RlbC4lMEElMEFvbm54X2V4cG9ydF9mcm9tX21vZGVsKG1vZGVsJTJDJTIwb3V0cHV0JTNEJTIyZ3B0Ml9vbm54JTJGJTIyKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForCausalLM

<span class="hljs-meta">&gt;&gt;&gt; </span>model = AutoModelForCausalLM.from_pretrained(<span class="hljs-string">&quot;gpt2&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># At this point, we could override some submodules, forward methods, weights, etc. from the model.</span>

<span class="hljs-meta">&gt;&gt;&gt; </span>onnx_export_from_model(model, output=<span class="hljs-string">&quot;gpt2_onnx/&quot;</span>)`,wrap:!1}}),{c(){s=c("p"),s.textContent=w,m=a(),h(d.$$.fragment)},l(t){s=l(t,"P",{"data-svelte-h":!0}),X(s)!=="svelte-1ni337v"&&(s.textContent=w),m=i(t),f(d.$$.fragment,t)},m(t,u){r(t,s,u),r(t,m,u),g(d,t,u),p=!0},p:Pe,i(t){p||(_(d.$$.fragment,t),p=!0)},o(t){v(d.$$.fragment,t),p=!1},d(t){t&&(o(s),o(m)),b(d,t)}}}function Le(B){let s,w,m,d,p,t,u,K,F,we=`You can export models to ONNX from PyTorch.
There is an export function for PyTorch models <a href="/docs/optimum/main/en/onnx/package_reference/export#optimum.exporters.onnx.convert.export_pytorch">export_pytorch()</a>,
but the recommended way of using those is via the main export function <code>~optimum.exporters.main_export</code>,
which will take care of using the proper exporting function according to the available framework,
check that the exported model is valid, and provide extended options to run optimizations on the exported model.`,ee,E,oe,N,j,xe,H,Te="Full-suite ONNX export function, exporting <strong>from a model ID on Hugging Face Hub or a local model repository</strong>.",he,P,te,y,A,fe,V,Oe="Full-suite ONNX export function, exporting <strong>from a pre-loaded PyTorch model</strong>. This function is especially useful in case one needs to do modifications on the model, as overriding a forward call, before exporting to ONNX.",ge,C,ne,T,U,_e,W,$e="Exports a Pytorch model to an ONNX Intermediate Representation.",re,O,z,ve,Z,ke="Exports a PyTorch model to an ONNX Intermediate Representation.",se,L,ae,$,R,be,G,Me="Checks that the dummy inputs from the ONNX config is a subset of the allowed inputs for <code>model</code>.",ie,k,J,Ne,S,qe="Validates the export by checking that the outputs from both the reference and the exported model match.",de,Y,ce;return p=new Ae({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),u=new ye({props:{title:"Export functions",local:"export-functions",headingTag:"h1"}}),E=new ye({props:{title:"Main functions",local:"optimum.exporters.onnx.main_export",headingTag:"h2"}}),j=new Q({props:{name:"optimum.exporters.onnx.main_export",anchor:"optimum.exporters.onnx.main_export",parameters:[{name:"model_name_or_path",val:": str"},{name:"output",val:": str | Path"},{name:"task",val:": str = 'auto'"},{name:"opset",val:": int | None = None"},{name:"device",val:": str = 'cpu'"},{name:"dtype",val:": str | None = None"},{name:"optimize",val:": str | None = None"},{name:"monolith",val:": bool = False"},{name:"no_post_process",val:": bool = False"},{name:"framework",val:": str | None = 'pt'"},{name:"atol",val:": float | None = None"},{name:"pad_token_id",val:": int | None = None"},{name:"subfolder",val:": str = ''"},{name:"revision",val:": str = 'main'"},{name:"force_download",val:": bool = False"},{name:"local_files_only",val:": bool = False"},{name:"trust_remote_code",val:": bool = False"},{name:"cache_dir",val:": str = '/home/runner/.cache/huggingface/hub'"},{name:"token",val:": bool | str | None = None"},{name:"do_validation",val:": bool = True"},{name:"model_kwargs",val:": dict[str, Any] | None = None"},{name:"custom_onnx_configs",val:": dict[str, OnnxConfig] | None = None"},{name:"fn_get_submodels",val:": Callable | None = None"},{name:"use_subprocess",val:": bool = False"},{name:"_variant",val:": str = 'default'"},{name:"library_name",val:": str | None = None"},{name:"no_dynamic_axes",val:": bool = False"},{name:"do_constant_folding",val:": bool = True"},{name:"slim",val:": bool = False"},{name:"**kwargs_shapes",val:""}],source:"https://github.com/huggingface/optimum-onnx/blob/main/optimum/exporters/onnx/__main__.py#L57",parameterGroups:[{title:"Required parameters",parametersDescription:[{anchor:"optimum.exporters.onnx.main_export.model_name_or_path",description:`<strong>model_name_or_path</strong> (<code>str</code>) &#x2014;
Model ID on huggingface.co or path on disk to the model repository to export. Example: <code>model_name_or_path=&quot;BAAI/bge-m3&quot;</code> or <code>mode_name_or_path=&quot;/path/to/model_folder</code>.`,name:"model_name_or_path"},{anchor:"optimum.exporters.onnx.main_export.output",description:`<strong>output</strong> (<code>Union[str, Path]</code>) &#x2014;
Path indicating the directory where to store the generated ONNX model.`,name:"output"}]},{title:"Optional parameters",parametersDescription:[{anchor:"optimum.exporters.onnx.main_export.task",description:`<strong>task</strong> (<code>Optional[str]</code>, defaults to <code>None</code>) &#x2014;
The task to export the model for. If not specified, the task will be auto-inferred based on the model. For decoder models,
use <code>xxx-with-past</code> to export the model using past key values in the decoder.`,name:"task"},{anchor:"optimum.exporters.onnx.main_export.opset",description:`<strong>opset</strong> (<code>Optional[int]</code>, defaults to <code>None</code>) &#x2014;
If specified, ONNX opset version to export the model with. Otherwise, the default opset for the given model architecture
will be used.`,name:"opset"},{anchor:"optimum.exporters.onnx.main_export.device",description:`<strong>device</strong> (<code>str</code>, defaults to <code>&quot;cpu&quot;</code>) &#x2014;
The device to use to do the export. Defaults to &#x201C;cpu&#x201D;.`,name:"device"},{anchor:"optimum.exporters.onnx.main_export.dtype",description:`<strong>dtype</strong> (<code>Optional[str]</code>, defaults to <code>None</code>) &#x2014;
The floating point precision to use for the export. Supported options: <code>&quot;fp32&quot;</code> (float32), <code>&quot;fp16&quot;</code> (float16), <code>&quot;bf16&quot;</code> (bfloat16). Defaults to <code>&quot;fp32&quot;</code>.`,name:"dtype"},{anchor:"optimum.exporters.onnx.main_export.optimize",description:`<strong>optimize</strong> (<code>Optional[str]</code>, defaults to <code>None</code>) &#x2014;
Allows to run ONNX Runtime optimizations directly during the export. Some of these optimizations are specific to
ONNX Runtime, and the resulting ONNX will not be usable with other runtime as OpenVINO or TensorRT.
Available options: <code>&quot;O1&quot;, &quot;O2&quot;, &quot;O3&quot;, &quot;O4&quot;</code>. Reference: <a href="/docs/optimum/main/en/onnxruntime/package_reference/configuration#optimum.onnxruntime.AutoOptimizationConfig">AutoOptimizationConfig</a>`,name:"optimize"},{anchor:"optimum.exporters.onnx.main_export.monolith",description:`<strong>monolith</strong> (<code>bool</code>, defaults to <code>False</code>) &#x2014;
Forces to export the model as a single ONNX file.`,name:"monolith"},{anchor:"optimum.exporters.onnx.main_export.no_post_process",description:`<strong>no_post_process</strong> (<code>bool</code>, defaults to <code>False</code>) &#x2014;
Allows to disable any post-processing done by default on the exported ONNX models.`,name:"no_post_process"},{anchor:"optimum.exporters.onnx.main_export.framework",description:`<strong>framework</strong> (<code>Optional[str]</code>, defaults to <code>None</code>) &#x2014;
The framework to use for the ONNX export (<code>&quot;pt&quot;</code>). If not provided, will attempt to automatically detect the framework for the checkpoint.`,name:"framework"},{anchor:"optimum.exporters.onnx.main_export.atol",description:`<strong>atol</strong> (<code>Optional[float]</code>, defaults to <code>None</code>) &#x2014;
If specified, the absolute difference tolerance when validating the model. Otherwise, the default atol for the model will be used.`,name:"atol"},{anchor:"optimum.exporters.onnx.main_export.cache_dir",description:`<strong>cache_dir</strong> (<code>Optional[str]</code>, defaults to <code>None</code>) &#x2014;
Path indicating where to store cache. The default Hugging Face cache path will be used by default.`,name:"cache_dir"},{anchor:"optimum.exporters.onnx.main_export.trust_remote_code",description:`<strong>trust_remote_code</strong> (<code>bool</code>, defaults to <code>False</code>) &#x2014;
Allows to use custom code for the modeling hosted in the model repository. This option should only be set for repositories
you trust and in which you have read the code, as it will execute on your local machine arbitrary code present in the
model repository.`,name:"trust_remote_code"},{anchor:"optimum.exporters.onnx.main_export.pad_token_id",description:`<strong>pad_token_id</strong> (<code>Optional[int]</code>, defaults to <code>None</code>) &#x2014;
This is needed by some models, for some tasks. If not provided, will attempt to use the tokenizer to guess it.`,name:"pad_token_id"},{anchor:"optimum.exporters.onnx.main_export.subfolder",description:`<strong>subfolder</strong> (<code>str</code>, defaults to <code>&quot;&quot;</code>) &#x2014;
In case the relevant files are located inside a subfolder of the model repo either locally or on huggingface.co, you can
specify the folder name here.`,name:"subfolder"},{anchor:"optimum.exporters.onnx.main_export.revision",description:`<strong>revision</strong> (<code>str</code>, defaults to <code>&quot;main&quot;</code>) &#x2014;
Revision is the specific model version to use. It can be a branch name, a tag name, or a commit id.`,name:"revision"},{anchor:"optimum.exporters.onnx.main_export.force_download",description:`<strong>force_download</strong> (<code>bool</code>, defaults to <code>False</code>) &#x2014;
Whether or not to force the (re-)download of the model weights and configuration files, overriding the
cached versions if they exist.`,name:"force_download"},{anchor:"optimum.exporters.onnx.main_export.local_files_only",description:`<strong>local_files_only</strong> (<code>Optional[bool]</code>, defaults to <code>False</code>) &#x2014;
Whether or not to only look at local files (i.e., do not try to download the model).`,name:"local_files_only"},{anchor:"optimum.exporters.onnx.main_export.token",description:`<strong>token</strong> (<code>Optional[Union[bool,str]]</code>, defaults to <code>None</code>) &#x2014;
The token to use as HTTP bearer authorization for remote files. If <code>True</code>, will use the token generated
when running <code>huggingface-cli login</code> (stored in <code>huggingface_hub.constants.HF_TOKEN_PATH</code>).`,name:"token"},{anchor:"optimum.exporters.onnx.main_export.do_validation",description:`<strong>do_validation</strong> (<code>bool</code>, defaults to <code>True</code>) &#x2014;
Whether or not to validate the exported ONNX model by running inference on it.`,name:"do_validation"},{anchor:"optimum.exporters.onnx.main_export.model_kwargs",description:`<strong>model_kwargs</strong> (<code>Optional[Dict[str, Any]]</code>, defaults to <code>None</code>) &#x2014;
Experimental usage: keyword arguments to pass to the model during
the export. This argument should be used along the <code>custom_onnx_configs</code> argument
in case, for example, the model inputs/outputs are changed (for example, if
<code>model_kwargs={&quot;output_attentions&quot;: True}</code> is passed).`,name:"model_kwargs"},{anchor:"optimum.exporters.onnx.main_export.custom_onnx_configs",description:`<strong>custom_onnx_configs</strong> (<code>Optional[Dict[str, OnnxConfig]]</code>, defaults to <code>None</code>) &#x2014;
Experimental usage: override the default ONNX config used for the given model. This argument may be useful for advanced users that desire a finer-grained control on the export. An example is available <a href="https://huggingface.co/docs/optimum/main/en/exporters/onnx/usage_guides/export_a_model" rel="nofollow">here</a>.`,name:"custom_onnx_configs"},{anchor:"optimum.exporters.onnx.main_export.fn_get_submodels",description:`<strong>fn_get_submodels</strong> (<code>Optional[Callable]</code>, defaults to <code>None</code>) &#x2014;
Experimental usage: Override the default submodels that are used at the export. This is
especially useful when exporting a custom architecture that needs to split the ONNX (e.g. encoder-decoder). If unspecified with custom models, optimum will try to use the default submodels used for the given task, with no guarantee of success.`,name:"fn_get_submodels"},{anchor:"optimum.exporters.onnx.main_export.use_subprocess",description:`<strong>use_subprocess</strong> (<code>bool</code>, defaults to <code>False</code>) &#x2014;
Do the ONNX exported model validation in subprocesses. This is especially useful when
exporting on CUDA device, where ORT does not release memory at inference session
destruction. When set to <code>True</code>, the <code>main_export</code> call should be guarded in
<code>if __name__ == &quot;__main__&quot;:</code> block.`,name:"use_subprocess"},{anchor:"optimum.exporters.onnx.main_export._variant",description:`<strong>_variant</strong> (<code>str</code>, defaults to <code>default</code>) &#x2014;
Specify the variant of the ONNX export to use.`,name:"_variant"},{anchor:"optimum.exporters.onnx.main_export.library_name",description:`<strong>library_name</strong> (<code>Optional[str]</code>, defaults to <code>None</code>) &#x2014;
The library of the model (<code>&quot;transformers&quot;</code> or <code>&quot;diffusers&quot;</code> or <code>&quot;timm&quot;</code> or <code>&quot;sentence_transformers&quot;</code>). If not provided, will attempt to automatically detect the library name for the checkpoint.`,name:"library_name"},{anchor:"optimum.exporters.onnx.main_export.no_dynamic_axes",description:`<strong>no_dynamic_axes</strong> (bool, defaults to <code>False</code>) &#x2014;
If True, disables the use of dynamic axes during ONNX export.`,name:"no_dynamic_axes"},{anchor:"optimum.exporters.onnx.main_export.do_constant_folding",description:`<strong>do_constant_folding</strong> (bool, defaults to <code>True</code>) &#x2014;
PyTorch-specific argument. If <code>True</code>, the PyTorch ONNX export will fold constants into adjacent nodes, if possible.`,name:"do_constant_folding"},{anchor:"optimum.exporters.onnx.main_export.slim",description:`<strong>slim</strong> (bool, defaults to <code>False</code>) &#x2014;
PyTorch-specific argument. If <code>True</code>, use onnxslim to optimize the ONNX model.`,name:"slim"},{anchor:"optimum.exporters.onnx.main_export.*kwargs_shapes",description:`*<strong>*kwargs_shapes</strong> (<code>Dict</code>) &#x2014;
Shapes to use during inference. This argument allows to override the default shapes used during the ONNX export.`,name:"*kwargs_shapes"}]}]}}),P=new Xe({props:{anchor:"optimum.exporters.onnx.main_export.example",$$slots:{default:[Ue]},$$scope:{ctx:B}}}),A=new Q({props:{name:"optimum.exporters.onnx.onnx_export_from_model",anchor:"optimum.exporters.onnx.onnx_export_from_model",parameters:[{name:"model",val:": PreTrainedModel | DiffusionPipeline"},{name:"output",val:": str | Path"},{name:"opset",val:": int | None = None"},{name:"optimize",val:": str | None = None"},{name:"monolith",val:": bool = False"},{name:"no_post_process",val:": bool = False"},{name:"atol",val:": float | None = None"},{name:"do_validation",val:": bool = True"},{name:"model_kwargs",val:": dict[str, Any] | None = None"},{name:"custom_onnx_configs",val:": dict[str, OnnxConfig] | None = None"},{name:"fn_get_submodels",val:": Callable | None = None"},{name:"_variant",val:": str = 'default'"},{name:"preprocessors",val:": list | None = None"},{name:"device",val:": str = 'cpu'"},{name:"no_dynamic_axes",val:": bool = False"},{name:"task",val:": str | None = None"},{name:"use_subprocess",val:": bool = False"},{name:"do_constant_folding",val:": bool = True"},{name:"slim",val:": bool = False"},{name:"**kwargs_shapes",val:""}],source:"https://github.com/huggingface/optimum-onnx/blob/main/optimum/exporters/onnx/convert.py#L809",parameterGroups:[{title:"Required parameters",parametersDescription:[{anchor:"optimum.exporters.onnx.onnx_export_from_model.model",description:`<strong>model</strong> (<code>Union[&quot;PreTrainedModel&quot;, &quot;DiffusionPipeline&quot;]</code>) &#x2014;
PyTorch model to export to ONNX.`,name:"model"},{anchor:"optimum.exporters.onnx.onnx_export_from_model.output",description:`<strong>output</strong> (<code>Union[str, Path]</code>) &#x2014;
Path indicating the directory where to store the generated ONNX model.`,name:"output"}]},{title:"Optional parameters",parametersDescription:[{anchor:"optimum.exporters.onnx.onnx_export_from_model.task",description:`<strong>task</strong> (<code>Optional[str]</code>, defaults to <code>None</code>) &#x2014;
The task to export the model for. If not specified, the task will be auto-inferred based on the model.`,name:"task"},{anchor:"optimum.exporters.onnx.onnx_export_from_model.opset",description:`<strong>opset</strong> (<code>Optional[int]</code>, defaults to <code>None</code>) &#x2014;
If specified, ONNX opset version to export the model with. Otherwise, the default opset for the given model architecture
will be used.`,name:"opset"},{anchor:"optimum.exporters.onnx.onnx_export_from_model.device",description:`<strong>device</strong> (<code>str</code>, defaults to <code>&quot;cpu&quot;</code>) &#x2014;
The device to use to do the export. Defaults to &#x201C;cpu&#x201D;.`,name:"device"},{anchor:"optimum.exporters.onnx.onnx_export_from_model.optimize",description:`<strong>optimize</strong> (<code>Optional[str]</code>, defaults to <code>None</code>) &#x2014;
Allows to run ONNX Runtime optimizations directly during the export. Some of these optimizations are specific to
ONNX Runtime, and the resulting ONNX will not be usable with other runtime as OpenVINO or TensorRT.
Available options: <code>&quot;O1&quot;, &quot;O2&quot;, &quot;O3&quot;, &quot;O4&quot;</code>. Reference: <a href="/docs/optimum/main/en/onnxruntime/package_reference/configuration#optimum.onnxruntime.AutoOptimizationConfig">AutoOptimizationConfig</a>`,name:"optimize"},{anchor:"optimum.exporters.onnx.onnx_export_from_model.monolith",description:`<strong>monolith</strong> (<code>bool</code>, defaults to <code>False</code>) &#x2014;
Forces to export the model as a single ONNX file.`,name:"monolith"},{anchor:"optimum.exporters.onnx.onnx_export_from_model.no_post_process",description:`<strong>no_post_process</strong> (<code>bool</code>, defaults to <code>False</code>) &#x2014;
Allows to disable any post-processing done by default on the exported ONNX models.`,name:"no_post_process"},{anchor:"optimum.exporters.onnx.onnx_export_from_model.atol",description:`<strong>atol</strong> (<code>Optional[float]</code>, defaults to <code>None</code>) &#x2014;
If specified, the absolute difference tolerance when validating the model. Otherwise, the default atol for the model will be used.`,name:"atol"},{anchor:"optimum.exporters.onnx.onnx_export_from_model.do_validation",description:`<strong>do_validation</strong> (<code>bool</code>, defaults to <code>True</code>) &#x2014;
If <code>True</code>, the exported ONNX model will be validated against the original PyTorch model.`,name:"do_validation"},{anchor:"optimum.exporters.onnx.onnx_export_from_model.model_kwargs",description:`<strong>model_kwargs</strong> (<code>Optional[Dict[str, Any]]</code>, defaults to <code>None</code>) &#x2014;
Experimental usage: keyword arguments to pass to the model during
the export. This argument should be used along the <code>custom_onnx_configs</code> argument
in case, for example, the model inputs/outputs are changed (for example, if
<code>model_kwargs={&quot;output_attentions&quot;: True}</code> is passed).`,name:"model_kwargs"},{anchor:"optimum.exporters.onnx.onnx_export_from_model.custom_onnx_configs",description:`<strong>custom_onnx_configs</strong> (<code>Optional[Dict[str, OnnxConfig]]</code>, defaults to <code>None</code>) &#x2014;
Experimental usage: override the default ONNX config used for the given model. This argument may be useful for advanced users that desire a finer-grained control on the export. An example is available <a href="https://huggingface.co/docs/optimum/main/en/exporters/onnx/usage_guides/export_a_model" rel="nofollow">here</a>.`,name:"custom_onnx_configs"},{anchor:"optimum.exporters.onnx.onnx_export_from_model.fn_get_submodels",description:`<strong>fn_get_submodels</strong> (<code>Optional[Callable]</code>, defaults to <code>None</code>) &#x2014;
Experimental usage: Override the default submodels that are used at the export. This is
especially useful when exporting a custom architecture that needs to split the ONNX (e.g. encoder-decoder). If unspecified with custom models, optimum will try to use the default submodels used for the given task, with no guarantee of success.`,name:"fn_get_submodels"},{anchor:"optimum.exporters.onnx.onnx_export_from_model.use_subprocess",description:`<strong>use_subprocess</strong> (<code>bool</code>, defaults to <code>False</code>) &#x2014;
Do the ONNX exported model validation in subprocesses. This is especially useful when
exporting on CUDA device, where ORT does not release memory at inference session
destruction. When set to <code>True</code>, the <code>main_export</code> call should be guarded in
<code>if __name__ == &quot;__main__&quot;:</code> block.`,name:"use_subprocess"},{anchor:"optimum.exporters.onnx.onnx_export_from_model._variant",description:`<strong>_variant</strong> (<code>str</code>, defaults to <code>default</code>) &#x2014;
Specify the variant of the ONNX export to use.`,name:"_variant"},{anchor:"optimum.exporters.onnx.onnx_export_from_model.preprocessors",description:`<strong>preprocessors</strong> (<code>Optional[List]</code>, defaults to <code>None</code>) &#x2014;
List of preprocessors to use for the ONNX export.`,name:"preprocessors"},{anchor:"optimum.exporters.onnx.onnx_export_from_model.no_dynamic_axes",description:`<strong>no_dynamic_axes</strong> (bool, defaults to <code>False</code>) &#x2014;
If True, disables the use of dynamic axes during ONNX export.`,name:"no_dynamic_axes"},{anchor:"optimum.exporters.onnx.onnx_export_from_model.do_constant_folding",description:`<strong>do_constant_folding</strong> (bool, defaults to <code>True</code>) &#x2014;
PyTorch-specific argument. If <code>True</code>, the PyTorch ONNX export will fold constants into adjacent nodes, if possible.`,name:"do_constant_folding"},{anchor:"optimum.exporters.onnx.onnx_export_from_model.slim",description:`<strong>slim</strong> (bool, defaults to <code>False</code>) &#x2014;
Use onnxslim to optimize the ONNX model.`,name:"slim"},{anchor:"optimum.exporters.onnx.onnx_export_from_model.*kwargs_shapes",description:`*<strong>*kwargs_shapes</strong> (<code>Dict</code>) &#x2014;
Shapes to use during inference. This argument allows to override the default shapes used during the ONNX export.`,name:"*kwargs_shapes"}]}]}}),C=new Xe({props:{anchor:"optimum.exporters.onnx.onnx_export_from_model.example",$$slots:{default:[ze]},$$scope:{ctx:B}}}),U=new Q({props:{name:"optimum.exporters.onnx.export",anchor:"optimum.exporters.onnx.export",parameters:[{name:"model",val:": PreTrainedModel | ModelMixin"},{name:"config",val:": OnnxConfig"},{name:"output",val:": Path"},{name:"opset",val:": int | None = None"},{name:"device",val:": str = 'cpu'"},{name:"input_shapes",val:": dict | None = None"},{name:"disable_dynamic_axes_fix",val:": bool | None = False"},{name:"dtype",val:": str | None = None"},{name:"no_dynamic_axes",val:": bool = False"},{name:"do_constant_folding",val:": bool = True"},{name:"model_kwargs",val:": dict[str, Any] | None = None"}],parametersDescription:[{anchor:"optimum.exporters.onnx.export.model",description:`<strong>model</strong> (<code>PreTrainedModel</code> or <code>ModelMixin</code>) &#x2014;
The model to export.`,name:"model"},{anchor:"optimum.exporters.onnx.export.config",description:`<strong>config</strong> (<a href="/docs/optimum/main/en/onnx/package_reference/configuration#optimum.exporters.onnx.OnnxConfig">OnnxConfig</a>) &#x2014;
The ONNX configuration associated with the exported model.`,name:"config"},{anchor:"optimum.exporters.onnx.export.output",description:`<strong>output</strong> (<code>Path</code>) &#x2014;
Directory to store the exported ONNX model.`,name:"output"},{anchor:"optimum.exporters.onnx.export.opset",description:`<strong>opset</strong> (<code>Optional[int]</code>, defaults to <code>None</code>) &#x2014;
The version of the ONNX operator set to use.`,name:"opset"},{anchor:"optimum.exporters.onnx.export.device",description:`<strong>device</strong> (<code>Optional[str]</code>, defaults to <code>&quot;cpu&quot;</code>) &#x2014;
The device on which the ONNX model will be exported. Either <code>cpu</code> or <code>cuda</code>. Only PyTorch is supported for
export on CUDA devices.`,name:"device"},{anchor:"optimum.exporters.onnx.export.input_shapes",description:`<strong>input_shapes</strong> (<code>Optional[Dict]</code>, defaults to <code>None</code>) &#x2014;
If specified, allows to use specific shapes for the example input provided to the ONNX exporter.`,name:"input_shapes"},{anchor:"optimum.exporters.onnx.export.disable_dynamic_axes_fix",description:`<strong>disable_dynamic_axes_fix</strong> (<code>Optional[bool]</code>, defaults to <code>False</code>) &#x2014;
Whether to disable the default dynamic axes fixing.`,name:"disable_dynamic_axes_fix"},{anchor:"optimum.exporters.onnx.export.dtype",description:`<strong>dtype</strong> (<code>Optional[str]</code>, defaults to <code>None</code>) &#x2014;
Data type to remap the model inputs to. PyTorch-only. Only <code>fp16</code> is supported.`,name:"dtype"},{anchor:"optimum.exporters.onnx.export.no_dynamic_axes",description:`<strong>no_dynamic_axes</strong> (bool, defaults to <code>False</code>) &#x2014;
If True, disables the use of dynamic axes during ONNX export.`,name:"no_dynamic_axes"},{anchor:"optimum.exporters.onnx.export.do_constant_folding",description:`<strong>do_constant_folding</strong> (bool, defaults to <code>True</code>) &#x2014;
PyTorch-specific argument. If <code>True</code>, the PyTorch ONNX export will fold constants into adjacent nodes, if possible.`,name:"do_constant_folding"},{anchor:"optimum.exporters.onnx.export.model_kwargs",description:`<strong>model_kwargs</strong> (<code>Optional[Dict[str, Any]]</code>, defaults to <code>None</code>) &#x2014;
Experimental usage: keyword arguments to pass to the model during
the export. This argument should be used along the <code>custom_onnx_config</code> argument
in case, for example, the model inputs/outputs are changed (for example, if
<code>model_kwargs={&quot;output_attentions&quot;: True}</code> is passed).`,name:"model_kwargs"}],source:"https://github.com/huggingface/optimum-onnx/blob/main/optimum/exporters/onnx/convert.py#L706",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<p>A tuple with an ordered list of the model’s inputs, and the named outputs from
the ONNX configuration.</p>
`,returnType:`<script context="module">export const metadata = 'undefined';<\/script>


<p><code>Tuple[List[str], List[str]]</code></p>
`}}),z=new Q({props:{name:"optimum.exporters.onnx.convert.export_pytorch",anchor:"optimum.exporters.onnx.convert.export_pytorch",parameters:[{name:"model",val:": PreTrainedModel | ModelMixin"},{name:"config",val:": OnnxConfig"},{name:"opset",val:": int"},{name:"output",val:": Path"},{name:"device",val:": str = 'cpu'"},{name:"input_shapes",val:": dict | None = None"},{name:"no_dynamic_axes",val:": bool = False"},{name:"do_constant_folding",val:": bool = True"},{name:"model_kwargs",val:": dict[str, Any] | None = None"}],parametersDescription:[{anchor:"optimum.exporters.onnx.convert.export_pytorch.model",description:`<strong>model</strong> (<code>PreTrainedModel</code>) &#x2014;
The model to export.`,name:"model"},{anchor:"optimum.exporters.onnx.convert.export_pytorch.config",description:`<strong>config</strong> (<a href="/docs/optimum/main/en/onnx/package_reference/configuration#optimum.exporters.onnx.OnnxConfig">OnnxConfig</a>) &#x2014;
The ONNX configuration associated with the exported model.`,name:"config"},{anchor:"optimum.exporters.onnx.convert.export_pytorch.opset",description:`<strong>opset</strong> (<code>int</code>) &#x2014;
The version of the ONNX operator set to use.`,name:"opset"},{anchor:"optimum.exporters.onnx.convert.export_pytorch.output",description:`<strong>output</strong> (<code>Path</code>) &#x2014;
Path to save the exported ONNX file to.`,name:"output"},{anchor:"optimum.exporters.onnx.convert.export_pytorch.device",description:`<strong>device</strong> (<code>str</code>, defaults to <code>&quot;cpu&quot;</code>) &#x2014;
The device on which the ONNX model will be exported. Either <code>cpu</code> or <code>cuda</code>. Only PyTorch is supported for
export on CUDA devices.`,name:"device"},{anchor:"optimum.exporters.onnx.convert.export_pytorch.input_shapes",description:`<strong>input_shapes</strong> (<code>Optional[Dict]</code>, defaults to <code>None</code>) &#x2014;
If specified, allows to use specific shapes for the example input provided to the ONNX exporter.`,name:"input_shapes"},{anchor:"optimum.exporters.onnx.convert.export_pytorch.no_dynamic_axes",description:`<strong>no_dynamic_axes</strong> (bool, defaults to <code>False</code>) &#x2014;
If True, disables the use of dynamic axes during ONNX export.`,name:"no_dynamic_axes"},{anchor:"optimum.exporters.onnx.convert.export_pytorch.do_constant_folding",description:`<strong>do_constant_folding</strong> (bool, defaults to <code>True</code>) &#x2014;
PyTorch-specific argument. If <code>True</code>, the PyTorch ONNX export will fold constants into adjacent nodes, if possible.`,name:"do_constant_folding"},{anchor:"optimum.exporters.onnx.convert.export_pytorch.model_kwargs",description:`<strong>model_kwargs</strong> (<code>Optional[Dict[str, Any]]</code>, defaults to <code>None</code>) &#x2014;
Experimental usage: keyword arguments to pass to the model during
the export. This argument should be used along the <code>custom_onnx_config</code> argument
in case, for example, the model inputs/outputs are changed (for example, if
<code>model_kwargs={&quot;output_attentions&quot;: True}</code> is passed).`,name:"model_kwargs"}],source:"https://github.com/huggingface/optimum-onnx/blob/main/optimum/exporters/onnx/convert.py#L463",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<p>A tuple with an ordered list of the model’s inputs, and the named outputs from
the ONNX configuration.</p>
`,returnType:`<script context="module">export const metadata = 'undefined';<\/script>


<p><code>Tuple[List[str], List[str]]</code></p>
`}}),L=new ye({props:{title:"Utility functions",local:"optimum.exporters.utils.check_dummy_inputs_are_allowed",headingTag:"h2"}}),R=new Q({props:{name:"optimum.exporters.utils.check_dummy_inputs_are_allowed",anchor:"optimum.exporters.utils.check_dummy_inputs_are_allowed",parameters:[{name:"model",val:": typing.Union[ForwardRef('PreTrainedModel'), ForwardRef('ModelMixin')]"},{name:"dummy_input_names",val:": typing.Iterable[str]"}],parametersDescription:[{anchor:"optimum.exporters.utils.check_dummy_inputs_are_allowed.model",description:`<strong>model</strong> (<code>PreTrainedModel</code> or <code>ModelMixin</code>) &#x2014;
The model instance.`,name:"model"},{anchor:"optimum.exporters.utils.check_dummy_inputs_are_allowed.model_inputs",description:`<strong>model_inputs</strong> (<code>Iterable[str]</code>) &#x2014;
The model input names.`,name:"model_inputs"}],source:"https://github.com/huggingface/optimum-onnx/blob/main/optimum/exporters/utils.py#L621"}}),J=new Q({props:{name:"optimum.exporters.onnx.validate_model_outputs",anchor:"optimum.exporters.onnx.validate_model_outputs",parameters:[{name:"config",val:": OnnxConfig"},{name:"reference_model",val:": PreTrainedModel | ModelMixin"},{name:"onnx_model",val:": Path"},{name:"onnx_named_outputs",val:": list[str]"},{name:"atol",val:": float | None = None"},{name:"input_shapes",val:": dict | None = None"},{name:"device",val:": str = 'cpu'"},{name:"use_subprocess",val:": bool | None = True"},{name:"model_kwargs",val:": dict[str, Any] | None = None"}],parametersDescription:[{anchor:"optimum.exporters.onnx.validate_model_outputs.config",description:`<strong>config</strong> (<code>~OnnxConfig</code>) &#x2014;
The configuration used to export the model.`,name:"config"},{anchor:"optimum.exporters.onnx.validate_model_outputs.reference_model",description:`<strong>reference_model</strong> (<code>Union[&quot;PreTrainedModel&quot;, &quot;ModelMixin&quot;]</code>) &#x2014;
The model used for the export.`,name:"reference_model"},{anchor:"optimum.exporters.onnx.validate_model_outputs.onnx_model",description:`<strong>onnx_model</strong> (<code>Path</code>) &#x2014;
The path to the exported model.`,name:"onnx_model"},{anchor:"optimum.exporters.onnx.validate_model_outputs.onnx_named_outputs",description:`<strong>onnx_named_outputs</strong> (<code>List[str]</code>) &#x2014;
The names of the outputs to check.`,name:"onnx_named_outputs"},{anchor:"optimum.exporters.onnx.validate_model_outputs.atol",description:`<strong>atol</strong> (<code>Optional[float]</code>, defaults to <code>None</code>) &#x2014;
The absolute tolerance in terms of outputs difference between the reference and the exported model.`,name:"atol"},{anchor:"optimum.exporters.onnx.validate_model_outputs.input_shapes",description:`<strong>input_shapes</strong> (<code>Optional[Dict]</code>, defaults to <code>None</code>) &#x2014;
If specified, allows to use specific shapes to validate the ONNX model on.`,name:"input_shapes"},{anchor:"optimum.exporters.onnx.validate_model_outputs.device",description:`<strong>device</strong> (<code>str</code>, defaults to <code>&quot;cpu&quot;</code>) &#x2014;
The device on which the ONNX model will be validated. Either <code>cpu</code> or <code>cuda</code>. Validation on a CUDA device is supported only for PyTorch.`,name:"device"},{anchor:"optimum.exporters.onnx.validate_model_outputs.use_subprocess",description:`<strong>use_subprocess</strong> (<code>Optional[bool]</code>, defaults to <code>True</code>) &#x2014;
Launch validation of each exported model in a subprocess.`,name:"use_subprocess"},{anchor:"optimum.exporters.onnx.validate_model_outputs.model_kwargs",description:`<strong>model_kwargs</strong> (<code>Optional[Dict[str, Any]]</code>, defaults to <code>None</code>) &#x2014;
Experimental usage: keyword arguments to pass to the model during
the export and validation.`,name:"model_kwargs"}],source:"https://github.com/huggingface/optimum-onnx/blob/main/optimum/exporters/onnx/convert.py#L167",raiseDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<ul>
<li><code>ValueError</code> — If the outputs shapes or values do not match between the reference and the exported model.</li>
</ul>
`,raiseType:`<script context="module">export const metadata = 'undefined';<\/script>


<p><code>ValueError</code></p>
`}}),{c(){s=c("meta"),w=a(),m=c("p"),d=a(),h(p.$$.fragment),t=a(),h(u.$$.fragment),K=a(),F=c("p"),F.innerHTML=we,ee=a(),h(E.$$.fragment),oe=a(),N=c("div"),h(j.$$.fragment),xe=a(),H=c("p"),H.innerHTML=Te,he=a(),h(P.$$.fragment),te=a(),y=c("div"),h(A.$$.fragment),fe=a(),V=c("p"),V.innerHTML=Oe,ge=a(),h(C.$$.fragment),ne=a(),T=c("div"),h(U.$$.fragment),_e=a(),W=c("p"),W.textContent=$e,re=a(),O=c("div"),h(z.$$.fragment),ve=a(),Z=c("p"),Z.textContent=ke,se=a(),h(L.$$.fragment),ae=a(),$=c("div"),h(R.$$.fragment),be=a(),G=c("p"),G.innerHTML=Me,ie=a(),k=c("div"),h(J.$$.fragment),Ne=a(),S=c("p"),S.textContent=qe,de=a(),Y=c("p"),this.h()},l(e){const n=je("svelte-u9bgzb",document.head);s=l(n,"META",{name:!0,content:!0}),n.forEach(o),w=i(e),m=l(e,"P",{}),D(m).forEach(o),d=i(e),f(p.$$.fragment,e),t=i(e),f(u.$$.fragment,e),K=i(e),F=l(e,"P",{"data-svelte-h":!0}),X(F)!=="svelte-12iitzy"&&(F.innerHTML=we),ee=i(e),f(E.$$.fragment,e),oe=i(e),N=l(e,"DIV",{class:!0});var M=D(N);f(j.$$.fragment,M),xe=i(M),H=l(M,"P",{"data-svelte-h":!0}),X(H)!=="svelte-laaw6v"&&(H.innerHTML=Te),he=i(M),f(P.$$.fragment,M),M.forEach(o),te=i(e),y=l(e,"DIV",{class:!0});var q=D(y);f(A.$$.fragment,q),fe=i(q),V=l(q,"P",{"data-svelte-h":!0}),X(V)!=="svelte-108bfhr"&&(V.innerHTML=Oe),ge=i(q),f(C.$$.fragment,q),q.forEach(o),ne=i(e),T=l(e,"DIV",{class:!0});var le=D(T);f(U.$$.fragment,le),_e=i(le),W=l(le,"P",{"data-svelte-h":!0}),X(W)!=="svelte-15a3jdv"&&(W.textContent=$e),le.forEach(o),re=i(e),O=l(e,"DIV",{class:!0});var pe=D(O);f(z.$$.fragment,pe),ve=i(pe),Z=l(pe,"P",{"data-svelte-h":!0}),X(Z)!=="svelte-h0jnyb"&&(Z.textContent=ke),pe.forEach(o),se=i(e),f(L.$$.fragment,e),ae=i(e),$=l(e,"DIV",{class:!0});var me=D($);f(R.$$.fragment,me),be=i(me),G=l(me,"P",{"data-svelte-h":!0}),X(G)!=="svelte-rrh373"&&(G.innerHTML=Me),me.forEach(o),ie=i(e),k=l(e,"DIV",{class:!0});var ue=D(k);f(J.$$.fragment,ue),Ne=i(ue),S=l(ue,"P",{"data-svelte-h":!0}),X(S)!=="svelte-1w8b0fb"&&(S.textContent=qe),ue.forEach(o),de=i(e),Y=l(e,"P",{}),D(Y).forEach(o),this.h()},h(){I(s,"name","hf:doc:metadata"),I(s,"content",Re),I(N,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),I(y,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),I(T,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),I(O,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),I($,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),I(k,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8")},m(e,n){x(document.head,s),r(e,w,n),r(e,m,n),r(e,d,n),g(p,e,n),r(e,t,n),g(u,e,n),r(e,K,n),r(e,F,n),r(e,ee,n),g(E,e,n),r(e,oe,n),r(e,N,n),g(j,N,null),x(N,xe),x(N,H),x(N,he),g(P,N,null),r(e,te,n),r(e,y,n),g(A,y,null),x(y,fe),x(y,V),x(y,ge),g(C,y,null),r(e,ne,n),r(e,T,n),g(U,T,null),x(T,_e),x(T,W),r(e,re,n),r(e,O,n),g(z,O,null),x(O,ve),x(O,Z),r(e,se,n),g(L,e,n),r(e,ae,n),r(e,$,n),g(R,$,null),x($,be),x($,G),r(e,ie,n),r(e,k,n),g(J,k,null),x(k,Ne),x(k,S),r(e,de,n),r(e,Y,n),ce=!0},p(e,[n]){const M={};n&2&&(M.$$scope={dirty:n,ctx:e}),P.$set(M);const q={};n&2&&(q.$$scope={dirty:n,ctx:e}),C.$set(q)},i(e){ce||(_(p.$$.fragment,e),_(u.$$.fragment,e),_(E.$$.fragment,e),_(j.$$.fragment,e),_(P.$$.fragment,e),_(A.$$.fragment,e),_(C.$$.fragment,e),_(U.$$.fragment,e),_(z.$$.fragment,e),_(L.$$.fragment,e),_(R.$$.fragment,e),_(J.$$.fragment,e),ce=!0)},o(e){v(p.$$.fragment,e),v(u.$$.fragment,e),v(E.$$.fragment,e),v(j.$$.fragment,e),v(P.$$.fragment,e),v(A.$$.fragment,e),v(C.$$.fragment,e),v(U.$$.fragment,e),v(z.$$.fragment,e),v(L.$$.fragment,e),v(R.$$.fragment,e),v(J.$$.fragment,e),ce=!1},d(e){e&&(o(w),o(m),o(d),o(t),o(K),o(F),o(ee),o(oe),o(N),o(te),o(y),o(ne),o(T),o(re),o(O),o(se),o(ae),o($),o(ie),o(k),o(de),o(Y)),o(s),b(p,e),b(u,e),b(E,e),b(j),b(P),b(A),b(C),b(U),b(z),b(L,e),b(R),b(J)}}}const Re='{"title":"Export functions","local":"export-functions","sections":[{"title":"Main functions","local":"optimum.exporters.onnx.main_export","sections":[],"depth":2},{"title":"Utility functions","local":"optimum.exporters.utils.check_dummy_inputs_are_allowed","sections":[],"depth":2}],"depth":1}';function Je(B){return Ie(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Se extends Fe{constructor(s){super(),Ee(this,s,Je,Le,De,{})}}export{Se as component};
