import{S as Nr,i as Dr,s as Gr,e as a,k as c,w as pe,t as s,M as Hr,c as n,d as r,m as f,a as o,x as he,h as p,b as i,G as t,g as h,y as ce,L as Lr,q as fe,o as ue,B as de,v as Jr}from"../chunks/vendor-hf-doc-builder.js";import{I as Xe}from"../chunks/IconCopyLink-hf-doc-builder.js";import{C as Zr}from"../chunks/CodeBlock-hf-doc-builder.js";function Wr(ar){let d,Ce,m,E,me,C,it,_e,lt,Ue,Z,st,ke,_,b,ve,U,pt,Pe,ht,Me,W,ct,Se,Y,ft,Be,g,ut,k,dt,mt,Fe,v,x,we,M,_t,Ee,vt,Ve,j,Pt,qe,y,be,S,O,wt,Et,Q,bt,gt,u,B,K,xt,yt,ee,Tt,At,F,te,$t,It,re,Xt,Ct,V,ae,Ut,kt,ne,Mt,St,q,oe,Bt,Ft,ie,Vt,Re,R,ze,T,qt,z,Rt,zt,Ne,P,A,ge,N,Nt,xe,Dt,De,D,Gt,G,Ht,Ge,le,se,Lt,$,Jt,ye,Zt,Wt,Te,Yt,He,w,I,Ae,H,jt,$e,Ot,Le,L,Qt,J,Kt,Je;return C=new Xe({}),U=new Xe({}),M=new Xe({}),R=new Zr({props:{code:"cGlwJTIwaW5zdGFsbCUyMGludGVsX2V4dGVuc2lvbl9mb3JfcHl0b3JjaCUzRCUzRCUzQ3ZlcnNpb25fbmFtZSUzRSUyMC1mJTIwaHR0cHMlM0ElMkYlMkZkZXZlbG9wZXIuaW50ZWwuY29tJTJGaXBleC13aGwtc3RhYmxlLWNwdQ==",highlighted:'pip install <span class="hljs-built_in">int</span>el_extension_for_pytorch==&lt;version_name&gt; -f https:<span class="hljs-comment">//developer.intel.com/ipex-whl-stable-cpu</span>'}}),N=new Xe({}),H=new Xe({}),{c(){d=a("meta"),Ce=c(),m=a("h1"),E=a("a"),me=a("span"),pe(C.$$.fragment),it=c(),_e=a("span"),lt=s("Efficient Training on CPU"),Ue=c(),Z=a("p"),st=s("This guide focuses on training large models efficiently on CPU."),ke=c(),_=a("h2"),b=a("a"),ve=a("span"),pe(U.$$.fragment),pt=c(),Pe=a("span"),ht=s("Mixed precision with IPEX"),Me=c(),W=a("p"),ct=s("IPEX is optimized for CPUs with AVX-512 or above, and functionally works for CPUs with only AVX2. So, it is expected to bring performance benefit for Intel CPU generations with AVX-512 or above while CPUs with only AVX2 (e.g., AMD CPUs or older Intel CPUs) might result in a better performance under IPEX, but not guaranteed. IPEX provides performance optimizations for CPU training with both Float32 and BFloat16. The usage of BFloat16 is the main focus of the following sections."),Se=c(),Y=a("p"),ft=s("Low precision data type BFloat16 has been natively supported on the 3rd Generation Xeon\xAE Scalable Processors (aka Cooper Lake) with AVX512 instruction set and will be supported on the next generation of Intel\xAE Xeon\xAE Scalable Processors with Intel\xAE Advanced Matrix Extensions (Intel\xAE AMX) instruction set with further boosted performance. The Auto Mixed Precision for CPU backend has been enabled since PyTorch-1.10. At the same time, the support of Auto Mixed Precision with BFloat16 for CPU and BFloat16 optimization of operators has been massively enabled in Intel\xAE Extension for PyTorch, and partially upstreamed to PyTorch master branch. Users can get better performance and user experience with IPEX Auto Mixed Precision."),Be=c(),g=a("p"),ut=s("Check more detailed information for "),k=a("a"),dt=s("Auto Mixed Precision"),mt=s("."),Fe=c(),v=a("h3"),x=a("a"),we=a("span"),pe(M.$$.fragment),_t=c(),Ee=a("span"),vt=s("IPEX installation:"),Ve=c(),j=a("p"),Pt=s("IPEX release is following PyTorch, to install via pip:"),qe=c(),y=a("table"),be=a("thead"),S=a("tr"),O=a("th"),wt=s("PyTorch Version"),Et=c(),Q=a("th"),bt=s("IPEX version"),gt=c(),u=a("tbody"),B=a("tr"),K=a("td"),xt=s("1.13"),yt=c(),ee=a("td"),Tt=s("1.13.0+cpu"),At=c(),F=a("tr"),te=a("td"),$t=s("1.12"),It=c(),re=a("td"),Xt=s("1.12.300+cpu"),Ct=c(),V=a("tr"),ae=a("td"),Ut=s("1.11"),kt=c(),ne=a("td"),Mt=s("1.11.200+cpu"),St=c(),q=a("tr"),oe=a("td"),Bt=s("1.10"),Ft=c(),ie=a("td"),Vt=s("1.10.100+cpu"),Re=c(),pe(R.$$.fragment),ze=c(),T=a("p"),qt=s("Check more approaches for "),z=a("a"),Rt=s("IPEX installation"),zt=s("."),Ne=c(),P=a("h3"),A=a("a"),ge=a("span"),pe(N.$$.fragment),Nt=c(),xe=a("span"),Dt=s("Usage in Trainer"),De=s("\n\nTo enable auto mixed precision with IPEX in Trainer, users should add `use_ipex`, `bf16` and `no_cuda` in training command arguments.\n"),D=a("p"),Gt=s("Take an example of the use cases on "),G=a("a"),Ht=s("Transformers question-answering"),Ge=c(),le=a("ul"),se=a("li"),Lt=s("Training with IPEX using BF16 auto mixed precision on CPU:"),$=a("pre"),Jt=s(` python run_qa.py \\
--model_name_or_path 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/ \\
`),ye=a("b"),Zt=s("--use_ipex \\"),Wt=s(`
`),Te=a("b"),Yt=s("--bf16 --no_cuda"),He=c(),w=a("h3"),I=a("a"),Ae=a("span"),pe(H.$$.fragment),jt=c(),$e=a("span"),Ot=s("Practice example"),Le=c(),L=a("p"),Qt=s("Blog: "),J=a("a"),Kt=s("Accelerating PyTorch Transformers with Intel Sapphire Rapids"),this.h()},l(e){const l=Hr('[data-svelte="svelte-1phssyn"]',document.head);d=n(l,"META",{name:!0,content:!0}),l.forEach(r),Ce=f(e),m=n(e,"H1",{class:!0});var Ze=o(m);E=n(Ze,"A",{id:!0,class:!0,href:!0});var nr=o(E);me=n(nr,"SPAN",{});var or=o(me);he(C.$$.fragment,or),or.forEach(r),nr.forEach(r),it=f(Ze),_e=n(Ze,"SPAN",{});var ir=o(_e);lt=p(ir,"Efficient Training on CPU"),ir.forEach(r),Ze.forEach(r),Ue=f(e),Z=n(e,"P",{});var lr=o(Z);st=p(lr,"This guide focuses on training large models efficiently on CPU."),lr.forEach(r),ke=f(e),_=n(e,"H2",{class:!0});var We=o(_);b=n(We,"A",{id:!0,class:!0,href:!0});var sr=o(b);ve=n(sr,"SPAN",{});var pr=o(ve);he(U.$$.fragment,pr),pr.forEach(r),sr.forEach(r),pt=f(We),Pe=n(We,"SPAN",{});var hr=o(Pe);ht=p(hr,"Mixed precision with IPEX"),hr.forEach(r),We.forEach(r),Me=f(e),W=n(e,"P",{});var cr=o(W);ct=p(cr,"IPEX is optimized for CPUs with AVX-512 or above, and functionally works for CPUs with only AVX2. So, it is expected to bring performance benefit for Intel CPU generations with AVX-512 or above while CPUs with only AVX2 (e.g., AMD CPUs or older Intel CPUs) might result in a better performance under IPEX, but not guaranteed. IPEX provides performance optimizations for CPU training with both Float32 and BFloat16. The usage of BFloat16 is the main focus of the following sections."),cr.forEach(r),Se=f(e),Y=n(e,"P",{});var fr=o(Y);ft=p(fr,"Low precision data type BFloat16 has been natively supported on the 3rd Generation Xeon\xAE Scalable Processors (aka Cooper Lake) with AVX512 instruction set and will be supported on the next generation of Intel\xAE Xeon\xAE Scalable Processors with Intel\xAE Advanced Matrix Extensions (Intel\xAE AMX) instruction set with further boosted performance. The Auto Mixed Precision for CPU backend has been enabled since PyTorch-1.10. At the same time, the support of Auto Mixed Precision with BFloat16 for CPU and BFloat16 optimization of operators has been massively enabled in Intel\xAE Extension for PyTorch, and partially upstreamed to PyTorch master branch. Users can get better performance and user experience with IPEX Auto Mixed Precision."),fr.forEach(r),Be=f(e),g=n(e,"P",{});var Ye=o(g);ut=p(Ye,"Check more detailed information for "),k=n(Ye,"A",{href:!0,rel:!0});var ur=o(k);dt=p(ur,"Auto Mixed Precision"),ur.forEach(r),mt=p(Ye,"."),Ye.forEach(r),Fe=f(e),v=n(e,"H3",{class:!0});var je=o(v);x=n(je,"A",{id:!0,class:!0,href:!0});var dr=o(x);we=n(dr,"SPAN",{});var mr=o(we);he(M.$$.fragment,mr),mr.forEach(r),dr.forEach(r),_t=f(je),Ee=n(je,"SPAN",{});var _r=o(Ee);vt=p(_r,"IPEX installation:"),_r.forEach(r),je.forEach(r),Ve=f(e),j=n(e,"P",{});var vr=o(j);Pt=p(vr,"IPEX release is following PyTorch, to install via pip:"),vr.forEach(r),qe=f(e),y=n(e,"TABLE",{});var Oe=o(y);be=n(Oe,"THEAD",{});var Pr=o(be);S=n(Pr,"TR",{});var Qe=o(S);O=n(Qe,"TH",{align:!0});var wr=o(O);wt=p(wr,"PyTorch Version"),wr.forEach(r),Et=f(Qe),Q=n(Qe,"TH",{align:!0});var Er=o(Q);bt=p(Er,"IPEX version"),Er.forEach(r),Qe.forEach(r),Pr.forEach(r),gt=f(Oe),u=n(Oe,"TBODY",{});var X=o(u);B=n(X,"TR",{});var Ke=o(B);K=n(Ke,"TD",{align:!0});var br=o(K);xt=p(br,"1.13"),br.forEach(r),yt=f(Ke),ee=n(Ke,"TD",{align:!0});var gr=o(ee);Tt=p(gr,"1.13.0+cpu"),gr.forEach(r),Ke.forEach(r),At=f(X),F=n(X,"TR",{});var et=o(F);te=n(et,"TD",{align:!0});var xr=o(te);$t=p(xr,"1.12"),xr.forEach(r),It=f(et),re=n(et,"TD",{align:!0});var yr=o(re);Xt=p(yr,"1.12.300+cpu"),yr.forEach(r),et.forEach(r),Ct=f(X),V=n(X,"TR",{});var tt=o(V);ae=n(tt,"TD",{align:!0});var Tr=o(ae);Ut=p(Tr,"1.11"),Tr.forEach(r),kt=f(tt),ne=n(tt,"TD",{align:!0});var Ar=o(ne);Mt=p(Ar,"1.11.200+cpu"),Ar.forEach(r),tt.forEach(r),St=f(X),q=n(X,"TR",{});var rt=o(q);oe=n(rt,"TD",{align:!0});var $r=o(oe);Bt=p($r,"1.10"),$r.forEach(r),Ft=f(rt),ie=n(rt,"TD",{align:!0});var Ir=o(ie);Vt=p(Ir,"1.10.100+cpu"),Ir.forEach(r),rt.forEach(r),X.forEach(r),Oe.forEach(r),Re=f(e),he(R.$$.fragment,e),ze=f(e),T=n(e,"P",{});var at=o(T);qt=p(at,"Check more approaches for "),z=n(at,"A",{href:!0,rel:!0});var Xr=o(z);Rt=p(Xr,"IPEX installation"),Xr.forEach(r),zt=p(at,"."),at.forEach(r),Ne=f(e),P=n(e,"H3",{class:!0});var nt=o(P);A=n(nt,"A",{id:!0,class:!0,href:!0});var Cr=o(A);ge=n(Cr,"SPAN",{});var Ur=o(ge);he(N.$$.fragment,Ur),Ur.forEach(r),Cr.forEach(r),Nt=f(nt),xe=n(nt,"SPAN",{});var kr=o(xe);Dt=p(kr,"Usage in Trainer"),kr.forEach(r),nt.forEach(r),De=p(e,"\n\nTo enable auto mixed precision with IPEX in Trainer, users should add `use_ipex`, `bf16` and `no_cuda` in training command arguments.\n"),D=n(e,"P",{});var er=o(D);Gt=p(er,"Take an example of the use cases on "),G=n(er,"A",{href:!0,rel:!0});var Mr=o(G);Ht=p(Mr,"Transformers question-answering"),Mr.forEach(r),er.forEach(r),Ge=f(e),le=n(e,"UL",{});var Sr=o(le);se=n(Sr,"LI",{});var tr=o(se);Lt=p(tr,"Training with IPEX using BF16 auto mixed precision on CPU:"),$=n(tr,"PRE",{});var Ie=o($);Jt=p(Ie,` python run_qa.py \\
--model_name_or_path 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/ \\
`),ye=n(Ie,"B",{});var Br=o(ye);Zt=p(Br,"--use_ipex \\"),Br.forEach(r),Wt=p(Ie,`
`),Te=n(Ie,"B",{});var Fr=o(Te);Yt=p(Fr,"--bf16 --no_cuda"),Fr.forEach(r),Ie.forEach(r),tr.forEach(r),Sr.forEach(r),He=f(e),w=n(e,"H3",{class:!0});var ot=o(w);I=n(ot,"A",{id:!0,class:!0,href:!0});var Vr=o(I);Ae=n(Vr,"SPAN",{});var qr=o(Ae);he(H.$$.fragment,qr),qr.forEach(r),Vr.forEach(r),jt=f(ot),$e=n(ot,"SPAN",{});var Rr=o($e);Ot=p(Rr,"Practice example"),Rr.forEach(r),ot.forEach(r),Le=f(e),L=n(e,"P",{});var rr=o(L);Qt=p(rr,"Blog: "),J=n(rr,"A",{href:!0,rel:!0});var zr=o(J);Kt=p(zr,"Accelerating PyTorch Transformers with Intel Sapphire Rapids"),zr.forEach(r),rr.forEach(r),this.h()},h(){i(d,"name","hf:doc:metadata"),i(d,"content",JSON.stringify(Yr)),i(E,"id","efficient-training-on-cpu"),i(E,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),i(E,"href","#efficient-training-on-cpu"),i(m,"class","relative group"),i(b,"id","mixed-precision-with-ipex"),i(b,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),i(b,"href","#mixed-precision-with-ipex"),i(_,"class","relative group"),i(k,"href","https://intel.github.io/intel-extension-for-pytorch/cpu/latest/tutorials/features/amp.html"),i(k,"rel","nofollow"),i(x,"id","ipex-installation"),i(x,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),i(x,"href","#ipex-installation"),i(v,"class","relative group"),i(O,"align","center"),i(Q,"align","center"),i(K,"align","center"),i(ee,"align","center"),i(te,"align","center"),i(re,"align","center"),i(ae,"align","center"),i(ne,"align","center"),i(oe,"align","center"),i(ie,"align","center"),i(z,"href","https://intel.github.io/intel-extension-for-pytorch/cpu/latest/tutorials/installation.html"),i(z,"rel","nofollow"),i(A,"id","usage-in-trainer"),i(A,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),i(A,"href","#usage-in-trainer"),i(P,"class","relative group"),i(G,"href","https://github.com/huggingface/transformers/tree/main/examples/pytorch/question-answering"),i(G,"rel","nofollow"),i(I,"id","practice-example"),i(I,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),i(I,"href","#practice-example"),i(w,"class","relative group"),i(J,"href","https://huggingface.co/blog/intel-sapphire-rapids"),i(J,"rel","nofollow")},m(e,l){t(document.head,d),h(e,Ce,l),h(e,m,l),t(m,E),t(E,me),ce(C,me,null),t(m,it),t(m,_e),t(_e,lt),h(e,Ue,l),h(e,Z,l),t(Z,st),h(e,ke,l),h(e,_,l),t(_,b),t(b,ve),ce(U,ve,null),t(_,pt),t(_,Pe),t(Pe,ht),h(e,Me,l),h(e,W,l),t(W,ct),h(e,Se,l),h(e,Y,l),t(Y,ft),h(e,Be,l),h(e,g,l),t(g,ut),t(g,k),t(k,dt),t(g,mt),h(e,Fe,l),h(e,v,l),t(v,x),t(x,we),ce(M,we,null),t(v,_t),t(v,Ee),t(Ee,vt),h(e,Ve,l),h(e,j,l),t(j,Pt),h(e,qe,l),h(e,y,l),t(y,be),t(be,S),t(S,O),t(O,wt),t(S,Et),t(S,Q),t(Q,bt),t(y,gt),t(y,u),t(u,B),t(B,K),t(K,xt),t(B,yt),t(B,ee),t(ee,Tt),t(u,At),t(u,F),t(F,te),t(te,$t),t(F,It),t(F,re),t(re,Xt),t(u,Ct),t(u,V),t(V,ae),t(ae,Ut),t(V,kt),t(V,ne),t(ne,Mt),t(u,St),t(u,q),t(q,oe),t(oe,Bt),t(q,Ft),t(q,ie),t(ie,Vt),h(e,Re,l),ce(R,e,l),h(e,ze,l),h(e,T,l),t(T,qt),t(T,z),t(z,Rt),t(T,zt),h(e,Ne,l),h(e,P,l),t(P,A),t(A,ge),ce(N,ge,null),t(P,Nt),t(P,xe),t(xe,Dt),h(e,De,l),h(e,D,l),t(D,Gt),t(D,G),t(G,Ht),h(e,Ge,l),h(e,le,l),t(le,se),t(se,Lt),t(se,$),t($,Jt),t($,ye),t(ye,Zt),t($,Wt),t($,Te),t(Te,Yt),h(e,He,l),h(e,w,l),t(w,I),t(I,Ae),ce(H,Ae,null),t(w,jt),t(w,$e),t($e,Ot),h(e,Le,l),h(e,L,l),t(L,Qt),t(L,J),t(J,Kt),Je=!0},p:Lr,i(e){Je||(fe(C.$$.fragment,e),fe(U.$$.fragment,e),fe(M.$$.fragment,e),fe(R.$$.fragment,e),fe(N.$$.fragment,e),fe(H.$$.fragment,e),Je=!0)},o(e){ue(C.$$.fragment,e),ue(U.$$.fragment,e),ue(M.$$.fragment,e),ue(R.$$.fragment,e),ue(N.$$.fragment,e),ue(H.$$.fragment,e),Je=!1},d(e){r(d),e&&r(Ce),e&&r(m),de(C),e&&r(Ue),e&&r(Z),e&&r(ke),e&&r(_),de(U),e&&r(Me),e&&r(W),e&&r(Se),e&&r(Y),e&&r(Be),e&&r(g),e&&r(Fe),e&&r(v),de(M),e&&r(Ve),e&&r(j),e&&r(qe),e&&r(y),e&&r(Re),de(R,e),e&&r(ze),e&&r(T),e&&r(Ne),e&&r(P),de(N),e&&r(De),e&&r(D),e&&r(Ge),e&&r(le),e&&r(He),e&&r(w),de(H),e&&r(Le),e&&r(L)}}}const Yr={local:"efficient-training-on-cpu",sections:[{local:"mixed-precision-with-ipex",sections:[{local:"ipex-installation",title:"IPEX installation:"},{local:"usage-in-trainer",title:"Usage in Trainer"},{local:"practice-example",title:"Practice example"}],title:"Mixed precision with IPEX"}],title:"Efficient Training on CPU"};function jr(ar){return Jr(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class ea extends Nr{constructor(d){super();Dr(this,d,jr,Wr,Gr,{})}}export{ea as default,Yr as metadata};
