import{s as Qe,n as Le,o as Ye}from"../chunks/scheduler.5f3e6389.js";import{S as ze,i as qe,e as c,s as o,c as s,h as Oe,a as M,d as t,b as m,f as Fe,g as a,j as u,k as He,l as Pe,m as n,n as i,t as r,o as p,p as d}from"../chunks/index.373ab25c.js";import{C as Ae,H as f}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.315d5a08.js";import{C as y}from"../chunks/CodeBlock.fbe06bf8.js";function Ke(Xe){let b,P,q,A,T,K,J,D,w,$e=`Optimum is a utility package for building and running inference with accelerated runtime like ONNX Runtime.
Optimum can be used to load optimized models from the <a href="hf.co/models">Hugging Face Hub</a> and create pipelines
to run accelerated inference without rewriting your APIs.`,ee,h,le,Z,te,g,Ge='Once your model was <a href="https://huggingface.co/docs/optimum/exporters/onnx/usage_guides/export_a_model" rel="nofollow">exported to the ONNX format</a>, you can load it by replacing <code>AutoModelForXxx</code> with the corresponding <code>ORTModelForXxx</code> class.',ne,U,oe,W,ve='More information for all the supported <code>ORTModelForXxx</code> in our <a href="https://huggingface.co/docs/optimum/onnxruntime/package_reference/modeling" rel="nofollow">documentation</a>',me,j,se,I,Ve="You can also load your ONNX model using ONNX Runtime pipelines which replace <code>transformers.pipeline</code> with <code>optimum.onnxruntime.pipeline</code>.",ae,R,ie,X,Ne='More information for all the supported <code>ORTXxxPipeline</code> in our <a href="https://huggingface.co/docs/optimum/onnxruntime/package_reference/pipelines" rel="nofollow">documentation</a>',re,$,pe,G,Be='Once your model was <a href="https://huggingface.co/docs/optimum/exporters/onnx/usage_guides/export_a_model" rel="nofollow">exported to the ONNX format</a>, you can load it by replacing <code>DiffusionPipeline</code> with the corresponding <code>ORTDiffusionPipeline</code> class.',de,v,ce,V,xe='More information for all the supported <code>ORTXxxPipeline</code> in our <a href="https://huggingface.co/docs/optimum/onnxruntime/package_reference/modeling_diffusion" rel="nofollow">documentation</a>',Me,N,ue,B,Ee='Once your model was <a href="https://huggingface.co/docs/optimum/exporters/onnx/usage_guides/export_a_model" rel="nofollow">exported to the ONNX format</a>, you can load it by replacing <code>AutoModel</code> with the corresponding <code>ORTModelForFeatureExtraction</code> class.',be,x,fe,E,ke='You can also load your ONNX model directly using the <a href="https://sbert.net/docs/sentence_transformer/usage/efficiency.html#onnx" rel="nofollow"><code>sentence_transformers.SentenceTransformer</code></a> class, just make sure to have <code>sentence-transformers&gt;=3.2</code> installed. If the model wasn’t already converted to ONNX, it will be converted automatically on-the-fly.',ye,k,Te,_,Je,C,_e='Once your model was <a href="https://huggingface.co/docs/optimum/exporters/onnx/usage_guides/export_a_model" rel="nofollow">exported to the ONNX format</a>, you can load it by replacing the <code>create_model</code> with the corresponding <code>ORTModelForImageClassification</code> class.',we,S,he,F,Ze,H,Ce=`In case your model wasn’t already <a href="https://huggingface.co/docs/optimum/exporters/onnx/usage_guides/export_a_model" rel="nofollow">converted to ONNX</a>, <a href="/docs/optimum/v0.0.2/en/onnxruntime/package_reference/modeling#optimum.onnxruntime.ORTModel">ORTModel</a> includes a method to convert your model to ONNX on-the-fly.
Simply pass <code>export=True</code> to the <a href="/docs/optimum/v0.0.2/en/onnxruntime/package_reference/modeling#optimum.onnxruntime.ORTModel.from_pretrained">from_pretrained()</a> method, and your model will be loaded and converted to ONNX on-the-fly:`,ge,Q,Ue,L,We,Y,Se='You can also call <code>push_to_hub</code> directly on your model to upload it to the <a href="https://hf.co/models" rel="nofollow">Hub</a>.',je,z,Ie,O,Re;return T=new Ae({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),J=new f({props:{title:"Optimum Inference with ONNX Runtime",local:"optimum-inference-with-onnx-runtime",headingTag:"h1"}}),h=new f({props:{title:"Loading",local:"loading",headingTag:"h2"}}),Z=new f({props:{title:"Transformers models",local:"transformers-models",headingTag:"h3"}}),U=new y({props:{code:"JTIwJTIwZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMkMlMjBwaXBlbGluZSUwQS0lMjBmcm9tJTIwdHJhbnNmb3JtZXJzJTIwaW1wb3J0JTIwQXV0b01vZGVsRm9yQ2F1c2FsTE0lMEElMkIlMjBmcm9tJTIwb3B0aW11bS5vbm54cnVudGltZSUyMGltcG9ydCUyME9SVE1vZGVsRm9yQ2F1c2FsTE0lMEElMEEtJTIwbW9kZWwlMjAlM0QlMjBBdXRvTW9kZWxGb3JDYXVzYWxMTS5mcm9tX3ByZXRyYWluZWQoJTIybWV0YS1sbGFtYSUyRkxsYW1hLTMuMi0xQiUyMiklMjAlMjMlMjBQeVRvcmNoJTIwY2hlY2twb2ludCUwQSUyQiUyMG1vZGVsJTIwJTNEJTIwT1JUTW9kZWxGb3JDYXVzYWxMTS5mcm9tX3ByZXRyYWluZWQoJTIyb25ueC1jb21tdW5pdHklMkZMbGFtYS0zLjItMUIlMjIlMkMlMjBzdWJmb2xkZXIlM0QlMjJvbm54JTIyKSUyMCUyMyUyME9OTlglMjBjaGVja3BvaW50JTBBJTIwJTIwdG9rZW5pemVyJTIwJTNEJTIwQXV0b1Rva2VuaXplci5mcm9tX3ByZXRyYWluZWQoJTIybWV0YS1sbGFtYSUyRkxsYW1hLTMuMi0xQiUyMiklMEElMEElMjAlMjBwaXBlJTIwJTNEJTIwcGlwZWxpbmUoJTIydGV4dC1nZW5lcmF0aW9uJTIyJTJDJTIwbW9kZWwlM0Rtb2RlbCUyQyUyMHRva2VuaXplciUzRHRva2VuaXplciklMEElMjAlMjByZXN1bHQlMjAlM0QlMjBwaXBlKCUyMkhlJTIwbmV2ZXIlMjB3ZW50JTIwb3V0JTIwd2l0aG91dCUyMGElMjBib29rJTIwdW5kZXIlMjBoaXMlMjBhcm0lMjIp",highlighted:`  from transformers import AutoTokenizer, pipeline
<span class="hljs-deletion">- from transformers import AutoModelForCausalLM</span>
<span class="hljs-addition">+ from optimum.onnxruntime import ORTModelForCausalLM</span>

<span class="hljs-deletion">- model = AutoModelForCausalLM.from_pretrained(&quot;meta-llama/Llama-3.2-1B&quot;) # PyTorch checkpoint</span>
<span class="hljs-addition">+ model = ORTModelForCausalLM.from_pretrained(&quot;onnx-community/Llama-3.2-1B&quot;, subfolder=&quot;onnx&quot;) # ONNX checkpoint</span>
  tokenizer = AutoTokenizer.from_pretrained(&quot;meta-llama/Llama-3.2-1B&quot;)

  pipe = pipeline(&quot;text-generation&quot;, model=model, tokenizer=tokenizer)
  result = pipe(&quot;He never went out without a book under his arm&quot;)`,wrap:!1}}),j=new f({props:{title:"Transformers pipelines",local:"transformers-pipelines",headingTag:"h3"}}),R=new y({props:{code:"LSUyMGZyb20lMjB0cmFuc2Zvcm1lcnMlMjBpbXBvcnQlMjBwaXBlbGluZSUwQSUyQiUyMGZyb20lMjBvcHRpbXVtLm9ubnhydW50aW1lJTIwaW1wb3J0JTIwcGlwZWxpbmUlMEElMEElMjAlMjBtb2RlbF9pZCUyMCUzRCUyMCUyMmRpc3RpbGJlcnQtYmFzZS11bmNhc2VkLWZpbmV0dW5lZC1zc3QtMi1lbmdsaXNoJTIyJTBBJTIwJTIwbmxwX3BpcGVsaW5lJTIwJTNEJTIwcGlwZWxpbmUoJTIyc2VudGltZW50LWFuYWx5c2lzJTIyJTJDJTIwbW9kZWwlM0Rtb2RlbF9pZCklMEElMjAlMjByZXN1bHQlMjAlM0QlMjBubHBfcGlwZWxpbmUoJTIySSd2ZSUyMGJlZW4lMjB3YWl0aW5nJTIwZm9yJTIwYSUyMEh1Z2dpbmdGYWNlJTIwY291cnNlJTIwbXklMjB3aG9sZSUyMGxpZmUuJTIyKQ==",highlighted:`<span class="hljs-deletion">- from transformers import pipeline</span>
<span class="hljs-addition">+ from optimum.onnxruntime import pipeline</span>

  model_id = &quot;distilbert-base-uncased-finetuned-sst-2-english&quot;
  nlp_pipeline = pipeline(&quot;sentiment-analysis&quot;, model=model_id)
  result = nlp_pipeline(&quot;I&#x27;ve been waiting for a HuggingFace course my whole life.&quot;)`,wrap:!1}}),$=new f({props:{title:"Diffusers models",local:"diffusers-models",headingTag:"h3"}}),v=new y({props:{code:"LSUyMGZyb20lMjBkaWZmdXNlcnMlMjBpbXBvcnQlMjBEaWZmdXNpb25QaXBlbGluZSUwQSUyQiUyMGZyb20lMjBvcHRpbXVtLm9ubnhydW50aW1lJTIwaW1wb3J0JTIwT1JURGlmZnVzaW9uUGlwZWxpbmUlMEElMEElMjAlMjBtb2RlbF9pZCUyMCUzRCUyMCUyMnJ1bndheW1sJTJGc3RhYmxlLWRpZmZ1c2lvbi12MS01JTIyJTBBLSUyMHBpcGVsaW5lJTIwJTNEJTIwRGlmZnVzaW9uUGlwZWxpbmUuZnJvbV9wcmV0cmFpbmVkKG1vZGVsX2lkKSUwQSUyQiUyMHBpcGVsaW5lJTIwJTNEJTIwT1JURGlmZnVzaW9uUGlwZWxpbmUuZnJvbV9wcmV0cmFpbmVkKG1vZGVsX2lkJTJDJTIwZXhwb3J0JTNEVHJ1ZSklMEElMjAlMjBwcm9tcHQlMjAlM0QlMjAlMjJzYWlsaW5nJTIwc2hpcCUyMGluJTIwc3Rvcm0lMjBieSUyMExlb25hcmRvJTIwZGElMjBWaW5jaSUyMiUwQSUyMCUyMGltYWdlJTIwJTNEJTIwcGlwZWxpbmUocHJvbXB0KS5pbWFnZXMlNUIwJTVE",highlighted:`<span class="hljs-deletion">- from diffusers import DiffusionPipeline</span>
<span class="hljs-addition">+ from optimum.onnxruntime import ORTDiffusionPipeline</span>

  model_id = &quot;runwayml/stable-diffusion-v1-5&quot;
<span class="hljs-deletion">- pipeline = DiffusionPipeline.from_pretrained(model_id)</span>
<span class="hljs-addition">+ pipeline = ORTDiffusionPipeline.from_pretrained(model_id, export=True)</span>
  prompt = &quot;sailing ship in storm by Leonardo da Vinci&quot;
  image = pipeline(prompt).images[0]`,wrap:!1}}),N=new f({props:{title:"Sentence Transformers models",local:"sentence-transformers-models",headingTag:"h3"}}),x=new y({props:{code:"JTIwJTIwZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMEEtJTIwZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbCUwQSUyQiUyMGZyb20lMjBvcHRpbXVtLm9ubnhydW50aW1lJTIwaW1wb3J0JTIwT1JUTW9kZWxGb3JGZWF0dXJlRXh0cmFjdGlvbiUwQSUwQSUyMCUyMHRva2VuaXplciUyMCUzRCUyMEF1dG9Ub2tlbml6ZXIuZnJvbV9wcmV0cmFpbmVkKCUyMnNlbnRlbmNlLXRyYW5zZm9ybWVycyUyRmFsbC1NaW5pTE0tTDYtdjIlMjIpJTBBLSUyMG1vZGVsJTIwJTNEJTIwQXV0b01vZGVsLmZyb21fcHJldHJhaW5lZCglMjJzZW50ZW5jZS10cmFuc2Zvcm1lcnMlMkZhbGwtTWluaUxNLUw2LXYyJTIyKSUwQSUyQiUyMG1vZGVsJTIwJTNEJTIwT1JUTW9kZWxGb3JGZWF0dXJlRXh0cmFjdGlvbi5mcm9tX3ByZXRyYWluZWQoJTIyb3B0aW11bSUyRmFsbC1NaW5pTE0tTDYtdjIlMjIpJTBBJTIwJTIwaW5wdXRzJTIwJTNEJTIwdG9rZW5pemVyKCUyMlRoaXMlMjBpcyUyMGFuJTIwZXhhbXBsZSUyMHNlbnRlbmNlJTIyJTJDJTIwcmV0dXJuX3RlbnNvcnMlM0QlMjJwdCUyMiklMEElMjAlMjBvdXRwdXRzJTIwJTNEJTIwbW9kZWwoKippbnB1dHMp",highlighted:`  from transformers import AutoTokenizer
<span class="hljs-deletion">- from transformers import AutoModel</span>
<span class="hljs-addition">+ from optimum.onnxruntime import ORTModelForFeatureExtraction</span>

  tokenizer = AutoTokenizer.from_pretrained(&quot;sentence-transformers/all-MiniLM-L6-v2&quot;)
<span class="hljs-deletion">- model = AutoModel.from_pretrained(&quot;sentence-transformers/all-MiniLM-L6-v2&quot;)</span>
<span class="hljs-addition">+ model = ORTModelForFeatureExtraction.from_pretrained(&quot;optimum/all-MiniLM-L6-v2&quot;)</span>
  inputs = tokenizer(&quot;This is an example sentence&quot;, return_tensors=&quot;pt&quot;)
  outputs = model(**inputs)`,wrap:!1}}),k=new y({props:{code:"JTIwJTIwZnJvbSUyMHNlbnRlbmNlX3RyYW5zZm9ybWVycyUyMGltcG9ydCUyMFNlbnRlbmNlVHJhbnNmb3JtZXIlMEElMEElMjAlMjBtb2RlbF9pZCUyMCUzRCUyMCUyMnNlbnRlbmNlLXRyYW5zZm9ybWVycyUyRmFsbC1NaW5pTE0tTDYtdjIlMjIlMEEtJTIwbW9kZWwlMjAlM0QlMjBTZW50ZW5jZVRyYW5zZm9ybWVyKG1vZGVsX2lkKSUwQSUyQiUyMG1vZGVsJTIwJTNEJTIwU2VudGVuY2VUcmFuc2Zvcm1lcihtb2RlbF9pZCUyQyUyMGJhY2tlbmQlM0QlMjJvbm54JTIyKSUwQSUwQSUyMCUyMHNlbnRlbmNlcyUyMCUzRCUyMCU1QiUyMlRoaXMlMjBpcyUyMGFuJTIwZXhhbXBsZSUyMHNlbnRlbmNlJTIyJTJDJTIwJTIyRWFjaCUyMHNlbnRlbmNlJTIwaXMlMjBjb252ZXJ0ZWQlMjIlNUQlMEElMjAlMjBlbWJlZGRpbmdzJTIwJTNEJTIwbW9kZWwuZW5jb2RlKHNlbnRlbmNlcyk=",highlighted:`  from sentence_transformers import SentenceTransformer

  model_id = &quot;sentence-transformers/all-MiniLM-L6-v2&quot;
<span class="hljs-deletion">- model = SentenceTransformer(model_id)</span>
<span class="hljs-addition">+ model = SentenceTransformer(model_id, backend=&quot;onnx&quot;)</span>

  sentences = [&quot;This is an example sentence&quot;, &quot;Each sentence is converted&quot;]
  embeddings = model.encode(sentences)`,wrap:!1}}),_=new f({props:{title:"Timm models",local:"timm-models",headingTag:"h3"}}),S=new y({props:{code:"JTIwJTIwaW1wb3J0JTIwcmVxdWVzdHMlMEElMjAlMjBmcm9tJTIwUElMJTIwaW1wb3J0JTIwSW1hZ2UlMEEtJTIwZnJvbSUyMHRpbW0lMjBpbXBvcnQlMjBjcmVhdGVfbW9kZWwlMEElMjAlMjBmcm9tJTIwdGltbS5kYXRhJTIwaW1wb3J0JTIwcmVzb2x2ZV9kYXRhX2NvbmZpZyUyQyUyMGNyZWF0ZV90cmFuc2Zvcm0lMEElMkIlMjBmcm9tJTIwb3B0aW11bS5vbm54cnVudGltZSUyMGltcG9ydCUyME9SVE1vZGVsRm9ySW1hZ2VDbGFzc2lmaWNhdGlvbiUwQSUwQS0lMjBtb2RlbCUyMCUzRCUyMGNyZWF0ZV9tb2RlbCglMjJ0aW1tJTJGbW9iaWxlbmV0djNfbGFyZ2VfMTAwLnJhX2luMWslMjIlMkMlMjBwcmV0cmFpbmVkJTNEVHJ1ZSklMEElMkIlMjBtb2RlbCUyMCUzRCUyME9SVE1vZGVsRm9ySW1hZ2VDbGFzc2lmaWNhdGlvbi5mcm9tX3ByZXRyYWluZWQoJTIyb3B0aW11bSUyRm1vYmlsZW5ldHYzX2xhcmdlXzEwMC5yYV9pbjFrJTIyKSUwQSUyMCUyMHRyYW5zZm9ybSUyMCUzRCUyMGNyZWF0ZV90cmFuc2Zvcm0oKipyZXNvbHZlX2RhdGFfY29uZmlnKG1vZGVsLmNvbmZpZy5wcmV0cmFpbmVkX2NmZyUyQyUyMG1vZGVsJTNEbW9kZWwpKSUwQSUyMCUyMHVybCUyMCUzRCUyMCUyMmh0dHBzJTNBJTJGJTJGaHVnZ2luZ2ZhY2UuY28lMkZkYXRhc2V0cyUyRmh1Z2dpbmdmYWNlJTJGZG9jdW1lbnRhdGlvbi1pbWFnZXMlMkZyZXNvbHZlJTJGbWFpbiUyRmJlaWduZXRzLXRhc2stZ3VpZGUucG5nJTIyJTBBJTIwJTIwaW1hZ2UlMjAlM0QlMjBJbWFnZS5vcGVuKHJlcXVlc3RzLmdldCh1cmwlMkMlMjBzdHJlYW0lM0RUcnVlKS5yYXcpJTBBJTIwJTIwaW5wdXRzJTIwJTNEJTIwdHJhbnNmb3JtKGltYWdlKS51bnNxdWVlemUoMCklMEElMjAlMjBvdXRwdXRzJTIwJTNEJTIwbW9kZWwoaW5wdXRzKQ==",highlighted:`  import requests
  from PIL import Image
<span class="hljs-deletion">- from timm import create_model</span>
  from timm.data import resolve_data_config, create_transform
<span class="hljs-addition">+ from optimum.onnxruntime import ORTModelForImageClassification</span>

<span class="hljs-deletion">- model = create_model(&quot;timm/mobilenetv3_large_100.ra_in1k&quot;, pretrained=True)</span>
<span class="hljs-addition">+ model = ORTModelForImageClassification.from_pretrained(&quot;optimum/mobilenetv3_large_100.ra_in1k&quot;)</span>
  transform = create_transform(**resolve_data_config(model.config.pretrained_cfg, model=model))
  url = &quot;https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png&quot;
  image = Image.open(requests.get(url, stream=True).raw)
  inputs = transform(image).unsqueeze(0)
  outputs = model(inputs)`,wrap:!1}}),F=new f({props:{title:"Converting your model to ONNX on-the-fly",local:"converting-your-model-to-onnx-on-the-fly",headingTag:"h2"}}),Q=new y({props:{code:"ZnJvbSUyMG9wdGltdW0ub25ueHJ1bnRpbWUlMjBpbXBvcnQlMjBPUlRNb2RlbEZvclNlcXVlbmNlQ2xhc3NpZmljYXRpb24lMEElMEElMjMlMjBMb2FkJTIwdGhlJTIwbW9kZWwlMjBmcm9tJTIwdGhlJTIwaHViJTIwYW5kJTIwZXhwb3J0JTIwaXQlMjB0byUyMHRoZSUyME9OTlglMjBmb3JtYXQlMEFtb2RlbF9pZCUyMCUzRCUyMCUyMmRpc3RpbGJlcnQtYmFzZS11bmNhc2VkLWZpbmV0dW5lZC1zc3QtMi1lbmdsaXNoJTIyJTBBbW9kZWwlMjAlM0QlMjBPUlRNb2RlbEZvclNlcXVlbmNlQ2xhc3NpZmljYXRpb24uZnJvbV9wcmV0cmFpbmVkKG1vZGVsX2lkJTJDJTIwZXhwb3J0JTNEVHJ1ZSk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> optimum.onnxruntime <span class="hljs-keyword">import</span> ORTModelForSequenceClassification

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Load the model from the hub and export it to the ONNX format</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model_id = <span class="hljs-string">&quot;distilbert-base-uncased-finetuned-sst-2-english&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model = ORTModelForSequenceClassification.from_pretrained(model_id, export=<span class="hljs-literal">True</span>)`,wrap:!1}}),L=new f({props:{title:"Pushing your model to the Hub",local:"pushing-your-model-to-the-hub",headingTag:"h2"}}),z=new y({props:{code:"ZnJvbSUyMG9wdGltdW0ub25ueHJ1bnRpbWUlMjBpbXBvcnQlMjBPUlRNb2RlbEZvclNlcXVlbmNlQ2xhc3NpZmljYXRpb24lMEElMEElMjMlMjBMb2FkJTIwdGhlJTIwbW9kZWwlMjBmcm9tJTIwdGhlJTIwaHViJTIwYW5kJTIwZXhwb3J0JTIwaXQlMjB0byUyMHRoZSUyME9OTlglMjBmb3JtYXQlMEFtb2RlbF9pZCUyMCUzRCUyMCUyMmRpc3RpbGJlcnQtYmFzZS11bmNhc2VkLWZpbmV0dW5lZC1zc3QtMi1lbmdsaXNoJTIyJTBBbW9kZWwlMjAlM0QlMjBPUlRNb2RlbEZvclNlcXVlbmNlQ2xhc3NpZmljYXRpb24uZnJvbV9wcmV0cmFpbmVkKG1vZGVsX2lkJTJDJTIwZXhwb3J0JTNEVHJ1ZSklMEElMEElMjMlMjBTYXZlJTIwdGhlJTIwY29udmVydGVkJTIwbW9kZWwlMjBsb2NhbGx5JTBBb3V0cHV0X2RpciUyMCUzRCUyMCUyMmFfbG9jYWxfcGF0aF9mb3JfY29udmVydF9vbm54X21vZGVsJTIyJTBBbW9kZWwuc2F2ZV9wcmV0cmFpbmVkKG91dHB1dF9kaXIpJTBBJTBBbW9kZWwucHVzaF90b19odWIob3V0cHV0X2RpciUyQyUyMHJlcG9zaXRvcnlfaWQlM0QlMjJteS1vbm54LXJlcG8lMjIp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> optimum.onnxruntime <span class="hljs-keyword">import</span> ORTModelForSequenceClassification

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Load the model from the hub and export it to the ONNX format</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model_id = <span class="hljs-string">&quot;distilbert-base-uncased-finetuned-sst-2-english&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model = ORTModelForSequenceClassification.from_pretrained(model_id, export=<span class="hljs-literal">True</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Save the converted model locally</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>output_dir = <span class="hljs-string">&quot;a_local_path_for_convert_onnx_model&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model.save_pretrained(output_dir)

<span class="hljs-comment"># Push the onnx model to HF Hub</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model.push_to_hub(output_dir, repository_id=<span class="hljs-string">&quot;my-onnx-repo&quot;</span>)`,wrap:!1}}),{c(){b=c("meta"),P=o(),q=c("p"),A=o(),s(T.$$.fragment),K=o(),s(J.$$.fragment),D=o(),w=c("p"),w.innerHTML=$e,ee=o(),s(h.$$.fragment),le=o(),s(Z.$$.fragment),te=o(),g=c("p"),g.innerHTML=Ge,ne=o(),s(U.$$.fragment),oe=o(),W=c("p"),W.innerHTML=ve,me=o(),s(j.$$.fragment),se=o(),I=c("p"),I.innerHTML=Ve,ae=o(),s(R.$$.fragment),ie=o(),X=c("p"),X.innerHTML=Ne,re=o(),s($.$$.fragment),pe=o(),G=c("p"),G.innerHTML=Be,de=o(),s(v.$$.fragment),ce=o(),V=c("p"),V.innerHTML=xe,Me=o(),s(N.$$.fragment),ue=o(),B=c("p"),B.innerHTML=Ee,be=o(),s(x.$$.fragment),fe=o(),E=c("p"),E.innerHTML=ke,ye=o(),s(k.$$.fragment),Te=o(),s(_.$$.fragment),Je=o(),C=c("p"),C.innerHTML=_e,we=o(),s(S.$$.fragment),he=o(),s(F.$$.fragment),Ze=o(),H=c("p"),H.innerHTML=Ce,ge=o(),s(Q.$$.fragment),Ue=o(),s(L.$$.fragment),We=o(),Y=c("p"),Y.innerHTML=Se,je=o(),s(z.$$.fragment),Ie=o(),O=c("p"),this.h()},l(e){const l=Oe("svelte-u9bgzb",document.head);b=M(l,"META",{name:!0,content:!0}),l.forEach(t),P=m(e),q=M(e,"P",{}),Fe(q).forEach(t),A=m(e),a(T.$$.fragment,e),K=m(e),a(J.$$.fragment,e),D=m(e),w=M(e,"P",{"data-svelte-h":!0}),u(w)!=="svelte-4xrbw1"&&(w.innerHTML=$e),ee=m(e),a(h.$$.fragment,e),le=m(e),a(Z.$$.fragment,e),te=m(e),g=M(e,"P",{"data-svelte-h":!0}),u(g)!=="svelte-gcnc8j"&&(g.innerHTML=Ge),ne=m(e),a(U.$$.fragment,e),oe=m(e),W=M(e,"P",{"data-svelte-h":!0}),u(W)!=="svelte-w7t282"&&(W.innerHTML=ve),me=m(e),a(j.$$.fragment,e),se=m(e),I=M(e,"P",{"data-svelte-h":!0}),u(I)!=="svelte-isld80"&&(I.innerHTML=Ve),ae=m(e),a(R.$$.fragment,e),ie=m(e),X=M(e,"P",{"data-svelte-h":!0}),u(X)!=="svelte-1mfm246"&&(X.innerHTML=Ne),re=m(e),a($.$$.fragment,e),pe=m(e),G=M(e,"P",{"data-svelte-h":!0}),u(G)!=="svelte-xv652"&&(G.innerHTML=Be),de=m(e),a(v.$$.fragment,e),ce=m(e),V=M(e,"P",{"data-svelte-h":!0}),u(V)!=="svelte-105e2wg"&&(V.innerHTML=xe),Me=m(e),a(N.$$.fragment,e),ue=m(e),B=M(e,"P",{"data-svelte-h":!0}),u(B)!=="svelte-173api3"&&(B.innerHTML=Ee),be=m(e),a(x.$$.fragment,e),fe=m(e),E=M(e,"P",{"data-svelte-h":!0}),u(E)!=="svelte-1mwaw5n"&&(E.innerHTML=ke),ye=m(e),a(k.$$.fragment,e),Te=m(e),a(_.$$.fragment,e),Je=m(e),C=M(e,"P",{"data-svelte-h":!0}),u(C)!=="svelte-1vruwj8"&&(C.innerHTML=_e),we=m(e),a(S.$$.fragment,e),he=m(e),a(F.$$.fragment,e),Ze=m(e),H=M(e,"P",{"data-svelte-h":!0}),u(H)!=="svelte-248wkh"&&(H.innerHTML=Ce),ge=m(e),a(Q.$$.fragment,e),Ue=m(e),a(L.$$.fragment,e),We=m(e),Y=M(e,"P",{"data-svelte-h":!0}),u(Y)!=="svelte-x3771f"&&(Y.innerHTML=Se),je=m(e),a(z.$$.fragment,e),Ie=m(e),O=M(e,"P",{}),Fe(O).forEach(t),this.h()},h(){He(b,"name","hf:doc:metadata"),He(b,"content",De)},m(e,l){Pe(document.head,b),n(e,P,l),n(e,q,l),n(e,A,l),i(T,e,l),n(e,K,l),i(J,e,l),n(e,D,l),n(e,w,l),n(e,ee,l),i(h,e,l),n(e,le,l),i(Z,e,l),n(e,te,l),n(e,g,l),n(e,ne,l),i(U,e,l),n(e,oe,l),n(e,W,l),n(e,me,l),i(j,e,l),n(e,se,l),n(e,I,l),n(e,ae,l),i(R,e,l),n(e,ie,l),n(e,X,l),n(e,re,l),i($,e,l),n(e,pe,l),n(e,G,l),n(e,de,l),i(v,e,l),n(e,ce,l),n(e,V,l),n(e,Me,l),i(N,e,l),n(e,ue,l),n(e,B,l),n(e,be,l),i(x,e,l),n(e,fe,l),n(e,E,l),n(e,ye,l),i(k,e,l),n(e,Te,l),i(_,e,l),n(e,Je,l),n(e,C,l),n(e,we,l),i(S,e,l),n(e,he,l),i(F,e,l),n(e,Ze,l),n(e,H,l),n(e,ge,l),i(Q,e,l),n(e,Ue,l),i(L,e,l),n(e,We,l),n(e,Y,l),n(e,je,l),i(z,e,l),n(e,Ie,l),n(e,O,l),Re=!0},p:Le,i(e){Re||(r(T.$$.fragment,e),r(J.$$.fragment,e),r(h.$$.fragment,e),r(Z.$$.fragment,e),r(U.$$.fragment,e),r(j.$$.fragment,e),r(R.$$.fragment,e),r($.$$.fragment,e),r(v.$$.fragment,e),r(N.$$.fragment,e),r(x.$$.fragment,e),r(k.$$.fragment,e),r(_.$$.fragment,e),r(S.$$.fragment,e),r(F.$$.fragment,e),r(Q.$$.fragment,e),r(L.$$.fragment,e),r(z.$$.fragment,e),Re=!0)},o(e){p(T.$$.fragment,e),p(J.$$.fragment,e),p(h.$$.fragment,e),p(Z.$$.fragment,e),p(U.$$.fragment,e),p(j.$$.fragment,e),p(R.$$.fragment,e),p($.$$.fragment,e),p(v.$$.fragment,e),p(N.$$.fragment,e),p(x.$$.fragment,e),p(k.$$.fragment,e),p(_.$$.fragment,e),p(S.$$.fragment,e),p(F.$$.fragment,e),p(Q.$$.fragment,e),p(L.$$.fragment,e),p(z.$$.fragment,e),Re=!1},d(e){e&&(t(P),t(q),t(A),t(K),t(D),t(w),t(ee),t(le),t(te),t(g),t(ne),t(oe),t(W),t(me),t(se),t(I),t(ae),t(ie),t(X),t(re),t(pe),t(G),t(de),t(ce),t(V),t(Me),t(ue),t(B),t(be),t(fe),t(E),t(ye),t(Te),t(Je),t(C),t(we),t(he),t(Ze),t(H),t(ge),t(Ue),t(We),t(Y),t(je),t(Ie),t(O)),t(b),d(T,e),d(J,e),d(h,e),d(Z,e),d(U,e),d(j,e),d(R,e),d($,e),d(v,e),d(N,e),d(x,e),d(k,e),d(_,e),d(S,e),d(F,e),d(Q,e),d(L,e),d(z,e)}}}const De='{"title":"Optimum Inference with ONNX Runtime","local":"optimum-inference-with-onnx-runtime","sections":[{"title":"Loading","local":"loading","sections":[{"title":"Transformers models","local":"transformers-models","sections":[],"depth":3},{"title":"Transformers pipelines","local":"transformers-pipelines","sections":[],"depth":3},{"title":"Diffusers models","local":"diffusers-models","sections":[],"depth":3},{"title":"Sentence Transformers models","local":"sentence-transformers-models","sections":[],"depth":3},{"title":"Timm models","local":"timm-models","sections":[],"depth":3}],"depth":2},{"title":"Converting your model to ONNX on-the-fly","local":"converting-your-model-to-onnx-on-the-fly","sections":[],"depth":2},{"title":"Pushing your model to the Hub","local":"pushing-your-model-to-the-hub","sections":[],"depth":2}],"depth":1}';function el(Xe){return Ye(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class ml extends ze{constructor(b){super(),qe(this,b,el,Ke,Qe,{})}}export{ml as component};
