import{s as Le,n as ke,o as Ae}from"../chunks/scheduler.25b97de1.js";import{S as Je,i as ze,g as r,s as l,r as c,A as Re,h as s,f as n,c as a,j as Ee,u,x as o,k as He,y as Be,a as i,v as f,d,t as m,w as h}from"../chunks/index.d9030fc9.js";import{C as Xe}from"../chunks/CodeBlock.e6cd0d95.js";import{H as V,E as je}from"../chunks/EditOnGithub.91d95064.js";function Ve(me){let p,G,B,S,g,Y,x,he="This guide focuses on training large models efficiently on CPU.",W,_,q,$,ge="Mixed precision uses single (fp32) and half-precision (bf16/fp16) data types in a model to accelerate training or inference while still preserving much of the single-precision accuracy. Modern CPUs such as 3rd and 4th Gen Intel® Xeon® Scalable processors natively support bf16, so you should get more performance out of the box by enabling mixed precision training with bf16.",F,b,xe="To further maximize training performance, you can use Intel® Extension for PyTorch (IPEX), which is a library built on PyTorch and adds additional CPU instruction level architecture (ISA) level support such as Intel® Advanced Vector Extensions 512 Vector Neural Network Instructions (Intel® AVX512-VNNI), and Intel® Advanced Matrix Extensions (Intel® AMX) for an extra performance boost on Intel CPUs. However, CPUs with only AVX2 (e.g., AMD or older Intel CPUs) are not guaranteed to have better performance under IPEX.",N,M,_e="Auto Mixed Precision (AMP) for CPU backends has been enabled since PyTorch 1.10. AMP support for bf16 on CPUs and bf16 operator optimization is also supported in IPEX and partially upstreamed to the main PyTorch branch. You can get better performance and user experience with IPEX AMP.",Z,T,$e='Check more detailed information for <a href="https://intel.github.io/intel-extension-for-pytorch/cpu/latest/tutorials/features/amp.html" rel="nofollow">Auto Mixed Precision</a>.',Q,C,D,P,be="IPEX release is following PyTorch, to install via pip:",K,w,Me='<thead><tr><th align="center">PyTorch Version</th> <th align="center">IPEX version</th></tr></thead> <tbody><tr><td align="center">2.1.x</td> <td align="center">2.1.100+cpu</td></tr> <tr><td align="center">2.0.x</td> <td align="center">2.0.100+cpu</td></tr> <tr><td align="center">1.13</td> <td align="center">1.13.0+cpu</td></tr> <tr><td align="center">1.12</td> <td align="center">1.12.300+cpu</td></tr></tbody>',O,v,Te="Please run <code>pip list | grep torch</code> to get your <code>pytorch_version</code>, so you can get the <code>IPEX version_name</code>.",ee,y,te,U,Ce='You can check the latest versions in <a href="https://developer.intel.com/ipex-whl-stable-cpu" rel="nofollow">ipex-whl-stable-cpu</a> if needed.',ne,I,Pe='Check more approaches for <a href="https://intel.github.io/intel-extension-for-pytorch/cpu/latest/tutorials/installation.html" rel="nofollow">IPEX installation</a>.',ie,E,le,H,we="To enable auto mixed precision with IPEX in Trainer, users should add <code>use_ipex</code>, <code>bf16</code> and <code>no_cuda</code> in training command arguments.",ae,X,ve='Take an example of the use cases on <a href="https://github.com/huggingface/transformers/tree/main/examples/pytorch/question-answering" rel="nofollow">Transformers question-answering</a>',re,L,ye=`<li>Training with IPEX using BF16 auto mixed precision on CPU:<pre> python run_qa.py \\
--model_name_or_path google-bert/bert-base-uncased \\
--dataset_name squad \\
--do_train \\
--do_eval \\
--per_device_train_batch_size 12 \\
--learning_rate 3e-5 \\
--num_train_epochs 2 \\
--max_seq_length 384 \\
--doc_stride 128 \\
--output_dir /tmp/debug_squad/ \\
<b>--use_ipex</b> \\
<b>--bf16</b> \\
<b>--use_cpu</b></pre></li>`,se,k,Ue="If you want to enable <code>use_ipex</code> and <code>bf16</code> in your script, add these parameters to <code>TrainingArguments</code> like this:",oe,A,pe,J,ce,z,Ie='Blog: <a href="https://huggingface.co/blog/intel-sapphire-rapids" rel="nofollow">Accelerating PyTorch Transformers with Intel Sapphire Rapids</a>',ue,R,fe,j,de;return g=new V({props:{title:"Efficient Training on CPU",local:"efficient-training-on-cpu",headingTag:"h1"}}),_=new V({props:{title:"Mixed precision with IPEX",local:"mixed-precision-with-ipex",headingTag:"h2"}}),C=new V({props:{title:"IPEX installation:",local:"ipex-installation",headingTag:"h3"}}),y=new Xe({props:{code:"cGlwJTIwaW5zdGFsbCUyMGludGVsX2V4dGVuc2lvbl9mb3JfcHl0b3JjaCUzRCUzRCUzQ3ZlcnNpb25fbmFtZSUzRSUyMC1mJTIwaHR0cHMlM0ElMkYlMkZkZXZlbG9wZXIuaW50ZWwuY29tJTJGaXBleC13aGwtc3RhYmxlLWNwdQ==",highlighted:"pip install intel_extension_for_pytorch==&lt;version_name&gt; -f https://developer.intel.com/ipex-whl-stable-cpu",wrap:!1}}),E=new V({props:{title:"Usage in Trainer",local:"usage-in-trainer",headingTag:"h3"}}),A=new Xe({props:{code:"dHJhaW5pbmdfYXJncyUyMCUzRCUyMFRyYWluaW5nQXJndW1lbnRzKCUwQSUyMCUyMCUyMCUyMG91dHB1dF9kaXIlM0RhcmdzLm91dHB1dF9wYXRoJTJDJTBBJTJCJTIwJTIwJTIwYmYxNiUzRFRydWUlMkMlMEElMkIlMjAlMjAlMjB1c2VfaXBleCUzRFRydWUlMkMlMEElMkIlMjAlMjAlMjB1c2VfY3B1JTNEVHJ1ZSUyQyUwQSUyMCUyMCUyMCUyMCoqa3dhcmdzJTBBKQ==",highlighted:`training_args = TrainingArguments(
    output_dir=args.output_path,
<span class="hljs-addition">+   bf16=True,</span>
<span class="hljs-addition">+   use_ipex=True,</span>
<span class="hljs-addition">+   use_cpu=True,</span>
    **kwargs
)`,wrap:!1}}),J=new V({props:{title:"Practice example",local:"practice-example",headingTag:"h3"}}),R=new je({props:{source:"https://github.com/huggingface/transformers/blob/main/docs/source/en/perf_train_cpu.md"}}),{c(){p=r("meta"),G=l(),B=r("p"),S=l(),c(g.$$.fragment),Y=l(),x=r("p"),x.textContent=he,W=l(),c(_.$$.fragment),q=l(),$=r("p"),$.textContent=ge,F=l(),b=r("p"),b.textContent=xe,N=l(),M=r("p"),M.textContent=_e,Z=l(),T=r("p"),T.innerHTML=$e,Q=l(),c(C.$$.fragment),D=l(),P=r("p"),P.textContent=be,K=l(),w=r("table"),w.innerHTML=Me,O=l(),v=r("p"),v.innerHTML=Te,ee=l(),c(y.$$.fragment),te=l(),U=r("p"),U.innerHTML=Ce,ne=l(),I=r("p"),I.innerHTML=Pe,ie=l(),c(E.$$.fragment),le=l(),H=r("p"),H.innerHTML=we,ae=l(),X=r("p"),X.innerHTML=ve,re=l(),L=r("ul"),L.innerHTML=ye,se=l(),k=r("p"),k.innerHTML=Ue,oe=l(),c(A.$$.fragment),pe=l(),c(J.$$.fragment),ce=l(),z=r("p"),z.innerHTML=Ie,ue=l(),c(R.$$.fragment),fe=l(),j=r("p"),this.h()},l(e){const t=Re("svelte-u9bgzb",document.head);p=s(t,"META",{name:!0,content:!0}),t.forEach(n),G=a(e),B=s(e,"P",{}),Ee(B).forEach(n),S=a(e),u(g.$$.fragment,e),Y=a(e),x=s(e,"P",{"data-svelte-h":!0}),o(x)!=="svelte-16zn87f"&&(x.textContent=he),W=a(e),u(_.$$.fragment,e),q=a(e),$=s(e,"P",{"data-svelte-h":!0}),o($)!=="svelte-1t5d7gz"&&($.textContent=ge),F=a(e),b=s(e,"P",{"data-svelte-h":!0}),o(b)!=="svelte-7ixgfk"&&(b.textContent=xe),N=a(e),M=s(e,"P",{"data-svelte-h":!0}),o(M)!=="svelte-1aa4rsn"&&(M.textContent=_e),Z=a(e),T=s(e,"P",{"data-svelte-h":!0}),o(T)!=="svelte-1orckb5"&&(T.innerHTML=$e),Q=a(e),u(C.$$.fragment,e),D=a(e),P=s(e,"P",{"data-svelte-h":!0}),o(P)!=="svelte-yt7jgu"&&(P.textContent=be),K=a(e),w=s(e,"TABLE",{"data-svelte-h":!0}),o(w)!=="svelte-63v1d5"&&(w.innerHTML=Me),O=a(e),v=s(e,"P",{"data-svelte-h":!0}),o(v)!=="svelte-op7gjt"&&(v.innerHTML=Te),ee=a(e),u(y.$$.fragment,e),te=a(e),U=s(e,"P",{"data-svelte-h":!0}),o(U)!=="svelte-6sdt3v"&&(U.innerHTML=Ce),ne=a(e),I=s(e,"P",{"data-svelte-h":!0}),o(I)!=="svelte-6x6sx"&&(I.innerHTML=Pe),ie=a(e),u(E.$$.fragment,e),le=a(e),H=s(e,"P",{"data-svelte-h":!0}),o(H)!=="svelte-550t3u"&&(H.innerHTML=we),ae=a(e),X=s(e,"P",{"data-svelte-h":!0}),o(X)!=="svelte-1t7mun5"&&(X.innerHTML=ve),re=a(e),L=s(e,"UL",{"data-svelte-h":!0}),o(L)!=="svelte-1p4s7xp"&&(L.innerHTML=ye),se=a(e),k=s(e,"P",{"data-svelte-h":!0}),o(k)!=="svelte-w7vrf2"&&(k.innerHTML=Ue),oe=a(e),u(A.$$.fragment,e),pe=a(e),u(J.$$.fragment,e),ce=a(e),z=s(e,"P",{"data-svelte-h":!0}),o(z)!=="svelte-w7zs5j"&&(z.innerHTML=Ie),ue=a(e),u(R.$$.fragment,e),fe=a(e),j=s(e,"P",{}),Ee(j).forEach(n),this.h()},h(){He(p,"name","hf:doc:metadata"),He(p,"content",Ge)},m(e,t){Be(document.head,p),i(e,G,t),i(e,B,t),i(e,S,t),f(g,e,t),i(e,Y,t),i(e,x,t),i(e,W,t),f(_,e,t),i(e,q,t),i(e,$,t),i(e,F,t),i(e,b,t),i(e,N,t),i(e,M,t),i(e,Z,t),i(e,T,t),i(e,Q,t),f(C,e,t),i(e,D,t),i(e,P,t),i(e,K,t),i(e,w,t),i(e,O,t),i(e,v,t),i(e,ee,t),f(y,e,t),i(e,te,t),i(e,U,t),i(e,ne,t),i(e,I,t),i(e,ie,t),f(E,e,t),i(e,le,t),i(e,H,t),i(e,ae,t),i(e,X,t),i(e,re,t),i(e,L,t),i(e,se,t),i(e,k,t),i(e,oe,t),f(A,e,t),i(e,pe,t),f(J,e,t),i(e,ce,t),i(e,z,t),i(e,ue,t),f(R,e,t),i(e,fe,t),i(e,j,t),de=!0},p:ke,i(e){de||(d(g.$$.fragment,e),d(_.$$.fragment,e),d(C.$$.fragment,e),d(y.$$.fragment,e),d(E.$$.fragment,e),d(A.$$.fragment,e),d(J.$$.fragment,e),d(R.$$.fragment,e),de=!0)},o(e){m(g.$$.fragment,e),m(_.$$.fragment,e),m(C.$$.fragment,e),m(y.$$.fragment,e),m(E.$$.fragment,e),m(A.$$.fragment,e),m(J.$$.fragment,e),m(R.$$.fragment,e),de=!1},d(e){e&&(n(G),n(B),n(S),n(Y),n(x),n(W),n(q),n($),n(F),n(b),n(N),n(M),n(Z),n(T),n(Q),n(D),n(P),n(K),n(w),n(O),n(v),n(ee),n(te),n(U),n(ne),n(I),n(ie),n(le),n(H),n(ae),n(X),n(re),n(L),n(se),n(k),n(oe),n(pe),n(ce),n(z),n(ue),n(fe),n(j)),n(p),h(g,e),h(_,e),h(C,e),h(y,e),h(E,e),h(A,e),h(J,e),h(R,e)}}}const Ge='{"title":"Efficient Training on CPU","local":"efficient-training-on-cpu","sections":[{"title":"Mixed precision with IPEX","local":"mixed-precision-with-ipex","sections":[{"title":"IPEX installation:","local":"ipex-installation","sections":[],"depth":3},{"title":"Usage in Trainer","local":"usage-in-trainer","sections":[],"depth":3},{"title":"Practice example","local":"practice-example","sections":[],"depth":3}],"depth":2}],"depth":1}';function Se(me){return Ae(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Ne extends Je{constructor(p){super(),ze(this,p,Se,Ve,Le,{})}}export{Ne as component};
