import{S as xn,i as yn,s as Tn,e as r,k as f,w as _e,t as l,M as An,c as a,d as n,m as c,a as o,x as ve,h as s,b as i,G as t,g as h,y as Pe,L as $n,q as Ee,o as be,B as we,v as Xn}from"../chunks/vendor-hf-doc-builder.js";import{I as Ye}from"../chunks/IconCopyLink-hf-doc-builder.js";import{C as In}from"../chunks/CodeBlock-hf-doc-builder.js";function Cn(zt){let d,ge,m,E,ae,X,Ke,oe,Qe,xe,z,We,ye,_,b,ie,I,Ze,le,et,Te,H,tt,Ae,R,nt,$e,w,rt,C,at,ot,Xe,v,g,se,U,it,pe,lt,Ie,G,st,Ce,x,he,k,j,pt,ht,O,ft,ct,u,M,J,ut,dt,Y,mt,_t,B,K,vt,Pt,Q,Et,bt,S,W,wt,gt,Z,xt,yt,q,ee,Tt,At,te,$t,Ue,F,ke,y,Xt,D,It,Ct,Me,P,T,fe,V,Ut,ce,kt,Be,L,Mt,N,Bt,Se,ne,re,St,A,qt,ue,Ft,Dt,de,Vt,qe;return X=new Ye({}),I=new Ye({}),U=new Ye({}),F=new In({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>'}}),V=new Ye({}),{c(){d=r("meta"),ge=f(),m=r("h1"),E=r("a"),ae=r("span"),_e(X.$$.fragment),Ke=f(),oe=r("span"),Qe=l("Efficient Training on CPU"),xe=f(),z=r("p"),We=l("This guide focuses on training large models efficiently on CPU."),ye=f(),_=r("h2"),b=r("a"),ie=r("span"),_e(I.$$.fragment),Ze=f(),le=r("span"),et=l("Mixed precision with IPEX"),Te=f(),H=r("p"),tt=l("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."),Ae=f(),R=r("p"),nt=l("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."),$e=f(),w=r("p"),rt=l("Check more detailed information for "),C=r("a"),at=l("Auto Mixed Precision"),ot=l("."),Xe=f(),v=r("h3"),g=r("a"),se=r("span"),_e(U.$$.fragment),it=f(),pe=r("span"),lt=l("IPEX installation:"),Ie=f(),G=r("p"),st=l("IPEX release is following PyTorch, to install via pip:"),Ce=f(),x=r("table"),he=r("thead"),k=r("tr"),j=r("th"),pt=l("PyTorch Version"),ht=f(),O=r("th"),ft=l("IPEX version"),ct=f(),u=r("tbody"),M=r("tr"),J=r("td"),ut=l("1.13"),dt=f(),Y=r("td"),mt=l("1.13.0+cpu"),_t=f(),B=r("tr"),K=r("td"),vt=l("1.12"),Pt=f(),Q=r("td"),Et=l("1.12.300+cpu"),bt=f(),S=r("tr"),W=r("td"),wt=l("1.11"),gt=f(),Z=r("td"),xt=l("1.11.200+cpu"),yt=f(),q=r("tr"),ee=r("td"),Tt=l("1.10"),At=f(),te=r("td"),$t=l("1.10.100+cpu"),Ue=f(),_e(F.$$.fragment),ke=f(),y=r("p"),Xt=l("Check more approaches for "),D=r("a"),It=l("IPEX installation"),Ct=l("."),Me=f(),P=r("h3"),T=r("a"),fe=r("span"),_e(V.$$.fragment),Ut=f(),ce=r("span"),kt=l("Usage in Trainer"),Be=l("\n\nTo enable auto mixed precision with IPEX in Trainer, users should add `use_ipex`, `bf16` and `no_cuda` in training command arguments.\n"),L=r("p"),Mt=l("Take an example of the use cases on "),N=r("a"),Bt=l("Transformers question-answering"),Se=f(),ne=r("ul"),re=r("li"),St=l("Training with IPEX using BF16 auto mixed precision on CPU:"),A=r("pre"),qt=l(` 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/ \\
`),ue=r("b"),Ft=l("--use_ipex \\"),Dt=l(`
`),de=r("b"),Vt=l("--bf16 --no_cuda"),this.h()},l(e){const p=An('[data-svelte="svelte-1phssyn"]',document.head);d=a(p,"META",{name:!0,content:!0}),p.forEach(n),ge=c(e),m=a(e,"H1",{class:!0});var Fe=o(m);E=a(Fe,"A",{id:!0,class:!0,href:!0});var Ht=o(E);ae=a(Ht,"SPAN",{});var Rt=o(ae);ve(X.$$.fragment,Rt),Rt.forEach(n),Ht.forEach(n),Ke=c(Fe),oe=a(Fe,"SPAN",{});var Gt=o(oe);Qe=s(Gt,"Efficient Training on CPU"),Gt.forEach(n),Fe.forEach(n),xe=c(e),z=a(e,"P",{});var jt=o(z);We=s(jt,"This guide focuses on training large models efficiently on CPU."),jt.forEach(n),ye=c(e),_=a(e,"H2",{class:!0});var De=o(_);b=a(De,"A",{id:!0,class:!0,href:!0});var Ot=o(b);ie=a(Ot,"SPAN",{});var Jt=o(ie);ve(I.$$.fragment,Jt),Jt.forEach(n),Ot.forEach(n),Ze=c(De),le=a(De,"SPAN",{});var Yt=o(le);et=s(Yt,"Mixed precision with IPEX"),Yt.forEach(n),De.forEach(n),Te=c(e),H=a(e,"P",{});var Kt=o(H);tt=s(Kt,"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."),Kt.forEach(n),Ae=c(e),R=a(e,"P",{});var Qt=o(R);nt=s(Qt,"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."),Qt.forEach(n),$e=c(e),w=a(e,"P",{});var Ve=o(w);rt=s(Ve,"Check more detailed information for "),C=a(Ve,"A",{href:!0,rel:!0});var Wt=o(C);at=s(Wt,"Auto Mixed Precision"),Wt.forEach(n),ot=s(Ve,"."),Ve.forEach(n),Xe=c(e),v=a(e,"H3",{class:!0});var Le=o(v);g=a(Le,"A",{id:!0,class:!0,href:!0});var Zt=o(g);se=a(Zt,"SPAN",{});var en=o(se);ve(U.$$.fragment,en),en.forEach(n),Zt.forEach(n),it=c(Le),pe=a(Le,"SPAN",{});var tn=o(pe);lt=s(tn,"IPEX installation:"),tn.forEach(n),Le.forEach(n),Ie=c(e),G=a(e,"P",{});var nn=o(G);st=s(nn,"IPEX release is following PyTorch, to install via pip:"),nn.forEach(n),Ce=c(e),x=a(e,"TABLE",{});var Ne=o(x);he=a(Ne,"THEAD",{});var rn=o(he);k=a(rn,"TR",{});var ze=o(k);j=a(ze,"TH",{align:!0});var an=o(j);pt=s(an,"PyTorch Version"),an.forEach(n),ht=c(ze),O=a(ze,"TH",{align:!0});var on=o(O);ft=s(on,"IPEX version"),on.forEach(n),ze.forEach(n),rn.forEach(n),ct=c(Ne),u=a(Ne,"TBODY",{});var $=o(u);M=a($,"TR",{});var He=o(M);J=a(He,"TD",{align:!0});var ln=o(J);ut=s(ln,"1.13"),ln.forEach(n),dt=c(He),Y=a(He,"TD",{align:!0});var sn=o(Y);mt=s(sn,"1.13.0+cpu"),sn.forEach(n),He.forEach(n),_t=c($),B=a($,"TR",{});var Re=o(B);K=a(Re,"TD",{align:!0});var pn=o(K);vt=s(pn,"1.12"),pn.forEach(n),Pt=c(Re),Q=a(Re,"TD",{align:!0});var hn=o(Q);Et=s(hn,"1.12.300+cpu"),hn.forEach(n),Re.forEach(n),bt=c($),S=a($,"TR",{});var Ge=o(S);W=a(Ge,"TD",{align:!0});var fn=o(W);wt=s(fn,"1.11"),fn.forEach(n),gt=c(Ge),Z=a(Ge,"TD",{align:!0});var cn=o(Z);xt=s(cn,"1.11.200+cpu"),cn.forEach(n),Ge.forEach(n),yt=c($),q=a($,"TR",{});var je=o(q);ee=a(je,"TD",{align:!0});var un=o(ee);Tt=s(un,"1.10"),un.forEach(n),At=c(je),te=a(je,"TD",{align:!0});var dn=o(te);$t=s(dn,"1.10.100+cpu"),dn.forEach(n),je.forEach(n),$.forEach(n),Ne.forEach(n),Ue=c(e),ve(F.$$.fragment,e),ke=c(e),y=a(e,"P",{});var Oe=o(y);Xt=s(Oe,"Check more approaches for "),D=a(Oe,"A",{href:!0,rel:!0});var mn=o(D);It=s(mn,"IPEX installation"),mn.forEach(n),Ct=s(Oe,"."),Oe.forEach(n),Me=c(e),P=a(e,"H3",{class:!0});var Je=o(P);T=a(Je,"A",{id:!0,class:!0,href:!0});var _n=o(T);fe=a(_n,"SPAN",{});var vn=o(fe);ve(V.$$.fragment,vn),vn.forEach(n),_n.forEach(n),Ut=c(Je),ce=a(Je,"SPAN",{});var Pn=o(ce);kt=s(Pn,"Usage in Trainer"),Pn.forEach(n),Je.forEach(n),Be=s(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"),L=a(e,"P",{});var Lt=o(L);Mt=s(Lt,"Take an example of the use cases on "),N=a(Lt,"A",{href:!0,rel:!0});var En=o(N);Bt=s(En,"Transformers question-answering"),En.forEach(n),Lt.forEach(n),Se=c(e),ne=a(e,"UL",{});var bn=o(ne);re=a(bn,"LI",{});var Nt=o(re);St=s(Nt,"Training with IPEX using BF16 auto mixed precision on CPU:"),A=a(Nt,"PRE",{});var me=o(A);qt=s(me,` 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/ \\
`),ue=a(me,"B",{});var wn=o(ue);Ft=s(wn,"--use_ipex \\"),wn.forEach(n),Dt=s(me,`
`),de=a(me,"B",{});var gn=o(de);Vt=s(gn,"--bf16 --no_cuda"),gn.forEach(n),me.forEach(n),Nt.forEach(n),bn.forEach(n),this.h()},h(){i(d,"name","hf:doc:metadata"),i(d,"content",JSON.stringify(Un)),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(C,"href","https://intel.github.io/intel-extension-for-pytorch/cpu/latest/tutorials/features/amp.html"),i(C,"rel","nofollow"),i(g,"id","ipex-installation"),i(g,"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(g,"href","#ipex-installation"),i(v,"class","relative group"),i(j,"align","center"),i(O,"align","center"),i(J,"align","center"),i(Y,"align","center"),i(K,"align","center"),i(Q,"align","center"),i(W,"align","center"),i(Z,"align","center"),i(ee,"align","center"),i(te,"align","center"),i(D,"href","https://intel.github.io/intel-extension-for-pytorch/cpu/latest/tutorials/installation.html"),i(D,"rel","nofollow"),i(T,"id","usage-in-trainer"),i(T,"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(T,"href","#usage-in-trainer"),i(P,"class","relative group"),i(N,"href","https://github.com/huggingface/transformers/tree/main/examples/pytorch/question-answering"),i(N,"rel","nofollow")},m(e,p){t(document.head,d),h(e,ge,p),h(e,m,p),t(m,E),t(E,ae),Pe(X,ae,null),t(m,Ke),t(m,oe),t(oe,Qe),h(e,xe,p),h(e,z,p),t(z,We),h(e,ye,p),h(e,_,p),t(_,b),t(b,ie),Pe(I,ie,null),t(_,Ze),t(_,le),t(le,et),h(e,Te,p),h(e,H,p),t(H,tt),h(e,Ae,p),h(e,R,p),t(R,nt),h(e,$e,p),h(e,w,p),t(w,rt),t(w,C),t(C,at),t(w,ot),h(e,Xe,p),h(e,v,p),t(v,g),t(g,se),Pe(U,se,null),t(v,it),t(v,pe),t(pe,lt),h(e,Ie,p),h(e,G,p),t(G,st),h(e,Ce,p),h(e,x,p),t(x,he),t(he,k),t(k,j),t(j,pt),t(k,ht),t(k,O),t(O,ft),t(x,ct),t(x,u),t(u,M),t(M,J),t(J,ut),t(M,dt),t(M,Y),t(Y,mt),t(u,_t),t(u,B),t(B,K),t(K,vt),t(B,Pt),t(B,Q),t(Q,Et),t(u,bt),t(u,S),t(S,W),t(W,wt),t(S,gt),t(S,Z),t(Z,xt),t(u,yt),t(u,q),t(q,ee),t(ee,Tt),t(q,At),t(q,te),t(te,$t),h(e,Ue,p),Pe(F,e,p),h(e,ke,p),h(e,y,p),t(y,Xt),t(y,D),t(D,It),t(y,Ct),h(e,Me,p),h(e,P,p),t(P,T),t(T,fe),Pe(V,fe,null),t(P,Ut),t(P,ce),t(ce,kt),h(e,Be,p),h(e,L,p),t(L,Mt),t(L,N),t(N,Bt),h(e,Se,p),h(e,ne,p),t(ne,re),t(re,St),t(re,A),t(A,qt),t(A,ue),t(ue,Ft),t(A,Dt),t(A,de),t(de,Vt),qe=!0},p:$n,i(e){qe||(Ee(X.$$.fragment,e),Ee(I.$$.fragment,e),Ee(U.$$.fragment,e),Ee(F.$$.fragment,e),Ee(V.$$.fragment,e),qe=!0)},o(e){be(X.$$.fragment,e),be(I.$$.fragment,e),be(U.$$.fragment,e),be(F.$$.fragment,e),be(V.$$.fragment,e),qe=!1},d(e){n(d),e&&n(ge),e&&n(m),we(X),e&&n(xe),e&&n(z),e&&n(ye),e&&n(_),we(I),e&&n(Te),e&&n(H),e&&n(Ae),e&&n(R),e&&n($e),e&&n(w),e&&n(Xe),e&&n(v),we(U),e&&n(Ie),e&&n(G),e&&n(Ce),e&&n(x),e&&n(Ue),we(F,e),e&&n(ke),e&&n(y),e&&n(Me),e&&n(P),we(V),e&&n(Be),e&&n(L),e&&n(Se),e&&n(ne)}}}const Un={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"}],title:"Mixed precision with IPEX"}],title:"Efficient Training on CPU"};function kn(zt){return Xn(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class qn extends xn{constructor(d){super();yn(this,d,kn,Cn,Tn,{})}}export{qn as default,Un as metadata};
