import{s as me,n as re,o as oe}from"../chunks/scheduler.d9d004e7.js";import{S as Me,i as pe,e as s,s as n,c as T,h as ce,a as m,d as l,b as i,f as ne,g as J,j as X,k as ie,l as de,m as a,n as g,t as Z,o as v,p as $}from"../chunks/index.4a2b774c.js";import{C as ue,H as P,E as fe}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.c93fcd94.js";import{C as se}from"../chunks/CodeBlock.8bd69f21.js";function he(D){let r,I,C,R,o,W,M,B,p,q="This section shows how to run inference-only workloads on Intel Gaudi accelerator.",x,c,O=`An effective quick start would be to review the inference examples provided in the Optimum for Intel Gaudi
[here].`,E,d,K=`You can also explore the
<a href="(/examples)">examples in the Optimum for Intel Gaudi repository</a>.
While the examples folder includes both training and inference, the inference-specific content
provides valuable guidance for optimizing and running workloads on Intel Gaudi accelerators.`,G,u,ee='For more advanced information about how to speed up inference, check out <a href="../usage_guides/accelerate_inference">this guide</a>.',Y,f,F,h,te="You can find below a template to perform inference with a <code>GaudiTrainer</code> instance where we want to compute the accuracy over the given dataset:",k,y,V,j,le='The variable <code>my_args</code> should contain some inference-specific arguments, you can take a look <a href="https://huggingface.co/docs/transformers/main/en/main_classes/trainer#transformers.TrainingArguments.set_evaluate" rel="nofollow">here</a> to see the arguments that can be interesting to set for inference.',H,w,z,_,ae=`All <a href="/examples">our examples</a> contain instructions for running inference with a given model on a given dataset.
The reasoning is the same for every example: run the example script with <code>--do_eval</code> and <code>--per_device_eval_batch_size</code> and without <code>--do_train</code>.
A simple template is the following:`,S,U,N,b,Q,A,L;return o=new ue({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),M=new P({props:{title:"Run Inference",local:"run-inference",headingTag:"h1"}}),f=new P({props:{title:"With GaudiTrainer",local:"with-gauditrainer",headingTag:"h2"}}),y=new se({props:{code:"aW1wb3J0JTIwZXZhbHVhdGUlMEElMEFtZXRyaWMlMjAlM0QlMjBldmFsdWF0ZS5sb2FkKCUyMmFjY3VyYWN5JT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jb21wdXRlX21ldHJpY3MlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjB0b2tlbml6ZXIlM0RteV90b2tlbml6ZXIlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBkYXRhX2NvbGxhdG9yJTNEbXlfZGF0YV9jb2xsYXRvciUyQyUwQSUyMCUyMCUyMCUyMCklMEElMEElMjMlMjBSdW4lMjBpbmZlcmVuY2UlMEFtZXRyaWNzJTIwJTNEJTIwdHJhaW5lci5ldmFsdWF0ZSgp",highlighted:`<span class="hljs-keyword">import</span> evaluate

metric = evaluate.load(<span class="hljs-string">&quot;accuracy&quot;</span>)

<span class="hljs-comment"># You can define your custom compute_metrics function. It takes an \`EvalPrediction\` object (a namedtuple with a</span>
<span class="hljs-comment"># predictions and label_ids field) and has to return a dictionary string to float.</span>
<span class="hljs-keyword">def</span> <span class="hljs-title function_">my_compute_metrics</span>(<span class="hljs-params">p</span>):
    <span class="hljs-keyword">return</span> metric.compute(predictions=np.argmax(p.predictions, axis=<span class="hljs-number">1</span>), references=p.label_ids)

<span class="hljs-comment"># Trainer initialization</span>
trainer = GaudiTrainer(
        model=my_model,
        gaudi_config=my_gaudi_config,
        args=my_args,
        train_dataset=<span class="hljs-literal">None</span>,
        eval_dataset=eval_dataset,
        compute_metrics=my_compute_metrics,
        tokenizer=my_tokenizer,
        data_collator=my_data_collator,
    )

<span class="hljs-comment"># Run inference</span>
metrics = trainer.evaluate()`,wrap:!1}}),w=new P({props:{title:"In our Examples",local:"in-our-examples",headingTag:"h2"}}),U=new se({props:{code:"UFRfSFBVX0xBWllfTU9ERSUzRDElMjBweXRob24lMjBwYXRoX3RvX3RoZV9leGFtcGxlX3NjcmlwdCUyMCU1QyUwQSUyMCUyMC0tbW9kZWxfbmFtZV9vcl9wYXRoJTIwbXlfbW9kZWxfbmFtZSUyMCU1QyUwQSUyMCUyMC0tZ2F1ZGlfY29uZmlnX25hbWUlMjBteV9nYXVkaV9jb25maWdfbmFtZSUyMCU1QyUwQSUyMCUyMC0tZGF0YXNldF9uYW1lJTIwbXlfZGF0YXNldF9uYW1lJTIwJTVDJTBBJTIwJTIwLS1kb19ldmFsJTIwJTVDJTBBJTIwJTIwLS1wZXJfZGV2aWNlX2V2YWxfYmF0Y2hfc2l6ZSUyMG15X2JhdGNoX3NpemUlMjAlNUMlMEElMjAlMjAtLW91dHB1dF9kaXIlMjBwYXRoX3RvX215X291dHB1dF9kaXIlMjAlNUMlMEElMjAlMjAtLXVzZV9oYWJhbmElMjAlNUMlMEElMjAlMjAtLXVzZV9sYXp5X21vZGUlMjAlNUMlMEElMjAlMjAtLXVzZV9ocHVfZ3JhcGhzX2Zvcl9pbmZlcmVuY2U=",highlighted:`PT_HPU_LAZY_MODE=1 python path_to_the_example_script \\
  --model_name_or_path my_model_name \\
  --gaudi_config_name my_gaudi_config_name \\
  --dataset_name my_dataset_name \\
  --do_eval \\
  --per_device_eval_batch_size my_batch_size \\
  --output_dir path_to_my_output_dir \\
  --use_habana \\
  --use_lazy_mode \\
  --use_hpu_graphs_for_inference`,wrap:!1}}),b=new fe({props:{source:"https://github.com/huggingface/optimum-habana/blob/main/docs/source/tutorials/inference.mdx"}}),{c(){r=s("meta"),I=n(),C=s("p"),R=n(),T(o.$$.fragment),W=n(),T(M.$$.fragment),B=n(),p=s("p"),p.textContent=q,x=n(),c=s("p"),c.textContent=O,E=n(),d=s("p"),d.innerHTML=K,G=n(),u=s("p"),u.innerHTML=ee,Y=n(),T(f.$$.fragment),F=n(),h=s("p"),h.innerHTML=te,k=n(),T(y.$$.fragment),V=n(),j=s("p"),j.innerHTML=le,H=n(),T(w.$$.fragment),z=n(),_=s("p"),_.innerHTML=ae,S=n(),T(U.$$.fragment),N=n(),T(b.$$.fragment),Q=n(),A=s("p"),this.h()},l(e){const t=ce("svelte-u9bgzb",document.head);r=m(t,"META",{name:!0,content:!0}),t.forEach(l),I=i(e),C=m(e,"P",{}),ne(C).forEach(l),R=i(e),J(o.$$.fragment,e),W=i(e),J(M.$$.fragment,e),B=i(e),p=m(e,"P",{"data-svelte-h":!0}),X(p)!=="svelte-tyeqxn"&&(p.textContent=q),x=i(e),c=m(e,"P",{"data-svelte-h":!0}),X(c)!=="svelte-p7tpoo"&&(c.textContent=O),E=i(e),d=m(e,"P",{"data-svelte-h":!0}),X(d)!=="svelte-1nig2zu"&&(d.innerHTML=K),G=i(e),u=m(e,"P",{"data-svelte-h":!0}),X(u)!=="svelte-cyccam"&&(u.innerHTML=ee),Y=i(e),J(f.$$.fragment,e),F=i(e),h=m(e,"P",{"data-svelte-h":!0}),X(h)!=="svelte-zgqbh4"&&(h.innerHTML=te),k=i(e),J(y.$$.fragment,e),V=i(e),j=m(e,"P",{"data-svelte-h":!0}),X(j)!=="svelte-f3hkxy"&&(j.innerHTML=le),H=i(e),J(w.$$.fragment,e),z=i(e),_=m(e,"P",{"data-svelte-h":!0}),X(_)!=="svelte-qf1gje"&&(_.innerHTML=ae),S=i(e),J(U.$$.fragment,e),N=i(e),J(b.$$.fragment,e),Q=i(e),A=m(e,"P",{}),ne(A).forEach(l),this.h()},h(){ie(r,"name","hf:doc:metadata"),ie(r,"content",ye)},m(e,t){de(document.head,r),a(e,I,t),a(e,C,t),a(e,R,t),g(o,e,t),a(e,W,t),g(M,e,t),a(e,B,t),a(e,p,t),a(e,x,t),a(e,c,t),a(e,E,t),a(e,d,t),a(e,G,t),a(e,u,t),a(e,Y,t),g(f,e,t),a(e,F,t),a(e,h,t),a(e,k,t),g(y,e,t),a(e,V,t),a(e,j,t),a(e,H,t),g(w,e,t),a(e,z,t),a(e,_,t),a(e,S,t),g(U,e,t),a(e,N,t),g(b,e,t),a(e,Q,t),a(e,A,t),L=!0},p:re,i(e){L||(Z(o.$$.fragment,e),Z(M.$$.fragment,e),Z(f.$$.fragment,e),Z(y.$$.fragment,e),Z(w.$$.fragment,e),Z(U.$$.fragment,e),Z(b.$$.fragment,e),L=!0)},o(e){v(o.$$.fragment,e),v(M.$$.fragment,e),v(f.$$.fragment,e),v(y.$$.fragment,e),v(w.$$.fragment,e),v(U.$$.fragment,e),v(b.$$.fragment,e),L=!1},d(e){e&&(l(I),l(C),l(R),l(W),l(B),l(p),l(x),l(c),l(E),l(d),l(G),l(u),l(Y),l(F),l(h),l(k),l(V),l(j),l(H),l(z),l(_),l(S),l(N),l(Q),l(A)),l(r),$(o,e),$(M,e),$(f,e),$(y,e),$(w,e),$(U,e),$(b,e)}}}const ye='{"title":"Run Inference","local":"run-inference","sections":[{"title":"With GaudiTrainer","local":"with-gauditrainer","sections":[],"depth":2},{"title":"In our Examples","local":"in-our-examples","sections":[],"depth":2}],"depth":1}';function je(D){return oe(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Te extends Me{constructor(r){super(),pe(this,r,je,he,me,{})}}export{Te as component};
