import{S as Lr,i as Rr,s as zr,e as a,k as f,w as pe,t as s,M as Hr,c as n,d as r,m as c,a as o,x as he,h as p,b as i,G as t,g as h,y as fe,L as Gr,q as ce,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 Or}from"../chunks/CodeBlock-hf-doc-builder.js";function Jr(ar){let d,Ce,m,w,me,C,it,_e,lt,ke,O,st,Ue,_,b,ve,k,pt,Pe,ht,Se,J,ft,Be,Y,ct,Me,g,ut,U,dt,mt,qe,v,x,Ee,S,_t,we,vt,Fe,K,Pt,De,y,be,B,Q,Et,wt,W,bt,gt,u,M,Z,xt,yt,ee,Tt,At,q,te,$t,It,re,Xt,Ct,F,ae,kt,Ut,ne,St,Bt,D,oe,Mt,qt,ie,Ft,Ve,V,Ne,T,Dt,N,Vt,Nt,Le,P,A,ge,L,Lt,xe,Rt,Re,R,zt,z,Ht,ze,le,se,Gt,$,jt,ye,Ot,Jt,Te,Yt,He,E,I,Ae,H,Kt,$e,Qt,Ge,G,Wt,j,Zt,je;return C=new Xe({}),k=new Xe({}),S=new Xe({}),V=new Or({props:{code:"pip install intel_extension_for_pytorch==<version_name> -f https://developer.intel.com/ipex-whl-stable-cpu",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>'}}),L=new Xe({}),H=new Xe({}),{c(){d=a("meta"),Ce=f(),m=a("h1"),w=a("a"),me=a("span"),pe(C.$$.fragment),it=f(),_e=a("span"),lt=s("Efficient Training on CPU"),ke=f(),O=a("p"),st=s("This guide focuses on training large models efficiently on CPU."),Ue=f(),_=a("h2"),b=a("a"),ve=a("span"),pe(k.$$.fragment),pt=f(),Pe=a("span"),ht=s("Mixed precision with IPEX"),Se=f(),J=a("p"),ft=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."),Be=f(),Y=a("p"),ct=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."),Me=f(),g=a("p"),ut=s("Check more detailed information for "),U=a("a"),dt=s("Auto Mixed Precision"),mt=s("."),qe=f(),v=a("h3"),x=a("a"),Ee=a("span"),pe(S.$$.fragment),_t=f(),we=a("span"),vt=s("IPEX installation:"),Fe=f(),K=a("p"),Pt=s("IPEX release is following PyTorch, to install via pip:"),De=f(),y=a("table"),be=a("thead"),B=a("tr"),Q=a("th"),Et=s("PyTorch Version"),wt=f(),W=a("th"),bt=s("IPEX version"),gt=f(),u=a("tbody"),M=a("tr"),Z=a("td"),xt=s("1.13"),yt=f(),ee=a("td"),Tt=s("1.13.0+cpu"),At=f(),q=a("tr"),te=a("td"),$t=s("1.12"),It=f(),re=a("td"),Xt=s("1.12.300+cpu"),Ct=f(),F=a("tr"),ae=a("td"),kt=s("1.11"),Ut=f(),ne=a("td"),St=s("1.11.200+cpu"),Bt=f(),D=a("tr"),oe=a("td"),Mt=s("1.10"),qt=f(),ie=a("td"),Ft=s("1.10.100+cpu"),Ve=f(),pe(V.$$.fragment),Ne=f(),T=a("p"),Dt=s("Check more approaches for "),N=a("a"),Vt=s("IPEX installation"),Nt=s("."),Le=f(),P=a("h3"),A=a("a"),ge=a("span"),pe(L.$$.fragment),Lt=f(),xe=a("span"),Rt=s("Usage in Trainer"),Re=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"),R=a("p"),zt=s("Take an example of the use cases on "),z=a("a"),Ht=s("Transformers question-answering"),ze=f(),le=a("ul"),se=a("li"),Gt=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"),Ot=s("--use_ipex \\"),Jt=s(`
`),Te=a("b"),Yt=s("--bf16 --no_cuda"),He=f(),E=a("h3"),I=a("a"),Ae=a("span"),pe(H.$$.fragment),Kt=f(),$e=a("span"),Qt=s("Practice example"),Ge=f(),G=a("p"),Wt=s("Blog: "),j=a("a"),Zt=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=c(e),m=n(e,"H1",{class:!0});var Oe=o(m);w=n(Oe,"A",{id:!0,class:!0,href:!0});var nr=o(w);me=n(nr,"SPAN",{});var or=o(me);he(C.$$.fragment,or),or.forEach(r),nr.forEach(r),it=c(Oe),_e=n(Oe,"SPAN",{});var ir=o(_e);lt=p(ir,"Efficient Training on CPU"),ir.forEach(r),Oe.forEach(r),ke=c(e),O=n(e,"P",{});var lr=o(O);st=p(lr,"This guide focuses on training large models efficiently on CPU."),lr.forEach(r),Ue=c(e),_=n(e,"H2",{class:!0});var Je=o(_);b=n(Je,"A",{id:!0,class:!0,href:!0});var sr=o(b);ve=n(sr,"SPAN",{});var pr=o(ve);he(k.$$.fragment,pr),pr.forEach(r),sr.forEach(r),pt=c(Je),Pe=n(Je,"SPAN",{});var hr=o(Pe);ht=p(hr,"Mixed precision with IPEX"),hr.forEach(r),Je.forEach(r),Se=c(e),J=n(e,"P",{});var fr=o(J);ft=p(fr,"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."),fr.forEach(r),Be=c(e),Y=n(e,"P",{});var cr=o(Y);ct=p(cr,"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."),cr.forEach(r),Me=c(e),g=n(e,"P",{});var Ye=o(g);ut=p(Ye,"Check more detailed information for "),U=n(Ye,"A",{href:!0,rel:!0});var ur=o(U);dt=p(ur,"Auto Mixed Precision"),ur.forEach(r),mt=p(Ye,"."),Ye.forEach(r),qe=c(e),v=n(e,"H3",{class:!0});var Ke=o(v);x=n(Ke,"A",{id:!0,class:!0,href:!0});var dr=o(x);Ee=n(dr,"SPAN",{});var mr=o(Ee);he(S.$$.fragment,mr),mr.forEach(r),dr.forEach(r),_t=c(Ke),we=n(Ke,"SPAN",{});var _r=o(we);vt=p(_r,"IPEX installation:"),_r.forEach(r),Ke.forEach(r),Fe=c(e),K=n(e,"P",{});var vr=o(K);Pt=p(vr,"IPEX release is following PyTorch, to install via pip:"),vr.forEach(r),De=c(e),y=n(e,"TABLE",{});var Qe=o(y);be=n(Qe,"THEAD",{});var Pr=o(be);B=n(Pr,"TR",{});var We=o(B);Q=n(We,"TH",{align:!0});var Er=o(Q);Et=p(Er,"PyTorch Version"),Er.forEach(r),wt=c(We),W=n(We,"TH",{align:!0});var wr=o(W);bt=p(wr,"IPEX version"),wr.forEach(r),We.forEach(r),Pr.forEach(r),gt=c(Qe),u=n(Qe,"TBODY",{});var X=o(u);M=n(X,"TR",{});var Ze=o(M);Z=n(Ze,"TD",{align:!0});var br=o(Z);xt=p(br,"1.13"),br.forEach(r),yt=c(Ze),ee=n(Ze,"TD",{align:!0});var gr=o(ee);Tt=p(gr,"1.13.0+cpu"),gr.forEach(r),Ze.forEach(r),At=c(X),q=n(X,"TR",{});var et=o(q);te=n(et,"TD",{align:!0});var xr=o(te);$t=p(xr,"1.12"),xr.forEach(r),It=c(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=c(X),F=n(X,"TR",{});var tt=o(F);ae=n(tt,"TD",{align:!0});var Tr=o(ae);kt=p(Tr,"1.11"),Tr.forEach(r),Ut=c(tt),ne=n(tt,"TD",{align:!0});var Ar=o(ne);St=p(Ar,"1.11.200+cpu"),Ar.forEach(r),tt.forEach(r),Bt=c(X),D=n(X,"TR",{});var rt=o(D);oe=n(rt,"TD",{align:!0});var $r=o(oe);Mt=p($r,"1.10"),$r.forEach(r),qt=c(rt),ie=n(rt,"TD",{align:!0});var Ir=o(ie);Ft=p(Ir,"1.10.100+cpu"),Ir.forEach(r),rt.forEach(r),X.forEach(r),Qe.forEach(r),Ve=c(e),he(V.$$.fragment,e),Ne=c(e),T=n(e,"P",{});var at=o(T);Dt=p(at,"Check more approaches for "),N=n(at,"A",{href:!0,rel:!0});var Xr=o(N);Vt=p(Xr,"IPEX installation"),Xr.forEach(r),Nt=p(at,"."),at.forEach(r),Le=c(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 kr=o(ge);he(L.$$.fragment,kr),kr.forEach(r),Cr.forEach(r),Lt=c(nt),xe=n(nt,"SPAN",{});var Ur=o(xe);Rt=p(Ur,"Usage in Trainer"),Ur.forEach(r),nt.forEach(r),Re=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"),R=n(e,"P",{});var er=o(R);zt=p(er,"Take an example of the use cases on "),z=n(er,"A",{href:!0,rel:!0});var Sr=o(z);Ht=p(Sr,"Transformers question-answering"),Sr.forEach(r),er.forEach(r),ze=c(e),le=n(e,"UL",{});var Br=o(le);se=n(Br,"LI",{});var tr=o(se);Gt=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 Mr=o(ye);Ot=p(Mr,"--use_ipex \\"),Mr.forEach(r),Jt=p(Ie,`
`),Te=n(Ie,"B",{});var qr=o(Te);Yt=p(qr,"--bf16 --no_cuda"),qr.forEach(r),Ie.forEach(r),tr.forEach(r),Br.forEach(r),He=c(e),E=n(e,"H3",{class:!0});var ot=o(E);I=n(ot,"A",{id:!0,class:!0,href:!0});var Fr=o(I);Ae=n(Fr,"SPAN",{});var Dr=o(Ae);he(H.$$.fragment,Dr),Dr.forEach(r),Fr.forEach(r),Kt=c(ot),$e=n(ot,"SPAN",{});var Vr=o($e);Qt=p(Vr,"Practice example"),Vr.forEach(r),ot.forEach(r),Ge=c(e),G=n(e,"P",{});var rr=o(G);Wt=p(rr,"Blog: "),j=n(rr,"A",{href:!0,rel:!0});var Nr=o(j);Zt=p(Nr,"Accelerating PyTorch Transformers with Intel Sapphire Rapids"),Nr.forEach(r),rr.forEach(r),this.h()},h(){i(d,"name","hf:doc:metadata"),i(d,"content",JSON.stringify(Yr)),i(w,"id","efficient-training-on-cpu"),i(w,"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(w,"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(U,"href","https://intel.github.io/intel-extension-for-pytorch/cpu/latest/tutorials/features/amp.html"),i(U,"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(Q,"align","center"),i(W,"align","center"),i(Z,"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(N,"href","https://intel.github.io/intel-extension-for-pytorch/cpu/latest/tutorials/installation.html"),i(N,"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(z,"href","https://github.com/huggingface/transformers/tree/main/examples/pytorch/question-answering"),i(z,"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(E,"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,w),t(w,me),fe(C,me,null),t(m,it),t(m,_e),t(_e,lt),h(e,ke,l),h(e,O,l),t(O,st),h(e,Ue,l),h(e,_,l),t(_,b),t(b,ve),fe(k,ve,null),t(_,pt),t(_,Pe),t(Pe,ht),h(e,Se,l),h(e,J,l),t(J,ft),h(e,Be,l),h(e,Y,l),t(Y,ct),h(e,Me,l),h(e,g,l),t(g,ut),t(g,U),t(U,dt),t(g,mt),h(e,qe,l),h(e,v,l),t(v,x),t(x,Ee),fe(S,Ee,null),t(v,_t),t(v,we),t(we,vt),h(e,Fe,l),h(e,K,l),t(K,Pt),h(e,De,l),h(e,y,l),t(y,be),t(be,B),t(B,Q),t(Q,Et),t(B,wt),t(B,W),t(W,bt),t(y,gt),t(y,u),t(u,M),t(M,Z),t(Z,xt),t(M,yt),t(M,ee),t(ee,Tt),t(u,At),t(u,q),t(q,te),t(te,$t),t(q,It),t(q,re),t(re,Xt),t(u,Ct),t(u,F),t(F,ae),t(ae,kt),t(F,Ut),t(F,ne),t(ne,St),t(u,Bt),t(u,D),t(D,oe),t(oe,Mt),t(D,qt),t(D,ie),t(ie,Ft),h(e,Ve,l),fe(V,e,l),h(e,Ne,l),h(e,T,l),t(T,Dt),t(T,N),t(N,Vt),t(T,Nt),h(e,Le,l),h(e,P,l),t(P,A),t(A,ge),fe(L,ge,null),t(P,Lt),t(P,xe),t(xe,Rt),h(e,Re,l),h(e,R,l),t(R,zt),t(R,z),t(z,Ht),h(e,ze,l),h(e,le,l),t(le,se),t(se,Gt),t(se,$),t($,jt),t($,ye),t(ye,Ot),t($,Jt),t($,Te),t(Te,Yt),h(e,He,l),h(e,E,l),t(E,I),t(I,Ae),fe(H,Ae,null),t(E,Kt),t(E,$e),t($e,Qt),h(e,Ge,l),h(e,G,l),t(G,Wt),t(G,j),t(j,Zt),je=!0},p:Gr,i(e){je||(ce(C.$$.fragment,e),ce(k.$$.fragment,e),ce(S.$$.fragment,e),ce(V.$$.fragment,e),ce(L.$$.fragment,e),ce(H.$$.fragment,e),je=!0)},o(e){ue(C.$$.fragment,e),ue(k.$$.fragment,e),ue(S.$$.fragment,e),ue(V.$$.fragment,e),ue(L.$$.fragment,e),ue(H.$$.fragment,e),je=!1},d(e){r(d),e&&r(Ce),e&&r(m),de(C),e&&r(ke),e&&r(O),e&&r(Ue),e&&r(_),de(k),e&&r(Se),e&&r(J),e&&r(Be),e&&r(Y),e&&r(Me),e&&r(g),e&&r(qe),e&&r(v),de(S),e&&r(Fe),e&&r(K),e&&r(De),e&&r(y),e&&r(Ve),de(V,e),e&&r(Ne),e&&r(T),e&&r(Le),e&&r(P),de(L),e&&r(Re),e&&r(R),e&&r(ze),e&&r(le),e&&r(He),e&&r(E),de(H),e&&r(Ge),e&&r(G)}}}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 Kr(ar){return jr(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class ea extends Lr{constructor(d){super();Rr(this,d,Kr,Jr,zr,{})}}export{ea as default,Yr as metadata};
