import{s as Q,o as H,n as Y}from"../chunks/scheduler.5f3e6389.js";import{S as D,i as L,e as w,s as m,c as _,h as O,a as x,d as a,b as u,f as X,g as M,j as C,k as B,l as f,m as g,n as P,t as $,o as N,p as I,q as K,r as ee}from"../chunks/index.373ab25c.js";import{T as oe}from"../chunks/Tip.3e202241.js";import{C as te,H as ne}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.3893c80c.js";import{D as ie}from"../chunks/Docstring.1f7d66e5.js";import{C as ae}from"../chunks/CodeBlock.d3463551.js";import{E as re}from"../chunks/ExampleCodeBlock.9027bfb5.js";function se(q){let o;return{c(){o=K("While there are such optional arguments as `tokenizer`, `feature_extractor`, `image_processor`, and `processor`,\nthey shouldn't be specified all at once. If these components are not provided, `pipeline` will try to load\nrequired ones automatically. In case you want to provide these components explicitly, please refer to a\nspecific pipeline in order to get more details regarding what components are required.")},l(s){o=ee(s,"While there are such optional arguments as `tokenizer`, `feature_extractor`, `image_processor`, and `processor`,\nthey shouldn't be specified all at once. If these components are not provided, `pipeline` will try to load\nrequired ones automatically. In case you want to provide these components explicitly, please refer to a\nspecific pipeline in order to get more details regarding what components are required.")},m(s,l){g(s,o,l)},d(s){s&&a(o)}}}function le(q){let o,s="Examples:",l,c,d;return c=new ae({props:{code:"ZnJvbSUyMG9wdGltdW0ub25ueHJ1bnRpbWUlMjBpbXBvcnQlMjBwaXBlbGluZSUwQSUwQSUyMyUyMFNlbnRpbWVudCUyMGFuYWx5c2lzJTIwcGlwZWxpbmUlMEFhbmFseXplciUyMCUzRCUyMHBpcGVsaW5lKCUyMnNlbnRpbWVudC1hbmFseXNpcyUyMiklMEElMEElMjMlMjBRdWVzdGlvbiUyMGFuc3dlcmluZyUyMHBpcGVsaW5lJTJDJTIwc3BlY2lmeWluZyUyMHRoZSUyMGNoZWNrcG9pbnQlMjBpZGVudGlmaWVyJTBBb3JhY2xlJTIwJTNEJTIwcGlwZWxpbmUoJTBBJTIwJTIwJTIwJTIwJTIycXVlc3Rpb24tYW5zd2VyaW5nJTIyJTJDJTIwbW9kZWwlM0QlMjJkaXN0aWxiZXJ0JTJGZGlzdGlsYmVydC1iYXNlLWNhc2VkLWRpc3RpbGxlZC1zcXVhZCUyMiUyQyUyMHRva2VuaXplciUzRCUyMmdvb2dsZS1iZXJ0JTJGYmVydC1iYXNlLWNhc2VkJTIyJTBBKSUwQSUwQSUyMyUyME5hbWVkJTIwZW50aXR5JTIwcmVjb2duaXRpb24lMjBwaXBlbGluZSUyQyUyMHBhc3NpbmclMjBpbiUyMGElMjBzcGVjaWZpYyUyMG1vZGVsJTIwYW5kJTIwdG9rZW5pemVyJTBBbW9kZWwlMjAlM0QlMjBPUlRNb2RlbEZvclRva2VuQ2xhc3NpZmljYXRpb24uZnJvbV9wcmV0cmFpbmVkKCUyMmRibWR6JTJGYmVydC1sYXJnZS1jYXNlZC1maW5ldHVuZWQtY29ubGwwMy1lbmdsaXNoJTIyKSUwQXRva2VuaXplciUyMCUzRCUyMEF1dG9Ub2tlbml6ZXIuZnJvbV9wcmV0cmFpbmVkKCUyMmdvb2dsZS1iZXJ0JTJGYmVydC1iYXNlLWNhc2VkJTIyKSUwQXJlY29nbml6ZXIlMjAlM0QlMjBwaXBlbGluZSglMjJuZXIlMjIlMkMlMjBtb2RlbCUzRG1vZGVsJTJDJTIwdG9rZW5pemVyJTNEdG9rZW5pemVyKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> optimum.onnxruntime <span class="hljs-keyword">import</span> pipeline

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Sentiment analysis pipeline</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>analyzer = pipeline(<span class="hljs-string">&quot;sentiment-analysis&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Question answering pipeline, specifying the checkpoint identifier</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>oracle = pipeline(
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;question-answering&quot;</span>, model=<span class="hljs-string">&quot;distilbert/distilbert-base-cased-distilled-squad&quot;</span>, tokenizer=<span class="hljs-string">&quot;google-bert/bert-base-cased&quot;</span>
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Named entity recognition pipeline, passing in a specific model and tokenizer</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model = ORTModelForTokenClassification.from_pretrained(<span class="hljs-string">&quot;dbmdz/bert-large-cased-finetuned-conll03-english&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;google-bert/bert-base-cased&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>recognizer = pipeline(<span class="hljs-string">&quot;ner&quot;</span>, model=model, tokenizer=tokenizer)`,wrap:!1}}),{c(){o=w("p"),o.textContent=s,l=m(),_(c.$$.fragment)},l(t){o=x(t,"P",{"data-svelte-h":!0}),C(o)!=="svelte-kvfsh7"&&(o.textContent=s),l=u(t),M(c.$$.fragment,t)},m(t,p){g(t,o,p),g(t,l,p),P(c,t,p),d=!0},p:Y,i(t){d||($(c.$$.fragment,t),d=!0)},o(t){N(c.$$.fragment,t),d=!1},d(t){t&&(a(o),a(l)),I(c,t)}}}function ce(q){let o,s,l,c,d,t,p,z,i,y,Z,v,S="Utility factory method to build a <code>Pipeline</code> with an ONNX Runtime model, similar to <code>transformers.pipeline</code>.",V,T,E="A pipeline consists of:",W,k,A=`<li>One or more components for pre-processing model inputs, such as a <a href="tokenizer">tokenizer</a>,
<a href="image_processor">image_processor</a>, <a href="feature_extractor">feature_extractor</a>, or <a href="processors">processor</a>.</li> <li>A <a href="model">model</a> that generates predictions from the inputs.</li> <li>Optional post-processing steps to refine the model’s output, which can also be handled by processors.</li>`,G,h,R,b,J,j,U;return d=new te({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),p=new ne({props:{title:"ONNX Runtime Pipelines",local:"optimum.onnxruntime.pipeline",headingTag:"h1"}}),y=new ie({props:{name:"optimum.onnxruntime.pipeline",anchor:"optimum.onnxruntime.pipeline",parameters:[{name:"task",val:": str | None = None"},{name:"model",val:": str | ORTModel | None = None"},{name:"config",val:": str | PretrainedConfig | None = None"},{name:"tokenizer",val:": str | PreTrainedTokenizer | PreTrainedTokenizerFast | None = None"},{name:"feature_extractor",val:": str | FeatureExtractionMixin | None = None"},{name:"image_processor",val:": str | BaseImageProcessor | None = None"},{name:"processor",val:": str | ProcessorMixin | None = None"},{name:"revision",val:": str | None = None"},{name:"use_fast",val:": bool = True"},{name:"token",val:": str | bool | None = None"},{name:"device",val:": int | str | torch.device | None = None"},{name:"trust_remote_code",val:": bool | None = None"},{name:"model_kwargs",val:": dict[str, Any] | None = None"},{name:"pipeline_class",val:": Any | None = None"},{name:"**kwargs",val:": Any"}],parametersDescription:[{anchor:"optimum.onnxruntime.pipeline.task",description:`<strong>task</strong> (<code>str</code>) &#x2014;
The task defining which pipeline will be returned. Currently accepted tasks are:</p>
<ul>
<li><code>&quot;audio-classification&quot;</code>: will return a <code>AudioClassificationPipeline</code>.</li>
<li><code>&quot;automatic-speech-recognition&quot;</code>: will return a <code>AutomaticSpeechRecognitionPipeline</code>.</li>
<li><code>&quot;depth-estimation&quot;</code>: will return a <code>DepthEstimationPipeline</code>.</li>
<li><code>&quot;document-question-answering&quot;</code>: will return a <code>DocumentQuestionAnsweringPipeline</code>.</li>
<li><code>&quot;feature-extraction&quot;</code>: will return a <code>FeatureExtractionPipeline</code>.</li>
<li><code>&quot;fill-mask&quot;</code>: will return a <code>FillMaskPipeline</code>:.</li>
<li><code>&quot;image-classification&quot;</code>: will return a <code>ImageClassificationPipeline</code>.</li>
<li><code>&quot;image-feature-extraction&quot;</code>: will return an <code>ImageFeatureExtractionPipeline</code>.</li>
<li><code>&quot;image-segmentation&quot;</code>: will return a <code>ImageSegmentationPipeline</code>.</li>
<li><code>&quot;image-text-to-text&quot;</code>: will return a <code>ImageTextToTextPipeline</code>.</li>
<li><code>&quot;image-to-image&quot;</code>: will return a <code>ImageToImagePipeline</code>.</li>
<li><code>&quot;image-to-text&quot;</code>: will return a <code>ImageToTextPipeline</code>.</li>
<li><code>&quot;mask-generation&quot;</code>: will return a <code>MaskGenerationPipeline</code>.</li>
<li><code>&quot;object-detection&quot;</code>: will return a <code>ObjectDetectionPipeline</code>.</li>
<li><code>&quot;question-answering&quot;</code>: will return a <code>QuestionAnsweringPipeline</code>.</li>
<li><code>&quot;summarization&quot;</code>: will return a <code>SummarizationPipeline</code>.</li>
<li><code>&quot;table-question-answering&quot;</code>: will return a <code>TableQuestionAnsweringPipeline</code>.</li>
<li><code>&quot;text2text-generation&quot;</code>: will return a <code>Text2TextGenerationPipeline</code>.</li>
<li><code>&quot;text-classification&quot;</code> (alias <code>&quot;sentiment-analysis&quot;</code> available): will return a
<code>TextClassificationPipeline</code>.</li>
<li><code>&quot;text-generation&quot;</code>: will return a <code>TextGenerationPipeline</code>:.</li>
<li><code>&quot;text-to-audio&quot;</code> (alias <code>&quot;text-to-speech&quot;</code> available): will return a <code>TextToAudioPipeline</code>:.</li>
<li><code>&quot;token-classification&quot;</code> (alias <code>&quot;ner&quot;</code> available): will return a <code>TokenClassificationPipeline</code>.</li>
<li><code>&quot;translation&quot;</code>: will return a <code>TranslationPipeline</code>.</li>
<li><code>&quot;translation_xx_to_yy&quot;</code>: will return a <code>TranslationPipeline</code>.</li>
<li><code>&quot;video-classification&quot;</code>: will return a <code>VideoClassificationPipeline</code>.</li>
<li><code>&quot;visual-question-answering&quot;</code>: will return a <code>VisualQuestionAnsweringPipeline</code>.</li>
<li><code>&quot;zero-shot-classification&quot;</code>: will return a <code>ZeroShotClassificationPipeline</code>.</li>
<li><code>&quot;zero-shot-image-classification&quot;</code>: will return a <code>ZeroShotImageClassificationPipeline</code>.</li>
<li><code>&quot;zero-shot-audio-classification&quot;</code>: will return a <code>ZeroShotAudioClassificationPipeline</code>.</li>
<li><code>&quot;zero-shot-object-detection&quot;</code>: will return a <code>ZeroShotObjectDetectionPipeline</code>.</li>
</ul>`,name:"task"},{anchor:"optimum.onnxruntime.pipeline.model",description:`<strong>model</strong> (<code>str</code> or <code>ORTModel</code>, <em>optional</em>) &#x2014;
The model that will be used by the pipeline to make predictions. This can be a model identifier or an
actual instance of a ONNX Runtime model inheriting from <code>ORTModel</code>.</p>
<p>If not provided, the default for the <code>task</code> will be loaded.`,name:"model"},{anchor:"optimum.onnxruntime.pipeline.config",description:`<strong>config</strong> (<code>str</code> or <code>PretrainedConfig</code>, <em>optional</em>) &#x2014;
The configuration that will be used by the pipeline to instantiate the model. This can be a model
identifier or an actual pretrained model configuration inheriting from <code>PretrainedConfig</code>.</p>
<p>If not provided, the default configuration file for the requested model will be used. That means that if
<code>model</code> is given, its default configuration will be used. However, if <code>model</code> is not supplied, this
<code>task</code>&#x2019;s default model&#x2019;s config is used instead.`,name:"config"},{anchor:"optimum.onnxruntime.pipeline.tokenizer",description:`<strong>tokenizer</strong> (<code>str</code> or <code>PreTrainedTokenizer</code>, <em>optional</em>) &#x2014;
The tokenizer that will be used by the pipeline to encode data for the model. This can be a model
identifier or an actual pretrained tokenizer inheriting from <code>PreTrainedTokenizer</code>.</p>
<p>If not provided, the default tokenizer for the given <code>model</code> will be loaded (if it is a string). If <code>model</code>
is not specified or not a string, then the default tokenizer for <code>config</code> is loaded (if it is a string).
However, if <code>config</code> is also not given or not a string, then the default tokenizer for the given <code>task</code>
will be loaded.`,name:"tokenizer"},{anchor:"optimum.onnxruntime.pipeline.feature_extractor",description:`<strong>feature_extractor</strong> (<code>str</code> or <code>PreTrainedFeatureExtractor</code>, <em>optional</em>) &#x2014;
The feature extractor that will be used by the pipeline to encode data for the model. This can be a model
identifier or an actual pretrained feature extractor inheriting from <code>PreTrainedFeatureExtractor</code>.</p>
<p>Feature extractors are used for non-NLP models, such as Speech or Vision models as well as multi-modal
models. Multi-modal models will also require a tokenizer to be passed.</p>
<p>If not provided, the default feature extractor for the given <code>model</code> will be loaded (if it is a string). If
<code>model</code> is not specified or not a string, then the default feature extractor for <code>config</code> is loaded (if it
is a string). However, if <code>config</code> is also not given or not a string, then the default feature extractor
for the given <code>task</code> will be loaded.`,name:"feature_extractor"},{anchor:"optimum.onnxruntime.pipeline.image_processor",description:`<strong>image_processor</strong> (<code>str</code> or <code>BaseImageProcessor</code>, <em>optional</em>) &#x2014;
The image processor that will be used by the pipeline to preprocess images for the model. This can be a
model identifier or an actual image processor inheriting from <code>BaseImageProcessor</code>.</p>
<p>Image processors are used for Vision models and multi-modal models that require image inputs. Multi-modal
models will also require a tokenizer to be passed.</p>
<p>If not provided, the default image processor for the given <code>model</code> will be loaded (if it is a string). If
<code>model</code> is not specified or not a string, then the default image processor for <code>config</code> is loaded (if it is
a string).`,name:"image_processor"},{anchor:"optimum.onnxruntime.pipeline.processor",description:`<strong>processor</strong> (<code>str</code> or <code>ProcessorMixin</code>, <em>optional</em>) &#x2014;
The processor that will be used by the pipeline to preprocess data for the model. This can be a model
identifier or an actual processor inheriting from <code>ProcessorMixin</code>.</p>
<p>Processors are used for multi-modal models that require multi-modal inputs, for example, a model that
requires both text and image inputs.</p>
<p>If not provided, the default processor for the given <code>model</code> will be loaded (if it is a string). If <code>model</code>
is not specified or not a string, then the default processor for <code>config</code> is loaded (if it is a string).`,name:"processor"},{anchor:"optimum.onnxruntime.pipeline.revision",description:`<strong>revision</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;main&quot;</code>) &#x2014;
When passing a task name or a string model identifier: The specific model version to use. It can be a
branch name, a tag name, or a commit id, since we use a git-based system for storing models and other
artifacts on huggingface.co, so <code>revision</code> can be any identifier allowed by git.`,name:"revision"},{anchor:"optimum.onnxruntime.pipeline.use_fast",description:`<strong>use_fast</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether or not to use a Fast tokenizer if possible (a <code>PreTrainedTokenizerFast</code>).`,name:"use_fast"},{anchor:"optimum.onnxruntime.pipeline.use_auth_token",description:`<strong>use_auth_token</strong> (<code>str</code> or <em>bool</em>, <em>optional</em>) &#x2014;
The token to use as HTTP bearer authorization for remote files. If <code>True</code>, will use the token generated
when running <code>hf auth login</code> (stored in <code>~/.huggingface</code>).`,name:"use_auth_token"},{anchor:"optimum.onnxruntime.pipeline.device",description:`<strong>device</strong> (<code>int</code> or <code>str</code> or <code>torch.device</code>) &#x2014;
Defines the device (<em>e.g.</em>, <code>&quot;cpu&quot;</code>, <code>&quot;cuda:1&quot;</code>, <code>&quot;mps&quot;</code>, or a GPU ordinal rank like <code>1</code>) on which this
pipeline will be allocated.`,name:"device"},{anchor:"optimum.onnxruntime.pipeline.device_map",description:`<strong>device_map</strong> (<code>str</code> or <code>dict[str, Union[int, str, torch.device]</code>, <em>optional</em>) &#x2014;
Sent directly as <code>model_kwargs</code> (just a simpler shortcut). When <code>accelerate</code> library is present, set
<code>device_map=&quot;auto&quot;</code> to compute the most optimized <code>device_map</code> automatically (see
<a href="https://huggingface.co/docs/accelerate/main/en/package_reference/big_modeling#accelerate.cpu_offload" rel="nofollow">here</a>
for more information).</p>
<div class="course-tip course-tip-orange bg-gradient-to-br dark:bg-gradient-to-r before:border-orange-500 dark:before:border-orange-800 from-orange-50 dark:from-gray-900 to-white dark:to-gray-950 border border-orange-50 text-orange-700 dark:text-gray-400">
						
<p>Do not use <code>device_map</code> AND <code>device</code> at the same time as they will conflict</p>

					</div>`,name:"device_map"},{anchor:"optimum.onnxruntime.pipeline.torch_dtype",description:`<strong>torch_dtype</strong> (<code>str</code> or <code>torch.dtype</code>, <em>optional</em>) &#x2014;
Sent directly as <code>model_kwargs</code> (just a simpler shortcut) to use the available precision for this model
(<code>torch.float16</code>, <code>torch.bfloat16</code>, &#x2026; or <code>&quot;auto&quot;</code>).`,name:"torch_dtype"},{anchor:"optimum.onnxruntime.pipeline.trust_remote_code",description:`<strong>trust_remote_code</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
Whether or not to allow for custom code defined on the Hub in their own modeling, configuration,
tokenization or even pipeline files. This option should only be set to <code>True</code> for repositories you trust
and in which you have read the code, as it will execute code present on the Hub on your local machine.`,name:"trust_remote_code"},{anchor:"optimum.onnxruntime.pipeline.model_kwargs",description:`<strong>model_kwargs</strong> (<code>dict[str, Any]</code>, <em>optional</em>) &#x2014;
Additional dictionary of keyword arguments passed along to the model&#x2019;s <code>from_pretrained(..., **model_kwargs)</code> function.`,name:"model_kwargs"},{anchor:"optimum.onnxruntime.pipeline.kwargs",description:`<strong>kwargs</strong> (<code>dict[str, Any]</code>, <em>optional</em>) &#x2014;
Additional keyword arguments passed along to the specific pipeline init (see the documentation for the
corresponding pipeline class for possible values).`,name:"kwargs"}],source:"https://github.com/huggingface/optimum-onnx/blob/vr_102/optimum/onnxruntime/pipelines.py#L150",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<p>A suitable pipeline for the task.</p>
`,returnType:`<script context="module">export const metadata = 'undefined';<\/script>


<p><code>Pipeline</code></p>
`}}),h=new oe({props:{$$slots:{default:[se]},$$scope:{ctx:q}}}),b=new re({props:{anchor:"optimum.onnxruntime.pipeline.example",$$slots:{default:[le]},$$scope:{ctx:q}}}),{c(){o=w("meta"),s=m(),l=w("p"),c=m(),_(d.$$.fragment),t=m(),_(p.$$.fragment),z=m(),i=w("div"),_(y.$$.fragment),Z=m(),v=w("p"),v.innerHTML=S,V=m(),T=w("p"),T.textContent=E,W=m(),k=w("ul"),k.innerHTML=A,G=m(),_(h.$$.fragment),R=m(),_(b.$$.fragment),J=m(),j=w("p"),this.h()},l(e){const n=O("svelte-u9bgzb",document.head);o=x(n,"META",{name:!0,content:!0}),n.forEach(a),s=u(e),l=x(e,"P",{}),X(l).forEach(a),c=u(e),M(d.$$.fragment,e),t=u(e),M(p.$$.fragment,e),z=u(e),i=x(e,"DIV",{class:!0});var r=X(i);M(y.$$.fragment,r),Z=u(r),v=x(r,"P",{"data-svelte-h":!0}),C(v)!=="svelte-grxee"&&(v.innerHTML=S),V=u(r),T=x(r,"P",{"data-svelte-h":!0}),C(T)!=="svelte-jpprfs"&&(T.textContent=E),W=u(r),k=x(r,"UL",{"data-svelte-h":!0}),C(k)!=="svelte-1htam2n"&&(k.innerHTML=A),G=u(r),M(h.$$.fragment,r),R=u(r),M(b.$$.fragment,r),r.forEach(a),J=u(e),j=x(e,"P",{}),X(j).forEach(a),this.h()},h(){B(o,"name","hf:doc:metadata"),B(o,"content",de),B(i,"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){f(document.head,o),g(e,s,n),g(e,l,n),g(e,c,n),P(d,e,n),g(e,t,n),P(p,e,n),g(e,z,n),g(e,i,n),P(y,i,null),f(i,Z),f(i,v),f(i,V),f(i,T),f(i,W),f(i,k),f(i,G),P(h,i,null),f(i,R),P(b,i,null),g(e,J,n),g(e,j,n),U=!0},p(e,[n]){const r={};n&2&&(r.$$scope={dirty:n,ctx:e}),h.$set(r);const F={};n&2&&(F.$$scope={dirty:n,ctx:e}),b.$set(F)},i(e){U||($(d.$$.fragment,e),$(p.$$.fragment,e),$(y.$$.fragment,e),$(h.$$.fragment,e),$(b.$$.fragment,e),U=!0)},o(e){N(d.$$.fragment,e),N(p.$$.fragment,e),N(y.$$.fragment,e),N(h.$$.fragment,e),N(b.$$.fragment,e),U=!1},d(e){e&&(a(s),a(l),a(c),a(t),a(z),a(i),a(J),a(j)),a(o),I(d,e),I(p,e),I(y),I(h),I(b)}}}const de='{"title":"ONNX Runtime Pipelines","local":"optimum.onnxruntime.pipeline","sections":[],"depth":1}';function pe(q){return H(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class xe extends D{constructor(o){super(),L(this,o,pe,ce,Q,{})}}export{xe as component};
