import{S as _t,i as wt,s as yt,e as r,k as c,w as de,t as n,M as Tt,c as i,d as t,m as h,a as s,x as fe,h as l,b as p,G as a,g as m,y as ue,L as Pt,q as ge,o as ve,B as _e,v as bt}from"../../chunks/vendor-hf-doc-builder.js";import{I as gt}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as vt}from"../../chunks/CodeBlock-hf-doc-builder.js";function At(Ke){let g,J,v,w,F,b,we,W,ye,K,_,y,q,A,Te,D,Pe,Q,T,be,E,Ae,Ee,X,L,Oe,Y,R,H,$e,Z,N,ke,ee,P,Me,O,Ge,Se,te,d,Ce,$,Le,Re,k,Ne,Ie,ae,I,xe,oe,M,re,x,Ue,ne,f,ze,V,Be,Fe,j,We,qe,ie,G,le,u,De,S,He,Ve,C,je,Je,se;return b=new gt({}),A=new gt({}),M=new vt({props:{code:`wget --content-disposition https://api.ngc.nvidia.com/v2/models/nvidia/megatron_lm_345m/versions/v0.0/zip -O
megatron_gpt2_345m_v0_0.zip`,highlighted:`wget --content-disposition https://api.ngc.nvidia.com/v2/models/nvidia/megatron_lm_345m/versions/v0.0/zip -O
megatron_gpt2_345m_v0_0.zip`}}),G=new vt({props:{code:"python3 $PATH_TO_TRANSFORMERS/models/megatron_gpt2/convert_megatron_gpt2_checkpoint.py megatron_gpt2_345m_v0_0.zip",highlighted:'python3 <span class="hljs-variable">$PATH_TO_TRANSFORMERS</span>/models/megatron_gpt2/convert_megatron_gpt2_checkpoint.py megatron_gpt2_345m_v0_0.zip'}}),{c(){g=r("meta"),J=c(),v=r("h1"),w=r("a"),F=r("span"),de(b.$$.fragment),we=c(),W=r("span"),ye=n("MegatronGPT2"),K=c(),_=r("h2"),y=r("a"),q=r("span"),de(A.$$.fragment),Te=c(),D=r("span"),Pe=n("Overview"),Q=c(),T=r("p"),be=n("The MegatronGPT2 model was proposed in "),E=r("a"),Ae=n(`Megatron-LM: Training Multi-Billion Parameter Language Models Using Model
Parallelism`),Ee=n(` by Mohammad Shoeybi, Mostofa Patwary, Raul Puri, Patrick LeGresley,
Jared Casper and Bryan Catanzaro.`),X=c(),L=r("p"),Oe=n("The abstract from the paper is the following:"),Y=c(),R=r("p"),H=r("em"),$e=n(`Recent work in language modeling demonstrates that training large transformer models advances the state of the art in
Natural Language Processing applications. However, very large models can be quite difficult to train due to memory
constraints. In this work, we present our techniques for training very large transformer models and implement a simple,
efficient intra-layer model parallel approach that enables training transformer models with billions of parameters. Our
approach does not require a new compiler or library changes, is orthogonal and complimentary to pipeline model
parallelism, and can be fully implemented with the insertion of a few communication operations in native PyTorch. We
illustrate this approach by converging transformer based models up to 8.3 billion parameters using 512 GPUs. We sustain
15.1 PetaFLOPs across the entire application with 76% scaling efficiency when compared to a strong single GPU baseline
that sustains 39 TeraFLOPs, which is 30% of peak FLOPs. To demonstrate that large language models can further advance
the state of the art (SOTA), we train an 8.3 billion parameter transformer language model similar to GPT-2 and a 3.9
billion parameter model similar to BERT. We show that careful attention to the placement of layer normalization in
BERT-like models is critical to achieving increased performance as the model size grows. Using the GPT-2 model we
achieve SOTA results on the WikiText103 (10.8 compared to SOTA perplexity of 15.8) and LAMBADA (66.5% compared to SOTA
accuracy of 63.2%) datasets. Our BERT model achieves SOTA results on the RACE dataset (90.9% compared to SOTA accuracy
of 89.4%).`),Z=c(),N=r("p"),ke=n("Tips:"),ee=c(),P=r("p"),Me=n("We have provided pretrained "),O=r("a"),Ge=n("GPT2-345M"),Se=n(` checkpoints
for use to evaluate or finetuning downstream tasks.`),te=c(),d=r("p"),Ce=n("To access these checkpoints, first "),$=r("a"),Le=n("sign up"),Re=n(` for and setup the NVIDIA GPU Cloud (NGC)
Registry CLI. Further documentation for downloading models can be found in the `),k=r("a"),Ne=n("NGC documentation"),Ie=n("."),ae=c(),I=r("p"),xe=n("Alternatively, you can directly download the checkpoints using:"),oe=c(),de(M.$$.fragment),re=c(),x=r("p"),Ue=n(`Once you have obtained the checkpoint from NVIDIA GPU Cloud (NGC), you have to convert it to a format that will easily
be loaded by Hugging Face Transformers GPT2 implementation.`),ne=c(),f=r("p"),ze=n("The following command allows you to do the conversion. We assume that the folder "),V=r("code"),Be=n("models/megatron_gpt2"),Fe=n(` contains
`),j=r("code"),We=n("megatron_gpt2_345m_v0_0.zip"),qe=n(" and that the command is run from that folder:"),ie=c(),de(G.$$.fragment),le=c(),u=r("p"),De=n("This model was contributed by "),S=r("a"),He=n("jdemouth"),Ve=n(". The original code can be found "),C=r("a"),je=n("here"),Je=n(`. That repository contains a multi-GPU and multi-node implementation of the
Megatron Language models. In particular, it contains a hybrid model parallel approach using \u201Ctensor parallel\u201D and
\u201Cpipeline parallel\u201D techniques.`),this.h()},l(e){const o=Tt('[data-svelte="svelte-1phssyn"]',document.head);g=i(o,"META",{name:!0,content:!0}),o.forEach(t),J=h(e),v=i(e,"H1",{class:!0});var me=s(v);w=i(me,"A",{id:!0,class:!0,href:!0});var Qe=s(w);F=i(Qe,"SPAN",{});var Xe=s(F);fe(b.$$.fragment,Xe),Xe.forEach(t),Qe.forEach(t),we=h(me),W=i(me,"SPAN",{});var Ye=s(W);ye=l(Ye,"MegatronGPT2"),Ye.forEach(t),me.forEach(t),K=h(e),_=i(e,"H2",{class:!0});var pe=s(_);y=i(pe,"A",{id:!0,class:!0,href:!0});var Ze=s(y);q=i(Ze,"SPAN",{});var et=s(q);fe(A.$$.fragment,et),et.forEach(t),Ze.forEach(t),Te=h(pe),D=i(pe,"SPAN",{});var tt=s(D);Pe=l(tt,"Overview"),tt.forEach(t),pe.forEach(t),Q=h(e),T=i(e,"P",{});var ce=s(T);be=l(ce,"The MegatronGPT2 model was proposed in "),E=i(ce,"A",{href:!0,rel:!0});var at=s(E);Ae=l(at,`Megatron-LM: Training Multi-Billion Parameter Language Models Using Model
Parallelism`),at.forEach(t),Ee=l(ce,` by Mohammad Shoeybi, Mostofa Patwary, Raul Puri, Patrick LeGresley,
Jared Casper and Bryan Catanzaro.`),ce.forEach(t),X=h(e),L=i(e,"P",{});var ot=s(L);Oe=l(ot,"The abstract from the paper is the following:"),ot.forEach(t),Y=h(e),R=i(e,"P",{});var rt=s(R);H=i(rt,"EM",{});var nt=s(H);$e=l(nt,`Recent work in language modeling demonstrates that training large transformer models advances the state of the art in
Natural Language Processing applications. However, very large models can be quite difficult to train due to memory
constraints. In this work, we present our techniques for training very large transformer models and implement a simple,
efficient intra-layer model parallel approach that enables training transformer models with billions of parameters. Our
approach does not require a new compiler or library changes, is orthogonal and complimentary to pipeline model
parallelism, and can be fully implemented with the insertion of a few communication operations in native PyTorch. We
illustrate this approach by converging transformer based models up to 8.3 billion parameters using 512 GPUs. We sustain
15.1 PetaFLOPs across the entire application with 76% scaling efficiency when compared to a strong single GPU baseline
that sustains 39 TeraFLOPs, which is 30% of peak FLOPs. To demonstrate that large language models can further advance
the state of the art (SOTA), we train an 8.3 billion parameter transformer language model similar to GPT-2 and a 3.9
billion parameter model similar to BERT. We show that careful attention to the placement of layer normalization in
BERT-like models is critical to achieving increased performance as the model size grows. Using the GPT-2 model we
achieve SOTA results on the WikiText103 (10.8 compared to SOTA perplexity of 15.8) and LAMBADA (66.5% compared to SOTA
accuracy of 63.2%) datasets. Our BERT model achieves SOTA results on the RACE dataset (90.9% compared to SOTA accuracy
of 89.4%).`),nt.forEach(t),rt.forEach(t),Z=h(e),N=i(e,"P",{});var it=s(N);ke=l(it,"Tips:"),it.forEach(t),ee=h(e),P=i(e,"P",{});var he=s(P);Me=l(he,"We have provided pretrained "),O=i(he,"A",{href:!0,rel:!0});var lt=s(O);Ge=l(lt,"GPT2-345M"),lt.forEach(t),Se=l(he,` checkpoints
for use to evaluate or finetuning downstream tasks.`),he.forEach(t),te=h(e),d=i(e,"P",{});var U=s(d);Ce=l(U,"To access these checkpoints, first "),$=i(U,"A",{href:!0,rel:!0});var st=s($);Le=l(st,"sign up"),st.forEach(t),Re=l(U,` for and setup the NVIDIA GPU Cloud (NGC)
Registry CLI. Further documentation for downloading models can be found in the `),k=i(U,"A",{href:!0,rel:!0});var mt=s(k);Ne=l(mt,"NGC documentation"),mt.forEach(t),Ie=l(U,"."),U.forEach(t),ae=h(e),I=i(e,"P",{});var pt=s(I);xe=l(pt,"Alternatively, you can directly download the checkpoints using:"),pt.forEach(t),oe=h(e),fe(M.$$.fragment,e),re=h(e),x=i(e,"P",{});var ct=s(x);Ue=l(ct,`Once you have obtained the checkpoint from NVIDIA GPU Cloud (NGC), you have to convert it to a format that will easily
be loaded by Hugging Face Transformers GPT2 implementation.`),ct.forEach(t),ne=h(e),f=i(e,"P",{});var z=s(f);ze=l(z,"The following command allows you to do the conversion. We assume that the folder "),V=i(z,"CODE",{});var ht=s(V);Be=l(ht,"models/megatron_gpt2"),ht.forEach(t),Fe=l(z,` contains
`),j=i(z,"CODE",{});var dt=s(j);We=l(dt,"megatron_gpt2_345m_v0_0.zip"),dt.forEach(t),qe=l(z," and that the command is run from that folder:"),z.forEach(t),ie=h(e),fe(G.$$.fragment,e),le=h(e),u=i(e,"P",{});var B=s(u);De=l(B,"This model was contributed by "),S=i(B,"A",{href:!0,rel:!0});var ft=s(S);He=l(ft,"jdemouth"),ft.forEach(t),Ve=l(B,". The original code can be found "),C=i(B,"A",{href:!0,rel:!0});var ut=s(C);je=l(ut,"here"),ut.forEach(t),Je=l(B,`. That repository contains a multi-GPU and multi-node implementation of the
Megatron Language models. In particular, it contains a hybrid model parallel approach using \u201Ctensor parallel\u201D and
\u201Cpipeline parallel\u201D techniques.`),B.forEach(t),this.h()},h(){p(g,"name","hf:doc:metadata"),p(g,"content",JSON.stringify(Et)),p(w,"id","megatrongpt2"),p(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"),p(w,"href","#megatrongpt2"),p(v,"class","relative group"),p(y,"id","overview"),p(y,"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"),p(y,"href","#overview"),p(_,"class","relative group"),p(E,"href","https://arxiv.org/abs/1909.08053"),p(E,"rel","nofollow"),p(O,"href","https://ngc.nvidia.com/catalog/models/nvidia:megatron_lm_345m"),p(O,"rel","nofollow"),p($,"href","https://ngc.nvidia.com/signup"),p($,"rel","nofollow"),p(k,"href","https://docs.nvidia.com/dgx/ngc-registry-cli-user-guide/index.html#topic_6_4_1"),p(k,"rel","nofollow"),p(S,"href","https://huggingface.co/jdemouth"),p(S,"rel","nofollow"),p(C,"href","https://github.com/NVIDIA/Megatron-LM"),p(C,"rel","nofollow")},m(e,o){a(document.head,g),m(e,J,o),m(e,v,o),a(v,w),a(w,F),ue(b,F,null),a(v,we),a(v,W),a(W,ye),m(e,K,o),m(e,_,o),a(_,y),a(y,q),ue(A,q,null),a(_,Te),a(_,D),a(D,Pe),m(e,Q,o),m(e,T,o),a(T,be),a(T,E),a(E,Ae),a(T,Ee),m(e,X,o),m(e,L,o),a(L,Oe),m(e,Y,o),m(e,R,o),a(R,H),a(H,$e),m(e,Z,o),m(e,N,o),a(N,ke),m(e,ee,o),m(e,P,o),a(P,Me),a(P,O),a(O,Ge),a(P,Se),m(e,te,o),m(e,d,o),a(d,Ce),a(d,$),a($,Le),a(d,Re),a(d,k),a(k,Ne),a(d,Ie),m(e,ae,o),m(e,I,o),a(I,xe),m(e,oe,o),ue(M,e,o),m(e,re,o),m(e,x,o),a(x,Ue),m(e,ne,o),m(e,f,o),a(f,ze),a(f,V),a(V,Be),a(f,Fe),a(f,j),a(j,We),a(f,qe),m(e,ie,o),ue(G,e,o),m(e,le,o),m(e,u,o),a(u,De),a(u,S),a(S,He),a(u,Ve),a(u,C),a(C,je),a(u,Je),se=!0},p:Pt,i(e){se||(ge(b.$$.fragment,e),ge(A.$$.fragment,e),ge(M.$$.fragment,e),ge(G.$$.fragment,e),se=!0)},o(e){ve(b.$$.fragment,e),ve(A.$$.fragment,e),ve(M.$$.fragment,e),ve(G.$$.fragment,e),se=!1},d(e){t(g),e&&t(J),e&&t(v),_e(b),e&&t(K),e&&t(_),_e(A),e&&t(Q),e&&t(T),e&&t(X),e&&t(L),e&&t(Y),e&&t(R),e&&t(Z),e&&t(N),e&&t(ee),e&&t(P),e&&t(te),e&&t(d),e&&t(ae),e&&t(I),e&&t(oe),_e(M,e),e&&t(re),e&&t(x),e&&t(ne),e&&t(f),e&&t(ie),_e(G,e),e&&t(le),e&&t(u)}}}const Et={local:"megatrongpt2",sections:[{local:"overview",title:"Overview"}],title:"MegatronGPT2"};function Ot(Ke){return bt(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Gt extends _t{constructor(g){super();wt(this,g,Ot,At,yt,{})}}export{Gt as default,Et as metadata};
