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new U({}),Pt=new U({}),wt=new U({}),kt=new U({}),Ut=new U({}),Ct=new Ip({props:{code:`
# DP
rm -r /tmp/test-clm; CUDA_VISIBLE_DEVICES=0,1 \\
python examples/pytorch/language-modeling/run_clm.py \\
--model_name_or_path gpt2 --dataset_name wikitext --dataset_config_name wikitext-2-raw-v1 \\
--do_train --output_dir /tmp/test-clm --per_device_train_batch_size 4 --max_steps 200

{'train_runtime': 110.5948, 'train_samples_per_second': 1.808, 'epoch': 0.69}

# DDP w/ NVlink
rm -r /tmp/test-clm; CUDA_VISIBLE_DEVICES=0,1 \\
python -m torch.distributed.launch --nproc_per_node 2 examples/pytorch/language-modeling/run_clm.py \\
--model_name_or_path gpt2 --dataset_name wikitext --dataset_config_name wikitext-2-raw-v1 \\
--do_train --output_dir /tmp/test-clm --per_device_train_batch_size 4 --max_steps 200

{'train_runtime': 101.9003, 'train_samples_per_second': 1.963, 'epoch': 0.69}

# DDP w/o NVlink
rm -r /tmp/test-clm; NCCL_P2P_DISABLE=1 CUDA_VISIBLE_DEVICES=0,1 \\
python -m torch.distributed.launch --nproc_per_node 2 examples/pytorch/language-modeling/run_clm.py \\
--model_name_or_path gpt2 --dataset_name wikitext --dataset_config_name wikitext-2-raw-v1 \\
--do_train --output_dir /tmp/test-clm --per_device_train_batch_size 4 --max_steps 200

{'train_runtime': 131.4367, 'train_samples_per_second': 1.522, 'epoch': 0.69}`,highlighted:`
<span class="hljs-comment"># DP</span>
<span class="hljs-string">rm</span> -<span class="hljs-string">r</span> /<span class="hljs-string">tmp</span>/<span class="hljs-string">test-clm</span>; <span class="hljs-string">CUDA_VISIBLE_DEVICES</span>=<span class="hljs-string">0</span>,<span class="hljs-string">1</span> \\
<span class="hljs-string">python</span> <span class="hljs-string">examples</span>/<span class="hljs-string">pytorch</span>/<span class="hljs-string">language-modeling</span>/<span class="hljs-string">run_clm</span>.<span class="hljs-string">py</span> \\
<span class="hljs-built_in">--model_name_or_path</span> <span class="hljs-string">gpt2</span> <span class="hljs-built_in">--dataset_name</span> <span class="hljs-string">wikitext</span> <span class="hljs-built_in">--dataset_config_name</span> <span class="hljs-string">wikitext-2-raw-v1</span> \\
<span class="hljs-built_in">--do_train</span> <span class="hljs-built_in">--output_dir</span> /<span class="hljs-string">tmp</span>/<span class="hljs-string">test-clm</span> <span class="hljs-built_in">--per_device_train_batch_size</span> <span class="hljs-string">4</span> <span class="hljs-built_in">--max_steps</span> <span class="hljs-string">200</span>

{<span class="hljs-string">&#x27;train_runtime&#x27;</span>: <span class="hljs-string">110</span>.<span class="hljs-string">5948</span>, <span class="hljs-string">&#x27;train_samples_per_second&#x27;</span>: <span class="hljs-string">1</span>.<span class="hljs-string">808</span>, <span class="hljs-string">&#x27;epoch&#x27;</span>: <span class="hljs-string">0</span>.<span class="hljs-string">69</span>}

<span class="hljs-comment"># DDP w/ NVlink</span>
<span class="hljs-string">rm</span> -<span class="hljs-string">r</span> /<span class="hljs-string">tmp</span>/<span class="hljs-string">test-clm</span>; <span class="hljs-string">CUDA_VISIBLE_DEVICES</span>=<span class="hljs-string">0</span>,<span class="hljs-string">1</span> \\
<span class="hljs-string">python</span> -<span class="hljs-string">m</span> <span class="hljs-string">torch</span>.<span class="hljs-string">distributed</span>.<span class="hljs-string">launch</span> <span class="hljs-built_in">--nproc_per_node</span> <span class="hljs-string">2</span> <span class="hljs-string">examples</span>/<span class="hljs-string">pytorch</span>/<span class="hljs-string">language-modeling</span>/<span class="hljs-string">run_clm</span>.<span class="hljs-string">py</span> \\
<span class="hljs-built_in">--model_name_or_path</span> <span class="hljs-string">gpt2</span> <span class="hljs-built_in">--dataset_name</span> <span class="hljs-string">wikitext</span> <span class="hljs-built_in">--dataset_config_name</span> <span class="hljs-string">wikitext-2-raw-v1</span> \\
<span class="hljs-built_in">--do_train</span> <span class="hljs-built_in">--output_dir</span> /<span class="hljs-string">tmp</span>/<span class="hljs-string">test-clm</span> <span class="hljs-built_in">--per_device_train_batch_size</span> <span class="hljs-string">4</span> <span class="hljs-built_in">--max_steps</span> <span class="hljs-string">200</span>

{<span class="hljs-string">&#x27;train_runtime&#x27;</span>: <span class="hljs-string">101</span>.<span class="hljs-string">9003</span>, <span class="hljs-string">&#x27;train_samples_per_second&#x27;</span>: <span class="hljs-string">1</span>.<span class="hljs-string">963</span>, <span class="hljs-string">&#x27;epoch&#x27;</span>: <span class="hljs-string">0</span>.<span class="hljs-string">69</span>}

<span class="hljs-comment"># DDP w/o NVlink</span>
<span class="hljs-string">rm</span> -<span class="hljs-string">r</span> /<span class="hljs-string">tmp</span>/<span class="hljs-string">test-clm</span>; <span class="hljs-string">NCCL_P2P_DISABLE</span>=<span class="hljs-string">1</span> <span class="hljs-string">CUDA_VISIBLE_DEVICES</span>=<span class="hljs-string">0</span>,<span class="hljs-string">1</span> \\
<span class="hljs-string">python</span> -<span class="hljs-string">m</span> <span class="hljs-string">torch</span>.<span class="hljs-string">distributed</span>.<span class="hljs-string">launch</span> <span class="hljs-built_in">--nproc_per_node</span> <span class="hljs-string">2</span> <span class="hljs-string">examples</span>/<span class="hljs-string">pytorch</span>/<span class="hljs-string">language-modeling</span>/<span class="hljs-string">run_clm</span>.<span class="hljs-string">py</span> \\
<span class="hljs-built_in">--model_name_or_path</span> <span class="hljs-string">gpt2</span> <span class="hljs-built_in">--dataset_name</span> <span class="hljs-string">wikitext</span> <span class="hljs-built_in">--dataset_config_name</span> <span class="hljs-string">wikitext-2-raw-v1</span> \\
<span class="hljs-built_in">--do_train</span> <span class="hljs-built_in">--output_dir</span> /<span class="hljs-string">tmp</span>/<span class="hljs-string">test-clm</span> <span class="hljs-built_in">--per_device_train_batch_size</span> <span class="hljs-string">4</span> <span class="hljs-built_in">--max_steps</span> <span class="hljs-string">200</span>

{<span class="hljs-string">&#x27;train_runtime&#x27;</span>: <span class="hljs-string">131</span>.<span class="hljs-string">4367</span>, <span class="hljs-string">&#x27;train_samples_per_second&#x27;</span>: <span class="hljs-string">1</span>.<span class="hljs-string">522</span>, <span class="hljs-string">&#x27;epoch&#x27;</span>: <span class="hljs-string">0</span>.<span class="hljs-string">69</span>}`}}),Rt=new U({}),Bt=new Ip({props:{code:`La | Lb | Lc
---|----|---
a0 | b0 | c0
a1 | b1 | c1
a2 | b2 | c2`,highlighted:`La |<span class="hljs-string"> Lb </span>|<span class="hljs-string"> Lc
---</span>|<span class="hljs-string">----</span>|<span class="hljs-string">---
a0 </span>|<span class="hljs-string"> b0 </span>|<span class="hljs-string"> c0
a1 </span>|<span class="hljs-string"> b1 </span>|<span class="hljs-string"> c1
a2 </span>|<span class="hljs-string"> b2 </span>|<span class="hljs-string"> c2</span>`}}),Vt=new Ip({props:{code:`GPU0:
La | Lb | Lc
---|----|---
a0 | b0 | c0

GPU1:
La | Lb | Lc
---|----|---
a1 | b1 | c1

GPU2:
La | Lb | Lc
---|----|---
a2 | b2 | c2`,highlighted:`GPU0:
La |<span class="hljs-string"> Lb </span>|<span class="hljs-string"> Lc
---</span>|<span class="hljs-string">----</span>|<span class="hljs-string">---
a0 </span>|<span class="hljs-string"> b0 </span>|<span class="hljs-string"> c0

GPU1:
La </span>|<span class="hljs-string"> Lb </span>|<span class="hljs-string"> Lc
---</span>|<span class="hljs-string">----</span>|<span class="hljs-string">---
a1 </span>|<span class="hljs-string"> b1 </span>|<span class="hljs-string"> c1

GPU2:
La </span>|<span class="hljs-string"> Lb </span>|<span class="hljs-string"> Lc
---</span>|<span class="hljs-string">----</span>|<span class="hljs-string">---
a2 </span>|<span class="hljs-string"> b2 </span>|<span class="hljs-string"> c2</span>`}}),qt=new Ip({props:{code:`x0 => GPU0
x1 => GPU1
x2 => GPU2`,highlighted:`<span class="hljs-attribute">x0</span> <span class="hljs-operator">=</span>&gt; GPU0
<span class="hljs-attribute">x1</span> <span class="hljs-operator">=</span>&gt; GPU1
<span class="hljs-attribute">x2</span> <span class="hljs-operator">=</span>&gt; GPU2`}}),Yt=new U({}),Xt=new Ip({props:{code:`===================  ===================
|  0 | 1 | 2 | 3  |  |  4 | 5 | 6 | 7  |
===================  ===================
        gpu0                 gpu1`,highlighted:`===================  ===================
|<span class="hljs-string">  0 </span>|<span class="hljs-string"> 1 </span>|<span class="hljs-string"> 2 </span>|<span class="hljs-string"> 3  </span>|<span class="hljs-string">  </span>|<span class="hljs-string">  4 </span>|<span class="hljs-string"> 5 </span>|<span class="hljs-string"> 6 </span>|<span class="hljs-string"> 7  </span>|
===================  ===================
        gpu0                 gpu1`}}),hl=new U({}),Tl=new U({}),Ol=new U({}),Cl=new U({}),ql=new U({}),Kl=new U({}),{c(){te=a("meta"),Sp=h(),le=a("h1"),Ge=a("a"),no=a("span"),m(vt.$$.fragment),Qd=h(),po=a("span"),eu=o("Efficient Training on Multiple GPUs"),Ap=h(),ha=a("p"),tu=o("When training on a single GPU is too slow or the model weights don\u2019t fit in a single GPUs memory we use a mutli-GPU setup. Switching from a single GPU to multiple requires some form of parallelism as the work needs to be distributed. There are several techniques to achieve parallism such as data, tensor, or pipeline parallism. However, there is no one solution to fit them all and which settings works best depends on the hardware you are running on. While the main concepts most likely will apply to any other framework, this article is focused on PyTorch-based implementations."),Op=h(),fa=a("p"),lu=o("We will first discuss in depth various 1D parallelism techniques and their pros and cons and then look at how they can be combined into 2D and 3D parallelism to enable an even faster training and to support even bigger models. Various other powerful alternative approaches will be presented."),jp=h(),ae=a("h2"),Ue=a("a"),ho=a("span"),m(Pt.$$.fragment),au=h(),fo=a("span"),su=o("Concepts"),xp=h(),ca=a("p"),iu=o("The following is the brief description of the main concepts that will be described later in depth in this document."),Mp=h(),E=a("ol"),da=a("li"),co=a("strong"),ou=o("DataParallel (DP)"),ru=o(" - the same setup is replicated multiple times, and each being fed a slice of the data. The processing is done in parallel and all setups are synchronized at the end of each training step."),nu=h(),ua=a("li"),uo=a("strong"),pu=o("TensorParallel (TP)"),hu=o(" - each tensor is split up into multiple chunks, so instead of having the whole tensor reside on a single gpu, each shard of the tensor resides on its designated gpu. During processing each shard gets processed separately and in parallel on different GPUs and the results are synced at the end of the step. This is what one may call horizontal parallelism, as the splitting happens on horizontal level."),fu=h(),ma=a("li"),mo=a("strong"),cu=o("PipelineParallel (PP)"),du=o(" - the model is split up vertically (layer-level) across multiple GPUs, so that only one or several layers of the model are places on a single gpu. Each gpu processes in parallel different stages of the pipeline and working on a small chunk of the batch."),uu=h(),va=a("li"),vo=a("strong"),mu=o("Zero Redundancy Optimizer (ZeRO)"),vu=o(" - Also performs sharding of the tensors somewhat similar to TP, except the whole tensor gets reconstructed in time for a forward or backward computation, therefore the model doesn\u2019t need to be modified. It also supports various offloading techniques to compensate for limited GPU memory."),Pu=h(),Pa=a("li"),Po=a("strong"),wu=o("Sharded DDP"),_u=o(" - is another name for the foundational ZeRO concept as used by various other implementations of ZeRO."),$p=h(),wa=a("p"),yu=o("Before diving deeper into the specifics of each concept we first have a look at the rough decision process when training large models on a large infrastructure."),Np=h(),se=a("h2"),Ie=a("a"),wo=a("span"),m(wt.$$.fragment),bu=h(),_o=a("span"),gu=o("Scalability Strategy"),zp=h(),_a=a("p"),yo=a("strong"),Eu=o("\u21E8 Single Node / Multi-GPU"),Cp=h(),$=a("ul"),_t=a("li"),bo=a("p"),Du=o("Model fits onto a single GPU:"),Lu=h(),yt=a("ol"),go=a("li"),Tu=o("DDP - Distributed DP"),ku=h(),Eo=a("li"),Gu=o("ZeRO - may or may not be faster depending on the situation and configuration used"),Uu=h(),bt=a("li"),Do=a("p"),Iu=o("Model doesn\u2019t fit onto a single GPU:"),Su=h(),ie=a("ol"),Lo=a("li"),To=a("p"),Au=o("PP"),Ou=h(),ko=a("li"),Go=a("p"),ju=o("ZeRO"),xu=h(),oe=a("li"),Uo=a("p"),Mu=o("TP"),$u=h(),Io=a("p"),Nu=o("With very fast intra-node connectivity of NVLINK or NVSwitch all three should be mostly on par, without these PP will be faster than TP or ZeRO. The degree of TP may also make a difference. Best to experiment to find the winner on your particular setup."),zu=h(),So=a("p"),Cu=o("TP is almost always used within a single node. That is TP size <= gpus per node."),Ru=h(),gt=a("li"),Ao=a("p"),Zu=o("Largest Layer not fitting into a single GPU:"),Bu=h(),Et=a("ol"),Oo=a("li"),Vu=o("If not using ZeRO - must use TP, as PP alone won\u2019t be able to fit."),qu=h(),jo=a("li"),Fu=o("With ZeRO see the same entry for \u201CSingle GPU\u201D above"),Rp=h(),ya=a("p"),xo=a("strong"),Wu=o("\u21E8 Multi-Node / Multi-GPU"),Zp=h(),Se=a("ul"),Dt=a("li"),Mo=a("p"),Hu=o("When you have fast inter-node connectivity:"),Yu=h(),Lt=a("ol"),$o=a("li"),Xu=o("ZeRO - as it requires close to no modifications to the model"),Ku=h(),No=a("li"),Ju=o("PP+TP+DP - less communications, but requires massive changes to the model"),Qu=h(),Tt=a("li"),zo=a("p"),em=o("when you have slow inter-node connectivity and still low on GPU memory:"),tm=h(),Co=a("ol"),Ro=a("li"),lm=o("DP+PP+TP+ZeRO-1"),Bp=h(),re=a("h2"),Ae=a("a"),Zo=a("span"),m(kt.$$.fragment),am=h(),Bo=a("span"),sm=o("Data Parallelism"),Vp=h(),I=a("p"),im=o("Most users with just 2 GPUs already enjoy the increased training speed up thanks to "),Vo=a("code"),om=o("DataParallel"),rm=o(" (DP) and "),qo=a("code"),nm=o("DistributedDataParallel"),pm=o(" (DDP) that are almost trivial to use. This is a built-in feature of Pytorch. Note that in general it is advised to use DDP as it is better maintained and works for all models while DP might fail for some models. "),Gt=a("a"),hm=o("PyTorch documentation"),fm=o(" itself recommends the use of DDP."),qp=h(),ne=a("h3"),Oe=a("a"),Fo=a("span"),m(Ut.$$.fragment),cm=h(),Wo=a("span"),dm=o("DP vs DDP"),Fp=h(),pe=a("p"),Ho=a("code"),um=o("DistributedDataParallel"),mm=o(" (DDP) is typically faster than "),Yo=a("code"),vm=o("DataParallel"),Pm=o(" (DP), but it is not always the case:"),Wp=h(),je=a("ul"),Xo=a("li"),wm=o("while DP is python threads-based, DDP is multiprocess-based - and as such it has no python threads limitations, such as GIL"),_m=h(),Ko=a("li"),ym=o("on the other hand a slow inter-connectivity between the GPU cards could lead to an actual slower outcome with DDP"),Hp=h(),ba=a("p"),bm=o("Here are the main differences in the inter-GPU communication overhead between the two modes:"),Yp=h(),It=a("p"),St=a("a"),gm=o("DDP"),Em=o(":"),Xp=h(),xe=a("ul"),Jo=a("li"),Dm=o("At the start time the main process replicates the model once from gpu 0 to the rest of gpus"),Lm=h(),ga=a("li"),Tm=o("Then for each batch:"),At=a("ol"),Qo=a("li"),km=o("each gpu consumes each own mini-batch of data directly"),Gm=h(),Ot=a("li"),Um=o("during "),er=a("code"),Im=o("backward"),Sm=o(", once the local gradients are ready, they are then averaged across all processes"),Kp=h(),jt=a("p"),xt=a("a"),Am=o("DP"),Om=o(":"),Jp=h(),Ea=a("p"),jm=o("For each batch:"),Qp=h(),D=a("ol"),tr=a("li"),xm=o("gpu 0 reads the batch of data and then sends a mini-batch to each gpu"),Mm=h(),lr=a("li"),$m=o("replicates the up-to-date model from gpu 0 to each gpu"),Nm=h(),Mt=a("li"),zm=o("runs "),ar=a("code"),Cm=o("forward"),Rm=o(" and sends output from each gpu to gpu 0, computes loss"),Zm=h(),Da=a("li"),Bm=o("scatters loss from gpu 0 to all gpus, runs "),sr=a("code"),Vm=o("backward"),qm=h(),ir=a("li"),Fm=o("sends gradients from each gpu to gpu 0 and averages those"),eh=h(),La=a("p"),Wm=o("The only communication DDP performs per batch is sending gradients, whereas DP does 5 different data exchanges per batch."),th=h(),Me=a("p"),Hm=o("DP copies data within the process via python threads, whereas DDP copies data via "),$t=a("a"),Ym=o("torch.distributed"),Xm=o("."),lh=h(),Ta=a("p"),Km=o("Under DP gpu 0 performs a lot more work than the rest of the gpus, thus resulting in under-utilization of gpus."),ah=h(),ka=a("p"),Jm=o("You can use DDP across multiple machines, but this is not the case with DP."),sh=h(),Ga=a("p"),Qm=o("There are other differences between DP and DDP but they aren\u2019t relevant to this discussion."),ih=h(),$e=a("p"),ev=o("If you want to go really deep into understanding these 2 modes, this "),Nt=a("a"),tv=o("article"),lv=o(" is highly recommended, as it has great diagrams, includes multiple benchmarks and profiler outputs on various hardware, explains all the nuances that you may need to know."),oh=h(),Ua=a("p"),av=o("Let\u2019s look at an actual benchmark:"),rh=h(),Ne=a("table"),or=a("thead"),he=a("tr"),Ia=a("th"),sv=o("Type"),iv=h(),rr=a("th"),ov=o("NVlink"),rv=h(),Sa=a("th"),nv=o("Time"),pv=h(),fe=a("tbody"),ce=a("tr"),Aa=a("td"),hv=o("2:DP"),fv=h(),nr=a("td"),cv=o("Y"),dv=h(),Oa=a("td"),uv=o("110s"),mv=h(),de=a("tr"),ja=a("td"),vv=o("2:DDP"),Pv=h(),pr=a("td"),wv=o("Y"),_v=h(),xa=a("td"),yv=o("101s"),bv=h(),ue=a("tr"),Ma=a("td"),gv=o("2:DDP"),Ev=h(),hr=a("td"),Dv=o("N"),Lv=h(),$a=a("td"),Tv=o("131s"),nh=h(),Na=a("p"),kv=o("Analysis:"),ph=h(),za=a("p"),Gv=o("Here DP is ~10% slower than DDP w/ NVlink, but ~15% faster than DDP w/o NVlink"),hh=h(),Ca=a("p"),Uv=o("The real difference will depend on how much data each GPU needs to sync with the others - the more there is to sync, the more a slow link will slow down the total runtime."),fh=h(),Ra=a("p"),Iv=o("Here is the full benchmark code and outputs:"),ch=h(),zt=a("p"),fr=a("code"),Sv=o("NCCL_P2P_DISABLE=1"),Av=o(" was used to disable the NVLink feature on the corresponding benchmark."),dh=h(),m(Ct.$$.fragment),uh=h(),g=a("p"),Ov=o("Hardware: 2x TITAN RTX 24GB each + NVlink with 2 NVLinks ("),cr=a("code"),jv=o("NV2"),xv=o(" in "),dr=a("code"),Mv=o("nvidia-smi topo -m"),$v=o(`)
Software: `),ur=a("code"),Nv=o("pytorch-1.8-to-be"),zv=o(" + "),mr=a("code"),Cv=o("cuda-11.0"),Rv=o(" / "),vr=a("code"),Zv=o("transformers==4.3.0.dev0"),mh=h(),me=a("h2"),ze=a("a"),Pr=a("span"),m(Rt.$$.fragment),Bv=h(),wr=a("span"),Vv=o("ZeRO Data Parallelism"),vh=h(),ve=a("p"),qv=o("ZeRO-powered data parallelism (ZeRO-DP) is described on the following diagram from this "),Zt=a("a"),Fv=o("blog post"),Wv=h(),Za=a("img"),Ph=h(),Ce=a("p"),Hv=o("It can be difficult to wrap one\u2019s head around it, but in reality the concept is quite simple. This is just the usual "),_r=a("code"),Yv=o("DataParallel"),Xv=o(" (DP), except, instead of replicating the full model params, gradients and optimizer states, each GPU stores only a slice of it.  And then at run-time when the full layer params are needed just for the given layer, all GPUs synchronize to give each other parts that they miss - this is it."),wh=h(),Ba=a("p"),Kv=o("Consider this simple model with 3 layers, where each layer has 3 params:"),_h=h(),m(Bt.$$.fragment),yh=h(),Va=a("p"),Jv=o("Layer La has weights a0, a1 and a2."),bh=h(),qa=a("p"),Qv=o("If we have 3 GPUs, the Sharded DDP (= Zero-DP) splits the model onto 3 GPUs like so:"),gh=h(),m(Vt.$$.fragment),Eh=h(),Fa=a("p"),eP=o("In a way this is the same horizontal slicing, as tensor parallelism, if you imagine the typical DNN diagram. Vertical slicing is where one puts whole layer-groups on different GPUs. But it\u2019s just the starting point."),Dh=h(),Wa=a("p"),tP=o("Now each of these GPUs will get the usual mini-batch as it works in DP:"),Lh=h(),m(qt.$$.fragment),Th=h(),Ha=a("p"),lP=o("The inputs are unmodified - they think they are going to be processed by the normal model."),kh=h(),Ya=a("p"),aP=o("First, the inputs hit the layer La."),Gh=h(),Xa=a("p"),sP=o("Let\u2019s focus just on GPU0: x0 needs a0, a1, a2 params to do its forward path, but GPU0 has only a0 - it gets sent a1 from GPU1 and a2 from GPU2, bringing all pieces of the model together."),Uh=h(),Ka=a("p"),iP=o("In parallel, GPU1 gets mini-batch x1 and it only has a1, but needs a0 and a2 params, so it gets those from GPU0 and GPU2."),Ih=h(),Ja=a("p"),oP=o("Same happens to GPU2 that gets input x2. It gets a0 and a1 from GPU0 and GPU1, and with its a2 it reconstructs the full tensor."),Sh=h(),Qa=a("p"),rP=o("All 3 GPUs get the full tensors reconstructed and a forward happens."),Ah=h(),es=a("p"),nP=o("As soon as the calculation is done, the data that is no longer needed gets dropped - it\u2019s only used during the calculation. The reconstruction is done efficiently via a pre-fetch."),Oh=h(),ts=a("p"),pP=o("And the whole process is repeated for layer Lb, then Lc forward-wise, and then backward Lc -> Lb -> La."),jh=h(),ls=a("p"),hP=o("To me this sounds like an efficient group backpacking weight distribution strategy:"),xh=h(),N=a("ol"),yr=a("li"),fP=o("person A carries the tent"),cP=h(),br=a("li"),dP=o("person B carries the stove"),uP=h(),gr=a("li"),mP=o("person C carries the axe"),Mh=h(),as=a("p"),vP=o("Now each night they all share what they have with others and get from others what they don\u2019t have, and in the morning they pack up their allocated type of gear and continue on their way. This is Sharded DDP / Zero DP."),$h=h(),ss=a("p"),PP=o("Compare this strategy to the simple one where each person has to carry their own tent, stove and axe, which would be far more inefficient. This is DataParallel (DP and DDP) in Pytorch."),Nh=h(),is=a("p"),wP=o("While reading the literature on this topic you may encounter the following synonyms: Sharded, Partitioned."),zh=h(),os=a("p"),_P=o("If you pay close attention the way ZeRO partitions the model\u2019s weights - it looks very similar to tensor parallelism which will be discussed later. This is because it partitions/shards each layer\u2019s weights, unlike vertical model parallelism which is discussed next."),Ch=h(),rs=a("p"),yP=o("Implementations:"),Rh=h(),z=a("ul"),ns=a("li"),Ft=a("a"),bP=o("DeepSpeed"),gP=o(" ZeRO-DP stages 1+2+3"),EP=h(),ps=a("li"),Wt=a("a"),DP=o("Fairscale"),LP=o(" ZeRO-DP stages 1+2+3"),TP=h(),Er=a("li"),Ht=a("a"),Dr=a("code"),kP=o("transformers"),GP=o(" integration"),Zh=h(),Pe=a("h2"),Re=a("a"),Lr=a("span"),m(Yt.$$.fragment),UP=h(),Tr=a("span"),IP=o("Naive Model Parallelism (Vertical) and Pipeline Parallelism"),Bh=h(),Ze=a("p"),SP=o("Naive Model Parallelism (MP) is where one spreads groups of model layers across multiple GPUs. The mechanism is relatively simple - switch the desired layers "),kr=a("code"),AP=o(".to()"),OP=o(" the desired devices and now whenever the data goes in and out those layers switch the data to the same device as the layer and leave the rest unmodified."),Vh=h(),hs=a("p"),jP=o("We refer to it as Vertical MP, because if you remember how most models are drawn, we slice the layers vertically. For example, if the following diagram shows an 8-layer model:"),qh=h(),m(Xt.$$.fragment),Fh=h(),fs=a("p"),xP=o("we just sliced it in 2 vertically, placing layers 0-3 onto GPU0 and 4-7 to GPU1."),Wh=h(),cs=a("p"),MP=o("Now while data travels from layer 0 to 1, 1 to 2 and 2 to 3 this is just the normal model. But when data needs to pass from layer 3 to layer 4 it needs to travel from GPU0 to GPU1 which introduces a communication overhead. If the participating GPUs are on the same compute node (e.g. same physical machine) this copying is pretty fast, but if the GPUs are located on different compute nodes (e.g. multiple machines) the communication overhead could be significantly larger."),Hh=h(),ds=a("p"),$P=o("Then layers 4 to 5 to 6 to 7 are as a normal model would have and when the 7th layer completes we often need to send the data back to layer 0 where the labels are (or alternatively send the labels to the last layer). Now the loss can be computed and the optimizer can do its work."),Yh=h(),us=a("p"),NP=o("Problems:"),Xh=h(),Be=a("ul"),Gr=a("li"),zP=o("the main deficiency and why this one is called \u201Cnaive\u201D MP, is that all but one GPU is idle at any given moment. So if 4 GPUs are used, it\u2019s almost identical to quadrupling the amount of memory of a single GPU, and ignoring the rest of the hardware. Plus there is the overhead of copying the data between devices. So 4x 6GB cards will be able to accommodate the same size as 1x 24GB card using naive MP, except the latter will complete the training faster, since it doesn\u2019t have the data copying overhead. But, say, if you have 40GB cards and need to fit a 45GB model you can with 4x 40GB cards (but barely because of the gradient and optimizer states)"),CP=h(),Ur=a("li"),RP=o("shared embeddings may need to get copied back and forth between GPUs."),Kh=h(),ms=a("p"),ZP=o("Pipeline Parallelism (PP) is almost identical to a naive MP, but it solves the GPU idling problem, by chunking the incoming batch into micro-batches and artificially creating a pipeline, which allows different GPUs to concurrently participate in the computation process."),Jh=h(),Ve=a("p"),BP=o("The following illustration from the "),Kt=a("a"),VP=o("GPipe paper"),qP=o(" shows the naive MP on the top, and PP on the bottom:"),Qh=h(),vs=a("p"),Ps=a("img"),ef=h(),ws=a("p"),FP=o("It\u2019s easy to see from the bottom diagram how PP has less dead zones, where GPUs are idle. The idle parts are referred to as the \u201Cbubble\u201D."),tf=h(),_s=a("p"),WP=o("Both parts of the diagram show a parallelism that is of degree 4. That is 4 GPUs are participating in the pipeline. So there is the forward path of 4 pipe stages F0, F1, F2 and F3 and then the return reverse order backward path of B3, B2, B1 and B0."),lf=h(),C=a("p"),HP=o("PP introduces a new hyper-parameter to tune and it\u2019s "),Ir=a("code"),YP=o("chunks"),XP=o(" which defines how many chunks of data are sent in a sequence through the same pipe stage. For example, in the bottomw diagram you can see that "),Sr=a("code"),KP=o("chunks=4"),JP=o(". GPU0 performs the same forward path on chunk 0, 1, 2 and 3 (F0,0, F0,1, F0,2, F0,3) and then it waits for other GPUs to do their work and only when their work is starting to be complete, GPU0 starts to work again doing the backward path for chunks 3, 2, 1 and 0 (B0,3, B0,2, B0,1, B0,0)."),af=h(),qe=a("p"),QP=o("Note that conceptually this is the same concept as gradient accumulation steps (GAS). Pytorch uses "),Ar=a("code"),e1=o("chunks"),t1=o(", whereas DeepSpeed refers to the same hyper-parameter as GAS."),sf=h(),Fe=a("p"),l1=o("Because of the chunks, PP introduces the concept of micro-batches (MBS). DP splits the global data batch size into mini-batches, so if you have a DP degree of 4, a global batch size of 1024 gets split up into 4 mini-batches of 256 each (1024/4). And if the number of "),Or=a("code"),a1=o("chunks"),s1=o(" (or GAS) is 32 we end up with a micro-batch size of 8 (256/32). Each Pipeline stage works with a single micro-batch at a time."),of=h(),R=a("p"),i1=o("To calculate the global batch size of the DP + PP setup we then do: "),jr=a("code"),o1=o("mbs*chunks*dp_degree"),r1=o(" ("),xr=a("code"),n1=o("8*32*4=1024"),p1=o(")."),rf=h(),ys=a("p"),h1=o("Let\u2019s go back to the diagram."),nf=h(),Z=a("p"),f1=o("With "),Mr=a("code"),c1=o("chunks=1"),d1=o(" you end up with the naive MP, which is very inefficient. With a very large "),$r=a("code"),u1=o("chunks"),m1=o(" value you end up with tiny micro-batch sizes which could be not every efficient either. So one has to experiment to find the value that leads to the highest efficient utilization of the gpus."),pf=h(),S=a("p"),v1=o("While the diagram shows that there is a bubble of \u201Cdead\u201D time that can\u2019t be parallelized because the last "),Nr=a("code"),P1=o("forward"),w1=o(" stage has to wait for "),zr=a("code"),_1=o("backward"),y1=o(" to complete the pipeline, the purpose of finding the best value for "),Cr=a("code"),b1=o("chunks"),g1=o(" is to enable a high concurrent GPU utilization across all participating GPUs which translates to minimizing the size of the bubble."),hf=h(),bs=a("p"),E1=o("There are 2 groups of solutions - the traditional Pipeline API and the more modern solutions that make things much easier for the end user."),ff=h(),gs=a("p"),D1=o("Traditional Pipeline API solutions:"),cf=h(),A=a("ul"),Rr=a("li"),L1=o("PyTorch"),T1=h(),Zr=a("li"),k1=o("FairScale"),G1=h(),Br=a("li"),U1=o("DeepSpeed"),I1=h(),Vr=a("li"),S1=o("Megatron-LM"),df=h(),Es=a("p"),A1=o("Modern solutions:"),uf=h(),We=a("ul"),qr=a("li"),O1=o("Varuna"),j1=h(),Fr=a("li"),x1=o("Sagemaker"),mf=h(),Ds=a("p"),M1=o("Problems with traditional Pipeline API solutions:"),vf=h(),O=a("ul"),Jt=a("li"),$1=o("have to modify the model quite heavily, because Pipeline requires one to rewrite the normal flow of modules into a "),Wr=a("code"),N1=o("nn.Sequential"),z1=o(" sequence of the same, which may require changes to the design of the model."),C1=h(),Ls=a("li"),R1=o("currently the Pipeline API is very restricted. If you had a bunch of python variables being passed in the very first stage of the Pipeline, you will have to find a way around it. Currently, the pipeline interface requires either a single Tensor or a tuple of Tensors as the only input and output. These tensors must have a batch size as the very first dimension, since pipeline is going to chunk the mini batch into micro-batches. Possible improvements are being discussed here "),Qt=a("a"),Z1=o("https://github.com/pytorch/pytorch/pull/50693"),B1=h(),Hr=a("li"),V1=o("conditional control flow at the level of pipe stages is not possible - e.g., Encoder-Decoder models like T5 require special workarounds to handle a conditional encoder stage."),q1=h(),Yr=a("li"),F1=o("have to arrange each layer so that the output of one model becomes an input to the other model."),Pf=h(),Ts=a("p"),W1=o("We are yet to experiment with Varuna and SageMaker but their papers report that they have overcome the list of problems mentioned above and that they require much smaller changes to the user\u2019s model."),wf=h(),ks=a("p"),H1=o("Implementations:"),_f=h(),u=a("ul"),el=a("li"),tl=a("a"),Y1=o("Pytorch"),X1=o(" (initial support in pytorch-1.8, and progressively getting improved in 1.9 and more so in 1.10). Some "),ll=a("a"),K1=o("examples"),J1=h(),Xr=a("li"),al=a("a"),Q1=o("FairScale"),ew=h(),Kr=a("li"),sl=a("a"),tw=o("DeepSpeed"),lw=h(),Gs=a("li"),il=a("a"),aw=o("Megatron-LM"),sw=o(" has an internal implementation - no API."),iw=h(),Jr=a("li"),ol=a("a"),ow=o("Varuna"),rw=h(),Us=a("li"),rl=a("a"),nw=o("SageMaker"),pw=o(" - this is a proprietary solution that can only be used on AWS."),hw=h(),Is=a("li"),nl=a("a"),fw=o("OSLO"),cw=o(" - this is implemented based on the Hugging Face Transformers."),yf=h(),He=a("p"),dw=o("\u{1F917} Transformers status: as of this writing none of the models supports full-PP. GPT2 and T5 models have naive MP support. The main obstacle is being unable to convert the models to "),Qr=a("code"),uw=o("nn.Sequential"),mw=o(" and have all the inputs to be Tensors. This is because currently the models include many features that make the conversion very complicated, and will need to be removed to accomplish that."),bf=h(),Ss=a("p"),vw=o("Other approaches:"),gf=h(),we=a("p"),Pw=o("DeepSpeed, Varuna and SageMaker use the concept of an "),pl=a("a"),ww=o("Interleaved Pipeline"),_w=h(),As=a("img"),Ef=h(),Os=a("p"),yw=o("Here the bubble (idle time) is further minimized by prioritizing backward passes."),Df=h(),js=a("p"),bw=o("Varuna further tries to improve the schedule by using simulations to discover the most efficient scheduling."),Lf=h(),Ye=a("p"),gw=o("OSLO has pipeline parallelism implementation based on the Transformers without "),en=a("code"),Ew=o("nn.Sequential"),Dw=o(" converting."),Tf=h(),_e=a("h2"),Xe=a("a"),tn=a("span"),m(hl.$$.fragment),Lw=h(),ln=a("span"),Tw=o("Tensor Parallelism"),kf=h(),xs=a("p"),kw=o("In Tensor Parallelism each GPU processes only a slice of a tensor and only aggregates the full tensor for operations that require the whole thing."),Gf=h(),B=a("p"),Gw=o("In this section we use concepts and diagrams from the "),fl=a("a"),Uw=o("Megatron-LM"),Iw=o(" paper: "),cl=a("a"),Sw=o("Efficient Large-Scale Language Model Training on GPU Clusters"),Aw=o("."),Uf=h(),V=a("p"),Ow=o("The main building block of any transformer is a fully connected "),an=a("code"),jw=o("nn.Linear"),xw=o(" followed by a nonlinear activation "),sn=a("code"),Mw=o("GeLU"),$w=o("."),If=h(),L=a("p"),Nw=o("Following the Megatron\u2019s paper notation, we can write the dot-product part of it as "),on=a("code"),zw=o("Y = GeLU(XA)"),Cw=o(", where "),rn=a("code"),Rw=o("X"),Zw=o(" and "),nn=a("code"),Bw=o("Y"),Vw=o(" are the input and output vectors, and "),pn=a("code"),qw=o("A"),Fw=o(" is the weight matrix."),Sf=h(),dl=a("p"),Ww=o(`If we look at the computation in matrix form, it\u2019s easy to see how the matrix multiplication can be split between multiple GPUs:
`),Ms=a("img"),Af=h(),d=a("p"),Hw=o("If we split the weight matrix "),hn=a("code"),Yw=o("A"),Xw=o(" column-wise across "),fn=a("code"),Kw=o("N"),Jw=o(" GPUs and perform matrix multiplications "),cn=a("code"),Qw=o("XA_1"),e2=o(" through "),dn=a("code"),t2=o("XA_n"),l2=o(" in parallel, then we will end up with "),un=a("code"),a2=o("N"),s2=o(" output vectors "),mn=a("code"),i2=o("Y_1, Y_2, ..., Y_n"),o2=o(" which can be fed into "),vn=a("code"),r2=o("GeLU"),n2=o(` independently:
`),$s=a("img"),Of=h(),ul=a("p"),p2=o(`Using this principle, we can update an MLP of arbitrary depth, without the need for any synchronization between GPUs until the very end, where we need to reconstruct the output vector from shards. The Megatron-LM paper authors provide a helpful illustration for that:
`),Ns=a("img"),jf=h(),ml=a("p"),h2=o(`Parallelizing the multi-headed attention layers is even simpler, since they are already inherently parallel, due to having multiple independent heads!
`),zs=a("img"),xf=h(),Cs=a("p"),f2=o("Special considerations: TP requires very fast network, and therefore it\u2019s not advisable to do TP across more than one node. Practically, if a node has 4 GPUs, the highest TP degree is therefore 4. If you need a TP degree of 8, you need to use nodes that have at least 8 GPUs."),Mf=h(),q=a("p"),c2=o("This section is based on the original much more "),vl=a("a"),d2=o("detailed TP overview"),u2=o(`.
by `),Pl=a("a"),m2=o("@anton-l"),v2=o("."),$f=h(),Rs=a("p"),P2=o("SageMaker combines TP with DP for a more efficient processing."),Nf=h(),Zs=a("p"),w2=o("Alternative names:"),zf=h(),Bs=a("ul"),Vs=a("li"),_2=o("DeepSpeed calls it "),wl=a("a"),y2=o("tensor slicing"),Cf=h(),qs=a("p"),b2=o("Implementations:"),Rf=h(),j=a("ul"),Fs=a("li"),_l=a("a"),g2=o("Megatron-LM"),E2=o(" has an internal implementation, as it\u2019s very model-specific"),D2=h(),Ws=a("li"),yl=a("a"),L2=o("parallelformers"),T2=o(" (only inference at the moment)"),k2=h(),Hs=a("li"),bl=a("a"),G2=o("SageMaker"),U2=o(" - this is a proprietary solution that can only be used on AWS."),I2=h(),Ys=a("li"),gl=a("a"),S2=o("OSLO"),A2=o(" has the tensor parallelism implementation based on the Transformers."),Zf=h(),Xs=a("p"),O2=o("\u{1F917} Transformers status:"),Bf=h(),F=a("ul"),Pn=a("li"),j2=o("core: not yet implemented in the core"),x2=h(),El=a("li"),M2=o("but if you want inference "),Dl=a("a"),$2=o("parallelformers"),N2=o(" provides this support for most of our models. So until this is implemented in the core you can use theirs. And hopefully training mode will be supported too."),z2=h(),Ks=a("li"),C2=o("Deepspeed-Inference also supports our BERT, GPT-2, and GPT-Neo models in their super-fast CUDA-kernel-based inference mode, see more "),Ll=a("a"),R2=o("here"),Vf=h(),ye=a("h2"),Ke=a("a"),wn=a("span"),m(Tl.$$.fragment),Z2=h(),_n=a("span"),B2=o("DP+PP"),qf=h(),Je=a("p"),V2=o("The following diagram from the DeepSpeed "),kl=a("a"),q2=o("pipeline tutorial"),F2=o(" demonstrates how one combines DP with PP."),Ff=h(),Js=a("p"),Qs=a("img"),Wf=h(),ei=a("p"),W2=o("Here it\u2019s important to see how DP rank 0 doesn\u2019t see GPU2 and DP rank 1 doesn\u2019t see GPU3. To DP there is just GPUs 0 and 1 where it feeds data as if there were just 2 GPUs. GPU0 \u201Csecretly\u201D offloads some of its load to GPU2 using PP. And GPU1 does the same by enlisting GPU3 to its aid."),Hf=h(),ti=a("p"),H2=o("Since each dimension requires at least 2 GPUs, here you\u2019d need at least 4 GPUs."),Yf=h(),li=a("p"),Y2=o("Implementations:"),Xf=h(),T=a("ul"),yn=a("li"),Gl=a("a"),X2=o("DeepSpeed"),K2=h(),bn=a("li"),Ul=a("a"),J2=o("Megatron-LM"),Q2=h(),gn=a("li"),Il=a("a"),e_=o("Varuna"),t_=h(),En=a("li"),Sl=a("a"),l_=o("SageMaker"),a_=h(),Dn=a("li"),Al=a("a"),s_=o("OSLO"),Kf=h(),ai=a("p"),i_=o("\u{1F917} Transformers status: not yet implemented"),Jf=h(),be=a("h2"),Qe=a("a"),Ln=a("span"),m(Ol.$$.fragment),o_=h(),Tn=a("span"),r_=o("DP+PP+TP"),Qf=h(),si=a("p"),n_=o("To get an even more efficient training a 3D parallelism is used where PP is combined with TP and DP. This can be seen in the following diagram."),ec=h(),ii=a("p"),oi=a("img"),tc=h(),et=a("p"),p_=o("This diagram is from a blog post "),jl=a("a"),h_=o("3D parallelism: Scaling to trillion-parameter models"),f_=o(", which is a good read as well."),lc=h(),ri=a("p"),c_=o("Since each dimension requires at least 2 GPUs, here you\u2019d need at least 8 GPUs."),ac=h(),ni=a("p"),d_=o("Implementations:"),sc=h(),k=a("ul"),pi=a("li"),xl=a("a"),u_=o("DeepSpeed"),m_=o(" - DeepSpeed also includes an even more efficient DP, which they call ZeRO-DP."),v_=h(),kn=a("li"),Ml=a("a"),P_=o("Megatron-LM"),w_=h(),Gn=a("li"),$l=a("a"),__=o("Varuna"),y_=h(),Un=a("li"),Nl=a("a"),b_=o("SageMaker"),g_=h(),In=a("li"),zl=a("a"),E_=o("OSLO"),ic=h(),hi=a("p"),D_=o("\u{1F917} Transformers status: not yet implemented, since we have no PP and TP."),oc=h(),ge=a("h2"),tt=a("a"),Sn=a("span"),m(Cl.$$.fragment),L_=h(),An=a("span"),T_=o("ZeRO DP+PP+TP"),rc=h(),lt=a("p"),k_=o("One of the main features of DeepSpeed is ZeRO, which is a super-scalable extension of DP. It has already been discussed in "),fi=a("a"),G_=o("ZeRO Data Parallelism"),U_=o(". Normally it\u2019s a standalone feature that doesn\u2019t require PP or TP. But it can be combined with PP and TP."),nc=h(),ci=a("p"),I_=o("When ZeRO-DP is combined with PP (and optionally TP) it typically enables only ZeRO stage 1 (optimizer sharding)."),pc=h(),di=a("p"),S_=o("While it\u2019s theoretically possible to use ZeRO stage 2 (gradient sharding) with Pipeline Parallelism, it will have bad performance impacts. There would need to be an additional reduce-scatter collective for every micro-batch to aggregate the gradients before sharding, which adds a potentially significant communication overhead. By nature of Pipeline Parallelism, small micro-batches are used and instead the focus is on trying to balance arithmetic intensity (micro-batch size) with minimizing the Pipeline bubble (number of micro-batches). Therefore those communication costs are going to hurt."),hc=h(),at=a("p"),A_=o("In addition, There are already fewer layers than normal due to PP and so the memory savings won\u2019t be huge. PP already reduces gradient size by "),On=a("code"),O_=o("1/PP"),j_=o(", and so gradient sharding savings on top of that are less significant than pure DP."),fc=h(),ui=a("p"),x_=o("ZeRO stage 3 is not a good choice either for the same reason - more inter-node communications required."),cc=h(),mi=a("p"),M_=o("And since we have ZeRO, the other benefit is ZeRO-Offload. Since this is stage 1 optimizer states can be offloaded to CPU."),dc=h(),vi=a("p"),$_=o("Implementations:"),uc=h(),st=a("ul"),it=a("li"),Rl=a("a"),N_=o("Megatron-DeepSpeed"),z_=o(" and "),Zl=a("a"),C_=o("Megatron-Deepspeed from BigScience"),R_=o(", which is the fork of the former repo."),Z_=h(),jn=a("li"),Bl=a("a"),B_=o("OSLO"),mc=h(),Pi=a("p"),V_=o("Important papers:"),vc=h(),wi=a("ul"),xn=a("li"),Vl=a("a"),q_=o("Using DeepSpeed and Megatron to Train Megatron-Turing NLG 530B, A Large-Scale Generative Language Model"),Pc=h(),_i=a("p"),F_=o("\u{1F917} Transformers status: not yet implemented, since we have no PP and TP."),wc=h(),Ee=a("h2"),ot=a("a"),Mn=a("span"),m(ql.$$.fragment),W_=h(),$n=a("span"),H_=o("FlexFlow"),_c=h(),Fl=a("p"),Wl=a("a"),Y_=o("FlexFlow"),X_=o(" also solves the parallelization problem in a slightly different approach."),yc=h(),Hl=a("p"),K_=o("Paper: "),Yl=a("a"),J_=o("\u201CBeyond Data and Model Parallelism for Deep Neural Networks\u201D by Zhihao Jia, Matei Zaharia, Alex Aiken"),bc=h(),yi=a("p"),Q_=o("It performs a sort of 4D Parallelism over Sample-Operator-Attribute-Parameter."),gc=h(),x=a("ol"),Nn=a("li"),ey=o("Sample = Data Parallelism (sample-wise parallel)"),ty=h(),zn=a("li"),ly=o("Operator = Parallelize a single operation into several sub-operations"),ay=h(),Cn=a("li"),sy=o("Attribute = Data Parallelism (length-wise parallel)"),iy=h(),Rn=a("li"),oy=o("Parameter = Model Parallelism (regardless of dimension - horizontal or vertical)"),Ec=h(),bi=a("p"),ry=o("Examples:"),Dc=h(),gi=a("ul"),Zn=a("li"),ny=o("Sample"),Lc=h(),Ei=a("p"),py=o("Let\u2019s take 10 batches of sequence length 512. If we parallelize them by sample dimension into 2 devices, we get 10 x 512 which becomes be 5 x 2 x 512."),Tc=h(),Di=a("ul"),Bn=a("li"),hy=o("Operator"),kc=h(),Li=a("p"),fy=o("If we perform layer normalization, we compute std first and mean second, and then we can normalize data. Operator parallelism allows computing std and mean in parallel. So if we parallelize them by operator dimension into 2 devices (cuda:0, cuda:1), first we copy input data into both devices, and cuda:0 computes std, cuda:1 computes mean at the same time."),Gc=h(),Ti=a("ul"),Vn=a("li"),cy=o("Attribute"),Uc=h(),ki=a("p"),dy=o("We have 10 batches of 512 length. If we parallelize them by attribute dimension into 2 devices, 10 x 512 will be 10 x 2 x 256."),Ic=h(),Gi=a("ul"),qn=a("li"),uy=o("Parameter"),Sc=h(),Ui=a("p"),my=o("It is similar with tensor model parallelism or naive layer-wise model parallelism."),Ac=h(),Ii=a("p"),Si=a("img"),Oc=h(),Ai=a("p"),vy=o("The significance of this framework is that it takes resources like (1) GPU/TPU/CPU vs. (2) RAM/DRAM vs. (3) fast-intra-connect/slow-inter-connect and it automatically optimizes all these  algorithmically deciding which parallelisation to use where."),jc=h(),Oi=a("p"),Py=o("One very important aspect is that FlexFlow is designed for optimizing DNN parallelizations for models with static and fixed workloads, since models with dynamic behavior may prefer different parallelization strategies across iterations."),xc=h(),ji=a("p"),wy=o("So the promise is very attractive - it runs a 30min simulation on the cluster of choice and it comes up with the best strategy to utilise this specific environment. If you add/remove/replace any parts it\u2019ll run and re-optimize the plan for that. And then you can train. A different setup will have its own custom optimization."),Mc=h(),rt=a("p"),_y=o("\u{1F917} Transformers status: not yet integrated. We already have our models FX-trace-able via "),Xl=a("a"),yy=o("transformers.utils.fx"),by=o(", which is a prerequisite for FlexFlow, so someone needs to figure out what needs to be done to make FlexFlow work with our models."),$c=h(),De=a("h2"),nt=a("a"),Fn=a("span"),m(Kl.$$.fragment),gy=h(),Wn=a("span"),Ey=o("Which Strategy To Use When"),Nc=h(),xi=a("p"),Dy=o("Here is a very rough outline at which parallelism strategy to use when. The first on each list is typically faster."),zc=h(),Mi=a("p"),Hn=a("strong"),Ly=o("\u21E8 Single GPU"),Cc=h(),W=a("ul"),Jl=a("li"),Yn=a("p"),Ty=o("Model fits onto a single GPU:"),ky=h(),Xn=a("ol"),Kn=a("li"),Gy=o("Normal use"),Uy=h(),Ql=a("li"),Jn=a("p"),Iy=o("Model doesn\u2019t fit onto a single GPU:"),Sy=h(),ea=a("ol"),Qn=a("li"),Ay=o("ZeRO + Offload CPU and optionally NVMe"),Oy=h(),ep=a("li"),jy=o("as above plus Memory Centric Tiling (see below for details) if the largest layer can\u2019t fit into a single GPU"),xy=h(),tp=a("li"),lp=a("p"),My=o("Largest Layer not fitting into a single GPU:"),Rc=h(),$i=a("ol"),Le=a("li"),$y=o("ZeRO - Enable "),ta=a("a"),Ny=o("Memory Centric Tiling"),zy=o(" (MCT). It allows you to run arbitrarily large layers by automatically splitting them and executing them sequentially. MCT reduces the number of parameters that are live on a GPU, but it does not affect the activation memory. As this need is very rare as of this writing a manual override of "),ap=a("code"),Cy=o("torch.nn.Linear"),Ry=o(" needs to be done by the user."),Zc=h(),Ni=a("p"),sp=a("strong"),Zy=o("\u21E8 Single Node / Multi-GPU"),Bc=h(),H=a("ul"),la=a("li"),ip=a("p"),By=o("Model fits onto a single GPU:"),Vy=h(),aa=a("ol"),op=a("li"),qy=o("DDP - Distributed DP"),Fy=h(),rp=a("li"),Wy=o("ZeRO - may or may not be faster depending on the situation and configuration used"),Hy=h(),sa=a("li"),np=a("p"),Yy=o("Model doesn\u2019t fit onto a single GPU:"),Xy=h(),Te=a("ol"),pp=a("li"),hp=a("p"),Ky=o("PP"),Jy=h(),fp=a("li"),cp=a("p"),Qy=o("ZeRO"),eb=h(),ke=a("li"),dp=a("p"),tb=o("TP"),lb=h(),up=a("p"),ab=o("With very fast intra-node connectivity of NVLINK or NVSwitch all three should be mostly on par, without these PP will be faster than TP or ZeRO. The degree of TP may also make a difference. Best to experiment to find the winner on your particular setup."),sb=h(),mp=a("p"),ib=o("TP is almost always used within a single node. That is TP size <= gpus per node."),ob=h(),ia=a("li"),vp=a("p"),rb=o("Largest Layer not fitting into a single GPU:"),nb=h(),oa=a("ol"),Pp=a("li"),pb=o("If not using ZeRO - must use TP, as PP alone won\u2019t be able to fit."),hb=h(),wp=a("li"),fb=o("With ZeRO see the same entry for \u201CSingle GPU\u201D above"),Vc=h(),zi=a("p"),_p=a("strong"),cb=o("\u21E8 Multi-Node / Multi-GPU"),qc=h(),pt=a("ul"),ra=a("li"),yp=a("p"),db=o("When you have fast inter-node connectivity:"),ub=h(),na=a("ol"),bp=a("li"),mb=o("ZeRO - as it requires close to no modifications to the model"),vb=h(),gp=a("li"),Pb=o("PP+TP+DP - less communications, but requires massive changes to the model"),wb=h(),pa=a("li"),Ep=a("p"),_b=o("when you have slow inter-node connectivity and still low on GPU memory:"),yb=h(),Dp=a("ol"),Lp=a("li"),bb=o("DP+PP+TP+ZeRO-1"),this.h()},l(e){const n=M6('[data-svelte="svelte-1phssyn"]',document.head);te=s(n,"META",{name:!0,content:!0}),n.forEach(t),Sp=f(e),le=s(e,"H1",{class:!0});var Wc=i(le);Ge=s(Wc,"A",{id:!0,class:!0,href:!0});var ng=i(Ge);no=s(ng,"SPAN",{});var pg=i(no);v(vt.$$.fragment,pg),pg.forEach(t),ng.forEach(t),Qd=f(Wc),po=s(Wc,"SPAN",{});var hg=i(po);eu=r(hg,"Efficient Training on Multiple GPUs"),hg.forEach(t),Wc.forEach(t),Ap=f(e),ha=s(e,"P",{});var fg=i(ha);tu=r(fg,"When training on a single GPU is too slow or the model weights don\u2019t fit in a single GPUs memory we use a mutli-GPU setup. Switching from a single GPU to multiple requires some form of parallelism as the work needs to be distributed. There are several techniques to achieve parallism such as data, tensor, or pipeline parallism. However, there is no one solution to fit them all and which settings works best depends on the hardware you are running on. While the main concepts most likely will apply to any other framework, this article is focused on PyTorch-based implementations."),fg.forEach(t),Op=f(e),fa=s(e,"P",{});var cg=i(fa);lu=r(cg,"We will first discuss in depth various 1D parallelism techniques and their pros and cons and then look at how they can be combined into 2D and 3D parallelism to enable an even faster training and to support even bigger models. Various other powerful alternative approaches will be presented."),cg.forEach(t),jp=f(e),ae=s(e,"H2",{class:!0});var Hc=i(ae);Ue=s(Hc,"A",{id:!0,class:!0,href:!0});var dg=i(Ue);ho=s(dg,"SPAN",{});var ug=i(ho);v(Pt.$$.fragment,ug),ug.forEach(t),dg.forEach(t),au=f(Hc),fo=s(Hc,"SPAN",{});var mg=i(fo);su=r(mg,"Concepts"),mg.forEach(t),Hc.forEach(t),xp=f(e),ca=s(e,"P",{});var vg=i(ca);iu=r(vg,"The following is the brief description of the main concepts that will be described later in depth in this document."),vg.forEach(t),Mp=f(e),E=s(e,"OL",{});var Y=i(E);da=s(Y,"LI",{});var gb=i(da);co=s(gb,"STRONG",{});var Pg=i(co);ou=r(Pg,"DataParallel (DP)"),Pg.forEach(t),ru=r(gb," - the same setup is replicated multiple times, and each being fed a slice of the data. The processing is done in parallel and all setups are synchronized at the end of each training step."),gb.forEach(t),nu=f(Y),ua=s(Y,"LI",{});var Eb=i(ua);uo=s(Eb,"STRONG",{});var wg=i(uo);pu=r(wg,"TensorParallel (TP)"),wg.forEach(t),hu=r(Eb," - each tensor is split up into multiple chunks, so instead of having the whole tensor reside on a single gpu, each shard of the tensor resides on its designated gpu. During processing each shard gets processed separately and in parallel on different GPUs and the results are synced at the end of the step. This is what one may call horizontal parallelism, as the splitting happens on horizontal level."),Eb.forEach(t),fu=f(Y),ma=s(Y,"LI",{});var Db=i(ma);mo=s(Db,"STRONG",{});var _g=i(mo);cu=r(_g,"PipelineParallel (PP)"),_g.forEach(t),du=r(Db," - the model is split up vertically (layer-level) across multiple GPUs, so that only one or several layers of the model are places on a single gpu. Each gpu processes in parallel different stages of the pipeline and working on a small chunk of the batch."),Db.forEach(t),uu=f(Y),va=s(Y,"LI",{});var Lb=i(va);vo=s(Lb,"STRONG",{});var yg=i(vo);mu=r(yg,"Zero Redundancy Optimizer (ZeRO)"),yg.forEach(t),vu=r(Lb," - Also performs sharding of the tensors somewhat similar to TP, except the whole tensor gets reconstructed in time for a forward or backward computation, therefore the model doesn\u2019t need to be modified. It also supports various offloading techniques to compensate for limited GPU memory."),Lb.forEach(t),Pu=f(Y),Pa=s(Y,"LI",{});var Tb=i(Pa);Po=s(Tb,"STRONG",{});var bg=i(Po);wu=r(bg,"Sharded DDP"),bg.forEach(t),_u=r(Tb," - is another name for the foundational ZeRO concept as used by various other implementations of ZeRO."),Tb.forEach(t),Y.forEach(t),$p=f(e),wa=s(e,"P",{});var gg=i(wa);yu=r(gg,"Before diving deeper into the specifics of each concept we first have a look at the rough decision process when training large models on a large infrastructure."),gg.forEach(t),Np=f(e),se=s(e,"H2",{class:!0});var Yc=i(se);Ie=s(Yc,"A",{id:!0,class:!0,href:!0});var Eg=i(Ie);wo=s(Eg,"SPAN",{});var Dg=i(wo);v(wt.$$.fragment,Dg),Dg.forEach(t),Eg.forEach(t),bu=f(Yc),_o=s(Yc,"SPAN",{});var Lg=i(_o);gu=r(Lg,"Scalability Strategy"),Lg.forEach(t),Yc.forEach(t),zp=f(e),_a=s(e,"P",{});var Tg=i(_a);yo=s(Tg,"STRONG",{});var kg=i(yo);Eu=r(kg,"\u21E8 Single Node / Multi-GPU"),kg.forEach(t),Tg.forEach(t),Cp=f(e),$=s(e,"UL",{});var Ci=i($);_t=s(Ci,"LI",{});var Xc=i(_t);bo=s(Xc,"P",{});var Gg=i(bo);Du=r(Gg,"Model fits onto a single GPU:"),Gg.forEach(t),Lu=f(Xc),yt=s(Xc,"OL",{});var Kc=i(yt);go=s(Kc,"LI",{});var Ug=i(go);Tu=r(Ug,"DDP - Distributed DP"),Ug.forEach(t),ku=f(Kc),Eo=s(Kc,"LI",{});var Ig=i(Eo);Gu=r(Ig,"ZeRO - may or may not be faster depending on the situation and configuration used"),Ig.forEach(t),Kc.forEach(t),Xc.forEach(t),Uu=f(Ci),bt=s(Ci,"LI",{});var Jc=i(bt);Do=s(Jc,"P",{});var Sg=i(Do);Iu=r(Sg,"Model doesn\u2019t fit onto a single GPU:"),Sg.forEach(t),Su=f(Jc),ie=s(Jc,"OL",{});var Ri=i(ie);Lo=s(Ri,"LI",{});var Ag=i(Lo);To=s(Ag,"P",{});var Og=i(To);Au=r(Og,"PP"),Og.forEach(t),Ag.forEach(t),Ou=f(Ri),ko=s(Ri,"LI",{});var jg=i(ko);Go=s(jg,"P",{});var xg=i(Go);ju=r(xg,"ZeRO"),xg.forEach(t),jg.forEach(t),xu=f(Ri),oe=s(Ri,"LI",{});var Zi=i(oe);Uo=s(Zi,"P",{});var Mg=i(Uo);Mu=r(Mg,"TP"),Mg.forEach(t),$u=f(Zi),Io=s(Zi,"P",{});var $g=i(Io);Nu=r($g,"With very fast intra-node connectivity of NVLINK or NVSwitch all three should be mostly on par, without these PP will be faster than TP or ZeRO. The degree of TP may also make a difference. Best to experiment to find the winner on your particular setup."),$g.forEach(t),zu=f(Zi),So=s(Zi,"P",{});var Ng=i(So);Cu=r(Ng,"TP is almost always used within a single node. That is TP size <= gpus per node."),Ng.forEach(t),Zi.forEach(t),Ri.forEach(t),Jc.forEach(t),Ru=f(Ci),gt=s(Ci,"LI",{});var Qc=i(gt);Ao=s(Qc,"P",{});var zg=i(Ao);Zu=r(zg,"Largest Layer not fitting into a single GPU:"),zg.forEach(t),Bu=f(Qc),Et=s(Qc,"OL",{});var ed=i(Et);Oo=s(ed,"LI",{});var Cg=i(Oo);Vu=r(Cg,"If not using ZeRO - must use TP, as PP alone won\u2019t be able to fit."),Cg.forEach(t),qu=f(ed),jo=s(ed,"LI",{});var Rg=i(jo);Fu=r(Rg,"With ZeRO see the same entry for \u201CSingle GPU\u201D above"),Rg.forEach(t),ed.forEach(t),Qc.forEach(t),Ci.forEach(t),Rp=f(e),ya=s(e,"P",{});var Zg=i(ya);xo=s(Zg,"STRONG",{});var Bg=i(xo);Wu=r(Bg,"\u21E8 Multi-Node / Multi-GPU"),Bg.forEach(t),Zg.forEach(t),Zp=f(e),Se=s(e,"UL",{});var td=i(Se);Dt=s(td,"LI",{});var ld=i(Dt);Mo=s(ld,"P",{});var Vg=i(Mo);Hu=r(Vg,"When you have fast inter-node connectivity:"),Vg.forEach(t),Yu=f(ld),Lt=s(ld,"OL",{});var ad=i(Lt);$o=s(ad,"LI",{});var qg=i($o);Xu=r(qg,"ZeRO - as it requires close to no modifications to the model"),qg.forEach(t),Ku=f(ad),No=s(ad,"LI",{});var Fg=i(No);Ju=r(Fg,"PP+TP+DP - less communications, but requires massive changes to the model"),Fg.forEach(t),ad.forEach(t),ld.forEach(t),Qu=f(td),Tt=s(td,"LI",{});var sd=i(Tt);zo=s(sd,"P",{});var Wg=i(zo);em=r(Wg,"when you have slow inter-node connectivity and still low on GPU memory:"),Wg.forEach(t),tm=f(sd),Co=s(sd,"OL",{});var Hg=i(Co);Ro=s(Hg,"LI",{});var Yg=i(Ro);lm=r(Yg,"DP+PP+TP+ZeRO-1"),Yg.forEach(t),Hg.forEach(t),sd.forEach(t),td.forEach(t),Bp=f(e),re=s(e,"H2",{class:!0});var id=i(re);Ae=s(id,"A",{id:!0,class:!0,href:!0});var Xg=i(Ae);Zo=s(Xg,"SPAN",{});var Kg=i(Zo);v(kt.$$.fragment,Kg),Kg.forEach(t),Xg.forEach(t),am=f(id),Bo=s(id,"SPAN",{});var Jg=i(Bo);sm=r(Jg,"Data Parallelism"),Jg.forEach(t),id.forEach(t),Vp=f(e),I=s(e,"P",{});var ht=i(I);im=r(ht,"Most users with just 2 GPUs already enjoy the increased training speed up thanks to "),Vo=s(ht,"CODE",{});var Qg=i(Vo);om=r(Qg,"DataParallel"),Qg.forEach(t),rm=r(ht," (DP) and "),qo=s(ht,"CODE",{});var eE=i(qo);nm=r(eE,"DistributedDataParallel"),eE.forEach(t),pm=r(ht," (DDP) that are almost trivial to use. This is a built-in feature of Pytorch. Note that in general it is advised to use DDP as it is better maintained and works for all models while DP might fail for some models. "),Gt=s(ht,"A",{href:!0,rel:!0});var tE=i(Gt);hm=r(tE,"PyTorch documentation"),tE.forEach(t),fm=r(ht," itself recommends the use of DDP."),ht.forEach(t),qp=f(e),ne=s(e,"H3",{class:!0});var od=i(ne);Oe=s(od,"A",{id:!0,class:!0,href:!0});var lE=i(Oe);Fo=s(lE,"SPAN",{});var aE=i(Fo);v(Ut.$$.fragment,aE),aE.forEach(t),lE.forEach(t),cm=f(od),Wo=s(od,"SPAN",{});var sE=i(Wo);dm=r(sE,"DP vs DDP"),sE.forEach(t),od.forEach(t),Fp=f(e),pe=s(e,"P",{});var Tp=i(pe);Ho=s(Tp,"CODE",{});var iE=i(Ho);um=r(iE,"DistributedDataParallel"),iE.forEach(t),mm=r(Tp," (DDP) is typically faster than "),Yo=s(Tp,"CODE",{});var oE=i(Yo);vm=r(oE,"DataParallel"),oE.forEach(t),Pm=r(Tp," (DP), but it is not always the case:"),Tp.forEach(t),Wp=f(e),je=s(e,"UL",{});var rd=i(je);Xo=s(rd,"LI",{});var rE=i(Xo);wm=r(rE,"while DP is python threads-based, DDP is multiprocess-based - and as such it has no python threads limitations, such as GIL"),rE.forEach(t),_m=f(rd),Ko=s(rd,"LI",{});var nE=i(Ko);ym=r(nE,"on the other hand a slow inter-connectivity between the GPU cards could lead to an actual slower outcome with DDP"),nE.forEach(t),rd.forEach(t),Hp=f(e),ba=s(e,"P",{});var pE=i(ba);bm=r(pE,"Here are the main differences in the inter-GPU communication overhead between the two modes:"),pE.forEach(t),Yp=f(e),It=s(e,"P",{});var kb=i(It);St=s(kb,"A",{href:!0,rel:!0});var hE=i(St);gm=r(hE,"DDP"),hE.forEach(t),Em=r(kb,":"),kb.forEach(t),Xp=f(e),xe=s(e,"UL",{});var nd=i(xe);Jo=s(nd,"LI",{});var fE=i(Jo);Dm=r(fE,"At the start time the main process replicates the model once from gpu 0 to the rest of gpus"),fE.forEach(t),Lm=f(nd),ga=s(nd,"LI",{});var Gb=i(ga);Tm=r(Gb,"Then for each batch:"),At=s(Gb,"OL",{});var pd=i(At);Qo=s(pd,"LI",{});var cE=i(Qo);km=r(cE,"each gpu consumes each own mini-batch of data directly"),cE.forEach(t),Gm=f(pd),Ot=s(pd,"LI",{});var hd=i(Ot);Um=r(hd,"during "),er=s(hd,"CODE",{});var dE=i(er);Im=r(dE,"backward"),dE.forEach(t),Sm=r(hd,", once the local gradients are ready, they are then averaged across all processes"),hd.forEach(t),pd.forEach(t),Gb.forEach(t),nd.forEach(t),Kp=f(e),jt=s(e,"P",{});var Ub=i(jt);xt=s(Ub,"A",{href:!0,rel:!0});var uE=i(xt);Am=r(uE,"DP"),uE.forEach(t),Om=r(Ub,":"),Ub.forEach(t),Jp=f(e),Ea=s(e,"P",{});var mE=i(Ea);jm=r(mE,"For each batch:"),mE.forEach(t),Qp=f(e),D=s(e,"OL",{});var X=i(D);tr=s(X,"LI",{});var vE=i(tr);xm=r(vE,"gpu 0 reads the batch of data and then sends a mini-batch to each gpu"),vE.forEach(t),Mm=f(X),lr=s(X,"LI",{});var PE=i(lr);$m=r(PE,"replicates the up-to-date model from gpu 0 to each gpu"),PE.forEach(t),Nm=f(X),Mt=s(X,"LI",{});var fd=i(Mt);zm=r(fd,"runs "),ar=s(fd,"CODE",{});var wE=i(ar);Cm=r(wE,"forward"),wE.forEach(t),Rm=r(fd," and sends output from each gpu to gpu 0, computes loss"),fd.forEach(t),Zm=f(X),Da=s(X,"LI",{});var Ib=i(Da);Bm=r(Ib,"scatters loss from gpu 0 to all gpus, runs "),sr=s(Ib,"CODE",{});var _E=i(sr);Vm=r(_E,"backward"),_E.forEach(t),Ib.forEach(t),qm=f(X),ir=s(X,"LI",{});var yE=i(ir);Fm=r(yE,"sends gradients from each gpu to gpu 0 and averages those"),yE.forEach(t),X.forEach(t),eh=f(e),La=s(e,"P",{});var bE=i(La);Wm=r(bE,"The only communication DDP performs per batch is sending gradients, whereas DP does 5 different data exchanges per batch."),bE.forEach(t),th=f(e),Me=s(e,"P",{});var cd=i(Me);Hm=r(cd,"DP copies data within the process via python threads, whereas DDP copies data via "),$t=s(cd,"A",{href:!0,rel:!0});var gE=i($t);Ym=r(gE,"torch.distributed"),gE.forEach(t),Xm=r(cd,"."),cd.forEach(t),lh=f(e),Ta=s(e,"P",{});var EE=i(Ta);Km=r(EE,"Under DP gpu 0 performs a lot more work than the rest of the gpus, thus resulting in under-utilization of gpus."),EE.forEach(t),ah=f(e),ka=s(e,"P",{});var DE=i(ka);Jm=r(DE,"You can use DDP across multiple machines, but this is not the case with DP."),DE.forEach(t),sh=f(e),Ga=s(e,"P",{});var LE=i(Ga);Qm=r(LE,"There are other differences between DP and DDP but they aren\u2019t relevant to this discussion."),LE.forEach(t),ih=f(e),$e=s(e,"P",{});var dd=i($e);ev=r(dd,"If you want to go really deep into understanding these 2 modes, this "),Nt=s(dd,"A",{href:!0,rel:!0});var TE=i(Nt);tv=r(TE,"article"),TE.forEach(t),lv=r(dd," is highly recommended, as it has great diagrams, includes multiple benchmarks and profiler outputs on various hardware, explains all the nuances that you may need to know."),dd.forEach(t),oh=f(e),Ua=s(e,"P",{});var kE=i(Ua);av=r(kE,"Let\u2019s look at an actual benchmark:"),kE.forEach(t),rh=f(e),Ne=s(e,"TABLE",{});var ud=i(Ne);or=s(ud,"THEAD",{});var GE=i(or);he=s(GE,"TR",{});var Bi=i(he);Ia=s(Bi,"TH",{align:!0});var UE=i(Ia);sv=r(UE,"Type"),UE.forEach(t),iv=f(Bi),rr=s(Bi,"TH",{});var IE=i(rr);ov=r(IE,"NVlink"),IE.forEach(t),rv=f(Bi),Sa=s(Bi,"TH",{align:!0});var SE=i(Sa);nv=r(SE,"Time"),SE.forEach(t),Bi.forEach(t),GE.forEach(t),pv=f(ud),fe=s(ud,"TBODY",{});var Vi=i(fe);ce=s(Vi,"TR",{});var qi=i(ce);Aa=s(qi,"TD",{align:!0});var AE=i(Aa);hv=r(AE,"2:DP"),AE.forEach(t),fv=f(qi),nr=s(qi,"TD",{});var OE=i(nr);cv=r(OE,"Y"),OE.forEach(t),dv=f(qi),Oa=s(qi,"TD",{align:!0});var jE=i(Oa);uv=r(jE,"110s"),jE.forEach(t),qi.forEach(t),mv=f(Vi),de=s(Vi,"TR",{});var Fi=i(de);ja=s(Fi,"TD",{align:!0});var xE=i(ja);vv=r(xE,"2:DDP"),xE.forEach(t),Pv=f(Fi),pr=s(Fi,"TD",{});var ME=i(pr);wv=r(ME,"Y"),ME.forEach(t),_v=f(Fi),xa=s(Fi,"TD",{align:!0});var $E=i(xa);yv=r($E,"101s"),$E.forEach(t),Fi.forEach(t),bv=f(Vi),ue=s(Vi,"TR",{});var Wi=i(ue);Ma=s(Wi,"TD",{align:!0});var NE=i(Ma);gv=r(NE,"2:DDP"),NE.forEach(t),Ev=f(Wi),hr=s(Wi,"TD",{});var zE=i(hr);Dv=r(zE,"N"),zE.forEach(t),Lv=f(Wi),$a=s(Wi,"TD",{align:!0});var CE=i($a);Tv=r(CE,"131s"),CE.forEach(t),Wi.forEach(t),Vi.forEach(t),ud.forEach(t),nh=f(e),Na=s(e,"P",{});var RE=i(Na);kv=r(RE,"Analysis:"),RE.forEach(t),ph=f(e),za=s(e,"P",{});var ZE=i(za);Gv=r(ZE,"Here DP is ~10% slower than DDP w/ NVlink, but ~15% faster than DDP w/o NVlink"),ZE.forEach(t),hh=f(e),Ca=s(e,"P",{});var BE=i(Ca);Uv=r(BE,"The real difference will depend on how much data each GPU needs to sync with the others - the more there is to sync, the more a slow link will slow down the total runtime."),BE.forEach(t),fh=f(e),Ra=s(e,"P",{});var VE=i(Ra);Iv=r(VE,"Here is the full benchmark code and outputs:"),VE.forEach(t),ch=f(e),zt=s(e,"P",{});var Sb=i(zt);fr=s(Sb,"CODE",{});var qE=i(fr);Sv=r(qE,"NCCL_P2P_DISABLE=1"),qE.forEach(t),Av=r(Sb," was used to disable the NVLink feature on the corresponding benchmark."),Sb.forEach(t),dh=f(e),v(Ct.$$.fragment,e),uh=f(e),g=s(e,"P",{});var M=i(g);Ov=r(M,"Hardware: 2x TITAN RTX 24GB each + NVlink with 2 NVLinks ("),cr=s(M,"CODE",{});var FE=i(cr);jv=r(FE,"NV2"),FE.forEach(t),xv=r(M," in "),dr=s(M,"CODE",{});var WE=i(dr);Mv=r(WE,"nvidia-smi topo -m"),WE.forEach(t),$v=r(M,`)
Software: `),ur=s(M,"CODE",{});var HE=i(ur);Nv=r(HE,"pytorch-1.8-to-be"),HE.forEach(t),zv=r(M," + "),mr=s(M,"CODE",{});var YE=i(mr);Cv=r(YE,"cuda-11.0"),YE.forEach(t),Rv=r(M," / "),vr=s(M,"CODE",{});var XE=i(vr);Zv=r(XE,"transformers==4.3.0.dev0"),XE.forEach(t),M.forEach(t),mh=f(e),me=s(e,"H2",{class:!0});var md=i(me);ze=s(md,"A",{id:!0,class:!0,href:!0});var KE=i(ze);Pr=s(KE,"SPAN",{});var JE=i(Pr);v(Rt.$$.fragment,JE),JE.forEach(t),KE.forEach(t),Bv=f(md),wr=s(md,"SPAN",{});var QE=i(wr);Vv=r(QE,"ZeRO Data Parallelism"),QE.forEach(t),md.forEach(t),vh=f(e),ve=s(e,"P",{});var kp=i(ve);qv=r(kp,"ZeRO-powered data parallelism (ZeRO-DP) is described on the following diagram from this "),Zt=s(kp,"A",{href:!0,rel:!0});var e3=i(Zt);Fv=r(e3,"blog post"),e3.forEach(t),Wv=f(kp),Za=s(kp,"IMG",{src:!0,alt:!0}),kp.forEach(t),Ph=f(e),Ce=s(e,"P",{});var vd=i(Ce);Hv=r(vd,"It can be difficult to wrap one\u2019s head around it, but in reality the concept is quite simple. This is just the usual "),_r=s(vd,"CODE",{});var t3=i(_r);Yv=r(t3,"DataParallel"),t3.forEach(t),Xv=r(vd," (DP), except, instead of replicating the full model params, gradients and optimizer states, each GPU stores only a slice of it.  And then at run-time when the full layer params are needed just for the given layer, all GPUs synchronize to give each other parts that they miss - this is it."),vd.forEach(t),wh=f(e),Ba=s(e,"P",{});var l3=i(Ba);Kv=r(l3,"Consider this simple model with 3 layers, where each layer has 3 params:"),l3.forEach(t),_h=f(e),v(Bt.$$.fragment,e),yh=f(e),Va=s(e,"P",{});var a3=i(Va);Jv=r(a3,"Layer La has weights a0, a1 and a2."),a3.forEach(t),bh=f(e),qa=s(e,"P",{});var s3=i(qa);Qv=r(s3,"If we have 3 GPUs, the Sharded DDP (= Zero-DP) splits the model onto 3 GPUs like so:"),s3.forEach(t),gh=f(e),v(Vt.$$.fragment,e),Eh=f(e),Fa=s(e,"P",{});var i3=i(Fa);eP=r(i3,"In a way this is the same horizontal slicing, as tensor parallelism, if you imagine the typical DNN diagram. Vertical slicing is where one puts whole layer-groups on different GPUs. But it\u2019s just the starting point."),i3.forEach(t),Dh=f(e),Wa=s(e,"P",{});var o3=i(Wa);tP=r(o3,"Now each of these GPUs will get the usual mini-batch as it works in DP:"),o3.forEach(t),Lh=f(e),v(qt.$$.fragment,e),Th=f(e),Ha=s(e,"P",{});var r3=i(Ha);lP=r(r3,"The inputs are unmodified - they think they are going to be processed by the normal model."),r3.forEach(t),kh=f(e),Ya=s(e,"P",{});var n3=i(Ya);aP=r(n3,"First, the inputs hit the layer La."),n3.forEach(t),Gh=f(e),Xa=s(e,"P",{});var p3=i(Xa);sP=r(p3,"Let\u2019s focus just on GPU0: x0 needs a0, a1, a2 params to do its forward path, but GPU0 has only a0 - it gets sent a1 from GPU1 and a2 from GPU2, bringing all pieces of the model together."),p3.forEach(t),Uh=f(e),Ka=s(e,"P",{});var h3=i(Ka);iP=r(h3,"In parallel, GPU1 gets mini-batch x1 and it only has a1, but needs a0 and a2 params, so it gets those from GPU0 and GPU2."),h3.forEach(t),Ih=f(e),Ja=s(e,"P",{});var f3=i(Ja);oP=r(f3,"Same happens to GPU2 that gets input x2. It gets a0 and a1 from GPU0 and GPU1, and with its a2 it reconstructs the full tensor."),f3.forEach(t),Sh=f(e),Qa=s(e,"P",{});var c3=i(Qa);rP=r(c3,"All 3 GPUs get the full tensors reconstructed and a forward happens."),c3.forEach(t),Ah=f(e),es=s(e,"P",{});var d3=i(es);nP=r(d3,"As soon as the calculation is done, the data that is no longer needed gets dropped - it\u2019s only used during the calculation. The reconstruction is done efficiently via a pre-fetch."),d3.forEach(t),Oh=f(e),ts=s(e,"P",{});var u3=i(ts);pP=r(u3,"And the whole process is repeated for layer Lb, then Lc forward-wise, and then backward Lc -> Lb -> La."),u3.forEach(t),jh=f(e),ls=s(e,"P",{});var m3=i(ls);hP=r(m3,"To me this sounds like an efficient group backpacking weight distribution strategy:"),m3.forEach(t),xh=f(e),N=s(e,"OL",{});var Hi=i(N);yr=s(Hi,"LI",{});var v3=i(yr);fP=r(v3,"person A carries the tent"),v3.forEach(t),cP=f(Hi),br=s(Hi,"LI",{});var P3=i(br);dP=r(P3,"person B carries the stove"),P3.forEach(t),uP=f(Hi),gr=s(Hi,"LI",{});var w3=i(gr);mP=r(w3,"person C carries the axe"),w3.forEach(t),Hi.forEach(t),Mh=f(e),as=s(e,"P",{});var _3=i(as);vP=r(_3,"Now each night they all share what they have with others and get from others what they don\u2019t have, and in the morning they pack up their allocated type of gear and continue on their way. This is Sharded DDP / Zero DP."),_3.forEach(t),$h=f(e),ss=s(e,"P",{});var y3=i(ss);PP=r(y3,"Compare this strategy to the simple one where each person has to carry their own tent, stove and axe, which would be far more inefficient. This is DataParallel (DP and DDP) in Pytorch."),y3.forEach(t),Nh=f(e),is=s(e,"P",{});var b3=i(is);wP=r(b3,"While reading the literature on this topic you may encounter the following synonyms: Sharded, Partitioned."),b3.forEach(t),zh=f(e),os=s(e,"P",{});var g3=i(os);_P=r(g3,"If you pay close attention the way ZeRO partitions the model\u2019s weights - it looks very similar to tensor parallelism which will be discussed later. This is because it partitions/shards each layer\u2019s weights, unlike vertical model parallelism which is discussed next."),g3.forEach(t),Ch=f(e),rs=s(e,"P",{});var E3=i(rs);yP=r(E3,"Implementations:"),E3.forEach(t),Rh=f(e),z=s(e,"UL",{});var Yi=i(z);ns=s(Yi,"LI",{});var Ab=i(ns);Ft=s(Ab,"A",{href:!0,rel:!0});var D3=i(Ft);bP=r(D3,"DeepSpeed"),D3.forEach(t),gP=r(Ab," ZeRO-DP stages 1+2+3"),Ab.forEach(t),EP=f(Yi),ps=s(Yi,"LI",{});var Ob=i(ps);Wt=s(Ob,"A",{href:!0,rel:!0});var L3=i(Wt);DP=r(L3,"Fairscale"),L3.forEach(t),LP=r(Ob," ZeRO-DP stages 1+2+3"),Ob.forEach(t),TP=f(Yi),Er=s(Yi,"LI",{});var T3=i(Er);Ht=s(T3,"A",{href:!0});var jb=i(Ht);Dr=s(jb,"CODE",{});var k3=i(Dr);kP=r(k3,"transformers"),k3.forEach(t),GP=r(jb," integration"),jb.forEach(t),T3.forEach(t),Yi.forEach(t),Zh=f(e),Pe=s(e,"H2",{class:!0});var Pd=i(Pe);Re=s(Pd,"A",{id:!0,class:!0,href:!0});var G3=i(Re);Lr=s(G3,"SPAN",{});var U3=i(Lr);v(Yt.$$.fragment,U3),U3.forEach(t),G3.forEach(t),UP=f(Pd),Tr=s(Pd,"SPAN",{});var I3=i(Tr);IP=r(I3,"Naive Model Parallelism (Vertical) and Pipeline Parallelism"),I3.forEach(t),Pd.forEach(t),Bh=f(e),Ze=s(e,"P",{});var wd=i(Ze);SP=r(wd,"Naive Model Parallelism (MP) is where one spreads groups of model layers across multiple GPUs. The mechanism is relatively simple - switch the desired layers "),kr=s(wd,"CODE",{});var S3=i(kr);AP=r(S3,".to()"),S3.forEach(t),OP=r(wd," the desired devices and now whenever the data goes in and out those layers switch the data to the same device as the layer and leave the rest unmodified."),wd.forEach(t),Vh=f(e),hs=s(e,"P",{});var A3=i(hs);jP=r(A3,"We refer to it as Vertical MP, because if you remember how most models are drawn, we slice the layers vertically. For example, if the following diagram shows an 8-layer model:"),A3.forEach(t),qh=f(e),v(Xt.$$.fragment,e),Fh=f(e),fs=s(e,"P",{});var O3=i(fs);xP=r(O3,"we just sliced it in 2 vertically, placing layers 0-3 onto GPU0 and 4-7 to GPU1."),O3.forEach(t),Wh=f(e),cs=s(e,"P",{});var j3=i(cs);MP=r(j3,"Now while data travels from layer 0 to 1, 1 to 2 and 2 to 3 this is just the normal model. But when data needs to pass from layer 3 to layer 4 it needs to travel from GPU0 to GPU1 which introduces a communication overhead. If the participating GPUs are on the same compute node (e.g. same physical machine) this copying is pretty fast, but if the GPUs are located on different compute nodes (e.g. multiple machines) the communication overhead could be significantly larger."),j3.forEach(t),Hh=f(e),ds=s(e,"P",{});var x3=i(ds);$P=r(x3,"Then layers 4 to 5 to 6 to 7 are as a normal model would have and when the 7th layer completes we often need to send the data back to layer 0 where the labels are (or alternatively send the labels to the last layer). Now the loss can be computed and the optimizer can do its work."),x3.forEach(t),Yh=f(e),us=s(e,"P",{});var M3=i(us);NP=r(M3,"Problems:"),M3.forEach(t),Xh=f(e),Be=s(e,"UL",{});var _d=i(Be);Gr=s(_d,"LI",{});var $3=i(Gr);zP=r($3,"the main deficiency and why this one is called \u201Cnaive\u201D MP, is that all but one GPU is idle at any given moment. So if 4 GPUs are used, it\u2019s almost identical to quadrupling the amount of memory of a single GPU, and ignoring the rest of the hardware. Plus there is the overhead of copying the data between devices. So 4x 6GB cards will be able to accommodate the same size as 1x 24GB card using naive MP, except the latter will complete the training faster, since it doesn\u2019t have the data copying overhead. But, say, if you have 40GB cards and need to fit a 45GB model you can with 4x 40GB cards (but barely because of the gradient and optimizer states)"),$3.forEach(t),CP=f(_d),Ur=s(_d,"LI",{});var N3=i(Ur);RP=r(N3,"shared embeddings may need to get copied back and forth between GPUs."),N3.forEach(t),_d.forEach(t),Kh=f(e),ms=s(e,"P",{});var z3=i(ms);ZP=r(z3,"Pipeline Parallelism (PP) is almost identical to a naive MP, but it solves the GPU idling problem, by chunking the incoming batch into micro-batches and artificially creating a pipeline, which allows different GPUs to concurrently participate in the computation process."),z3.forEach(t),Jh=f(e),Ve=s(e,"P",{});var yd=i(Ve);BP=r(yd,"The following illustration from the "),Kt=s(yd,"A",{href:!0,rel:!0});var C3=i(Kt);VP=r(C3,"GPipe paper"),C3.forEach(t),qP=r(yd," shows the naive MP on the top, and PP on the bottom:"),yd.forEach(t),Qh=f(e),vs=s(e,"P",{});var R3=i(vs);Ps=s(R3,"IMG",{src:!0,alt:!0}),R3.forEach(t),ef=f(e),ws=s(e,"P",{});var Z3=i(ws);FP=r(Z3,"It\u2019s easy to see from the bottom diagram how PP has less dead zones, where GPUs are idle. The idle parts are referred to as the \u201Cbubble\u201D."),Z3.forEach(t),tf=f(e),_s=s(e,"P",{});var B3=i(_s);WP=r(B3,"Both parts of the diagram show a parallelism that is of degree 4. That is 4 GPUs are participating in the pipeline. So there is the forward path of 4 pipe stages F0, F1, F2 and F3 and then the return reverse order backward path of B3, B2, B1 and B0."),B3.forEach(t),lf=f(e),C=s(e,"P",{});var Xi=i(C);HP=r(Xi,"PP introduces a new hyper-parameter to tune and it\u2019s "),Ir=s(Xi,"CODE",{});var V3=i(Ir);YP=r(V3,"chunks"),V3.forEach(t),XP=r(Xi," which defines how many chunks of data are sent in a sequence through the same pipe stage. For example, in the bottomw diagram you can see that "),Sr=s(Xi,"CODE",{});var q3=i(Sr);KP=r(q3,"chunks=4"),q3.forEach(t),JP=r(Xi,". GPU0 performs the same forward path on chunk 0, 1, 2 and 3 (F0,0, F0,1, F0,2, F0,3) and then it waits for other GPUs to do their work and only when their work is starting to be complete, GPU0 starts to work again doing the backward path for chunks 3, 2, 1 and 0 (B0,3, B0,2, B0,1, B0,0)."),Xi.forEach(t),af=f(e),qe=s(e,"P",{});var bd=i(qe);QP=r(bd,"Note that conceptually this is the same concept as gradient accumulation steps (GAS). Pytorch uses "),Ar=s(bd,"CODE",{});var F3=i(Ar);e1=r(F3,"chunks"),F3.forEach(t),t1=r(bd,", whereas DeepSpeed refers to the same hyper-parameter as GAS."),bd.forEach(t),sf=f(e),Fe=s(e,"P",{});var gd=i(Fe);l1=r(gd,"Because of the chunks, PP introduces the concept of micro-batches (MBS). DP splits the global data batch size into mini-batches, so if you have a DP degree of 4, a global batch size of 1024 gets split up into 4 mini-batches of 256 each (1024/4). And if the number of "),Or=s(gd,"CODE",{});var W3=i(Or);a1=r(W3,"chunks"),W3.forEach(t),s1=r(gd," (or GAS) is 32 we end up with a micro-batch size of 8 (256/32). Each Pipeline stage works with a single micro-batch at a time."),gd.forEach(t),of=f(e),R=s(e,"P",{});var Ki=i(R);i1=r(Ki,"To calculate the global batch size of the DP + PP setup we then do: "),jr=s(Ki,"CODE",{});var H3=i(jr);o1=r(H3,"mbs*chunks*dp_degree"),H3.forEach(t),r1=r(Ki," ("),xr=s(Ki,"CODE",{});var Y3=i(xr);n1=r(Y3,"8*32*4=1024"),Y3.forEach(t),p1=r(Ki,")."),Ki.forEach(t),rf=f(e),ys=s(e,"P",{});var X3=i(ys);h1=r(X3,"Let\u2019s go back to the diagram."),X3.forEach(t),nf=f(e),Z=s(e,"P",{});var Ji=i(Z);f1=r(Ji,"With "),Mr=s(Ji,"CODE",{});var K3=i(Mr);c1=r(K3,"chunks=1"),K3.forEach(t),d1=r(Ji," you end up with the naive MP, which is very inefficient. With a very large "),$r=s(Ji,"CODE",{});var J3=i($r);u1=r(J3,"chunks"),J3.forEach(t),m1=r(Ji," value you end up with tiny micro-batch sizes which could be not every efficient either. So one has to experiment to find the value that leads to the highest efficient utilization of the gpus."),Ji.forEach(t),pf=f(e),S=s(e,"P",{});var ft=i(S);v1=r(ft,"While the diagram shows that there is a bubble of \u201Cdead\u201D time that can\u2019t be parallelized because the last "),Nr=s(ft,"CODE",{});var Q3=i(Nr);P1=r(Q3,"forward"),Q3.forEach(t),w1=r(ft," stage has to wait for "),zr=s(ft,"CODE",{});var e0=i(zr);_1=r(e0,"backward"),e0.forEach(t),y1=r(ft," to complete the pipeline, the purpose of finding the best value for "),Cr=s(ft,"CODE",{});var t0=i(Cr);b1=r(t0,"chunks"),t0.forEach(t),g1=r(ft," is to enable a high concurrent GPU utilization across all participating GPUs which translates to minimizing the size of the bubble."),ft.forEach(t),hf=f(e),bs=s(e,"P",{});var l0=i(bs);E1=r(l0,"There are 2 groups of solutions - the traditional Pipeline API and the more modern solutions that make things much easier for the end user."),l0.forEach(t),ff=f(e),gs=s(e,"P",{});var a0=i(gs);D1=r(a0,"Traditional Pipeline API solutions:"),a0.forEach(t),cf=f(e),A=s(e,"UL",{});var ct=i(A);Rr=s(ct,"LI",{});var s0=i(Rr);L1=r(s0,"PyTorch"),s0.forEach(t),T1=f(ct),Zr=s(ct,"LI",{});var i0=i(Zr);k1=r(i0,"FairScale"),i0.forEach(t),G1=f(ct),Br=s(ct,"LI",{});var o0=i(Br);U1=r(o0,"DeepSpeed"),o0.forEach(t),I1=f(ct),Vr=s(ct,"LI",{});var r0=i(Vr);S1=r(r0,"Megatron-LM"),r0.forEach(t),ct.forEach(t),df=f(e),Es=s(e,"P",{});var n0=i(Es);A1=r(n0,"Modern solutions:"),n0.forEach(t),uf=f(e),We=s(e,"UL",{});var Ed=i(We);qr=s(Ed,"LI",{});var p0=i(qr);O1=r(p0,"Varuna"),p0.forEach(t),j1=f(Ed),Fr=s(Ed,"LI",{});var h0=i(Fr);x1=r(h0,"Sagemaker"),h0.forEach(t),Ed.forEach(t),mf=f(e),Ds=s(e,"P",{});var f0=i(Ds);M1=r(f0,"Problems with traditional Pipeline API solutions:"),f0.forEach(t),vf=f(e),O=s(e,"UL",{});var dt=i(O);Jt=s(dt,"LI",{});var Dd=i(Jt);$1=r(Dd,"have to modify the model quite heavily, because Pipeline requires one to rewrite the normal flow of modules into a "),Wr=s(Dd,"CODE",{});var c0=i(Wr);N1=r(c0,"nn.Sequential"),c0.forEach(t),z1=r(Dd," sequence of the same, which may require changes to the design of the model."),Dd.forEach(t),C1=f(dt),Ls=s(dt,"LI",{});var xb=i(Ls);R1=r(xb,"currently the Pipeline API is very restricted. If you had a bunch of python variables being passed in the very first stage of the Pipeline, you will have to find a way around it. Currently, the pipeline interface requires either a single Tensor or a tuple of Tensors as the only input and output. These tensors must have a batch size as the very first dimension, since pipeline is going to chunk the mini batch into micro-batches. Possible improvements are being discussed here "),Qt=s(xb,"A",{href:!0,rel:!0});var d0=i(Qt);Z1=r(d0,"https://github.com/pytorch/pytorch/pull/50693"),d0.forEach(t),xb.forEach(t),B1=f(dt),Hr=s(dt,"LI",{});var u0=i(Hr);V1=r(u0,"conditional control flow at the level of pipe stages is not possible - e.g., Encoder-Decoder models like T5 require special workarounds to handle a conditional encoder stage."),u0.forEach(t),q1=f(dt),Yr=s(dt,"LI",{});var m0=i(Yr);F1=r(m0,"have to arrange each layer so that the output of one model becomes an input to the other model."),m0.forEach(t),dt.forEach(t),Pf=f(e),Ts=s(e,"P",{});var v0=i(Ts);W1=r(v0,"We are yet to experiment with Varuna and SageMaker but their papers report that they have overcome the list of problems mentioned above and that they require much smaller changes to the user\u2019s model."),v0.forEach(t),wf=f(e),ks=s(e,"P",{});var P0=i(ks);H1=r(P0,"Implementations:"),P0.forEach(t),_f=f(e),u=s(e,"UL",{});var G=i(u);el=s(G,"LI",{});var Ld=i(el);tl=s(Ld,"A",{href:!0,rel:!0});var w0=i(tl);Y1=r(w0,"Pytorch"),w0.forEach(t),X1=r(Ld," (initial support in pytorch-1.8, and progressively getting improved in 1.9 and more so in 1.10). Some "),ll=s(Ld,"A",{href:!0,rel:!0});var _0=i(ll);K1=r(_0,"examples"),_0.forEach(t),Ld.forEach(t),J1=f(G),Xr=s(G,"LI",{});var y0=i(Xr);al=s(y0,"A",{href:!0,rel:!0});var b0=i(al);Q1=r(b0,"FairScale"),b0.forEach(t),y0.forEach(t),ew=f(G),Kr=s(G,"LI",{});var g0=i(Kr);sl=s(g0,"A",{href:!0,rel:!0});var E0=i(sl);tw=r(E0,"DeepSpeed"),E0.forEach(t),g0.forEach(t),lw=f(G),Gs=s(G,"LI",{});var Mb=i(Gs);il=s(Mb,"A",{href:!0,rel:!0});var D0=i(il);aw=r(D0,"Megatron-LM"),D0.forEach(t),sw=r(Mb," has an internal implementation - no API."),Mb.forEach(t),iw=f(G),Jr=s(G,"LI",{});var L0=i(Jr);ol=s(L0,"A",{href:!0,rel:!0});var T0=i(ol);ow=r(T0,"Varuna"),T0.forEach(t),L0.forEach(t),rw=f(G),Us=s(G,"LI",{});var $b=i(Us);rl=s($b,"A",{href:!0,rel:!0});var k0=i(rl);nw=r(k0,"SageMaker"),k0.forEach(t),pw=r($b," - this is a proprietary solution that can only be used on AWS."),$b.forEach(t),hw=f(G),Is=s(G,"LI",{});var Nb=i(Is);nl=s(Nb,"A",{href:!0,rel:!0});var G0=i(nl);fw=r(G0,"OSLO"),G0.forEach(t),cw=r(Nb," - this is implemented based on the Hugging Face Transformers."),Nb.forEach(t),G.forEach(t),yf=f(e),He=s(e,"P",{});var Td=i(He);dw=r(Td,"\u{1F917} Transformers status: as of this writing none of the models supports full-PP. GPT2 and T5 models have naive MP support. The main obstacle is being unable to convert the models to "),Qr=s(Td,"CODE",{});var U0=i(Qr);uw=r(U0,"nn.Sequential"),U0.forEach(t),mw=r(Td," and have all the inputs to be Tensors. This is because currently the models include many features that make the conversion very complicated, and will need to be removed to accomplish that."),Td.forEach(t),bf=f(e),Ss=s(e,"P",{});var I0=i(Ss);vw=r(I0,"Other approaches:"),I0.forEach(t),gf=f(e),we=s(e,"P",{});var Gp=i(we);Pw=r(Gp,"DeepSpeed, Varuna and SageMaker use the concept of an "),pl=s(Gp,"A",{href:!0,rel:!0});var S0=i(pl);ww=r(S0,"Interleaved Pipeline"),S0.forEach(t),_w=f(Gp),As=s(Gp,"IMG",{src:!0,alt:!0}),Gp.forEach(t),Ef=f(e),Os=s(e,"P",{});var A0=i(Os);yw=r(A0,"Here the bubble (idle time) is further minimized by prioritizing backward passes."),A0.forEach(t),Df=f(e),js=s(e,"P",{});var O0=i(js);bw=r(O0,"Varuna further tries to improve the schedule by using simulations to discover the most efficient scheduling."),O0.forEach(t),Lf=f(e),Ye=s(e,"P",{});var kd=i(Ye);gw=r(kd,"OSLO has pipeline parallelism implementation based on the Transformers without "),en=s(kd,"CODE",{});var j0=i(en);Ew=r(j0,"nn.Sequential"),j0.forEach(t),Dw=r(kd," converting."),kd.forEach(t),Tf=f(e),_e=s(e,"H2",{class:!0});var Gd=i(_e);Xe=s(Gd,"A",{id:!0,class:!0,href:!0});var x0=i(Xe);tn=s(x0,"SPAN",{});var M0=i(tn);v(hl.$$.fragment,M0),M0.forEach(t),x0.forEach(t),Lw=f(Gd),ln=s(Gd,"SPAN",{});var $0=i(ln);Tw=r($0,"Tensor Parallelism"),$0.forEach(t),Gd.forEach(t),kf=f(e),xs=s(e,"P",{});var N0=i(xs);kw=r(N0,"In Tensor Parallelism each GPU processes only a slice of a tensor and only aggregates the full tensor for operations that require the whole thing."),N0.forEach(t),Gf=f(e),B=s(e,"P",{});var Qi=i(B);Gw=r(Qi,"In this section we use concepts and diagrams from the "),fl=s(Qi,"A",{href:!0,rel:!0});var z0=i(fl);Uw=r(z0,"Megatron-LM"),z0.forEach(t),Iw=r(Qi," paper: "),cl=s(Qi,"A",{href:!0,rel:!0});var C0=i(cl);Sw=r(C0,"Efficient Large-Scale Language Model Training on GPU Clusters"),C0.forEach(t),Aw=r(Qi,"."),Qi.forEach(t),Uf=f(e),V=s(e,"P",{});var eo=i(V);Ow=r(eo,"The main building block of any transformer is a fully connected "),an=s(eo,"CODE",{});var R0=i(an);jw=r(R0,"nn.Linear"),R0.forEach(t),xw=r(eo," followed by a nonlinear activation "),sn=s(eo,"CODE",{});var Z0=i(sn);Mw=r(Z0,"GeLU"),Z0.forEach(t),$w=r(eo,"."),eo.forEach(t),If=f(e),L=s(e,"P",{});var K=i(L);Nw=r(K,"Following the Megatron\u2019s paper notation, we can write the dot-product part of it as "),on=s(K,"CODE",{});var B0=i(on);zw=r(B0,"Y = GeLU(XA)"),B0.forEach(t),Cw=r(K,", where "),rn=s(K,"CODE",{});var V0=i(rn);Rw=r(V0,"X"),V0.forEach(t),Zw=r(K," and "),nn=s(K,"CODE",{});var q0=i(nn);Bw=r(q0,"Y"),q0.forEach(t),Vw=r(K," are the input and output vectors, and "),pn=s(K,"CODE",{});var F0=i(pn);qw=r(F0,"A"),F0.forEach(t),Fw=r(K," is the weight matrix."),K.forEach(t),Sf=f(e),dl=s(e,"P",{});var zb=i(dl);Ww=r(zb,`If we look at the computation in matrix form, it\u2019s easy to see how the matrix multiplication can be split between multiple GPUs:
`),Ms=s(zb,"IMG",{src:!0,alt:!0}),zb.forEach(t),Af=f(e),d=s(e,"P",{});var b=i(d);Hw=r(b,"If we split the weight matrix "),hn=s(b,"CODE",{});var W0=i(hn);Yw=r(W0,"A"),W0.forEach(t),Xw=r(b," column-wise across "),fn=s(b,"CODE",{});var H0=i(fn);Kw=r(H0,"N"),H0.forEach(t),Jw=r(b," GPUs and perform matrix multiplications "),cn=s(b,"CODE",{});var Y0=i(cn);Qw=r(Y0,"XA_1"),Y0.forEach(t),e2=r(b," through "),dn=s(b,"CODE",{});var X0=i(dn);t2=r(X0,"XA_n"),X0.forEach(t),l2=r(b," in parallel, then we will end up with "),un=s(b,"CODE",{});var K0=i(un);a2=r(K0,"N"),K0.forEach(t),s2=r(b," output vectors "),mn=s(b,"CODE",{});var J0=i(mn);i2=r(J0,"Y_1, Y_2, ..., Y_n"),J0.forEach(t),o2=r(b," which can be fed into "),vn=s(b,"CODE",{});var Q0=i(vn);r2=r(Q0,"GeLU"),Q0.forEach(t),n2=r(b,` independently:
`),$s=s(b,"IMG",{src:!0,alt:!0}),b.forEach(t),Of=f(e),ul=s(e,"P",{});var Cb=i(ul);p2=r(Cb,`Using this principle, we can update an MLP of arbitrary depth, without the need for any synchronization between GPUs until the very end, where we need to reconstruct the output vector from shards. The Megatron-LM paper authors provide a helpful illustration for that:
`),Ns=s(Cb,"IMG",{src:!0,alt:!0}),Cb.forEach(t),jf=f(e),ml=s(e,"P",{});var Rb=i(ml);h2=r(Rb,`Parallelizing the multi-headed attention layers is even simpler, since they are already inherently parallel, due to having multiple independent heads!
`),zs=s(Rb,"IMG",{src:!0,alt:!0}),Rb.forEach(t),xf=f(e),Cs=s(e,"P",{});var e4=i(Cs);f2=r(e4,"Special considerations: TP requires very fast network, and therefore it\u2019s not advisable to do TP across more than one node. Practically, if a node has 4 GPUs, the highest TP degree is therefore 4. If you need a TP degree of 8, you need to use nodes that have at least 8 GPUs."),e4.forEach(t),Mf=f(e),q=s(e,"P",{});var to=i(q);c2=r(to,"This section is based on the original much more "),vl=s(to,"A",{href:!0,rel:!0});var t4=i(vl);d2=r(t4,"detailed TP overview"),t4.forEach(t),u2=r(to,`.
by `),Pl=s(to,"A",{href:!0,rel:!0});var l4=i(Pl);m2=r(l4,"@anton-l"),l4.forEach(t),v2=r(to,"."),to.forEach(t),$f=f(e),Rs=s(e,"P",{});var a4=i(Rs);P2=r(a4,"SageMaker combines TP with DP for a more efficient processing."),a4.forEach(t),Nf=f(e),Zs=s(e,"P",{});var s4=i(Zs);w2=r(s4,"Alternative names:"),s4.forEach(t),zf=f(e),Bs=s(e,"UL",{});var i4=i(Bs);Vs=s(i4,"LI",{});var Zb=i(Vs);_2=r(Zb,"DeepSpeed calls it "),wl=s(Zb,"A",{href:!0,rel:!0});var o4=i(wl);y2=r(o4,"tensor slicing"),o4.forEach(t),Zb.forEach(t),i4.forEach(t),Cf=f(e),qs=s(e,"P",{});var r4=i(qs);b2=r(r4,"Implementations:"),r4.forEach(t),Rf=f(e),j=s(e,"UL",{});var ut=i(j);Fs=s(ut,"LI",{});var Bb=i(Fs);_l=s(Bb,"A",{href:!0,rel:!0});var n4=i(_l);g2=r(n4,"Megatron-LM"),n4.forEach(t),E2=r(Bb," has an internal implementation, as it\u2019s very model-specific"),Bb.forEach(t),D2=f(ut),Ws=s(ut,"LI",{});var Vb=i(Ws);yl=s(Vb,"A",{href:!0,rel:!0});var p4=i(yl);L2=r(p4,"parallelformers"),p4.forEach(t),T2=r(Vb," (only inference at the moment)"),Vb.forEach(t),k2=f(ut),Hs=s(ut,"LI",{});var qb=i(Hs);bl=s(qb,"A",{href:!0,rel:!0});var h4=i(bl);G2=r(h4,"SageMaker"),h4.forEach(t),U2=r(qb," - this is a proprietary solution that can only be used on AWS."),qb.forEach(t),I2=f(ut),Ys=s(ut,"LI",{});var Fb=i(Ys);gl=s(Fb,"A",{href:!0,rel:!0});var f4=i(gl);S2=r(f4,"OSLO"),f4.forEach(t),A2=r(Fb," has the tensor parallelism implementation based on the Transformers."),Fb.forEach(t),ut.forEach(t),Zf=f(e),Xs=s(e,"P",{});var c4=i(Xs);O2=r(c4,"\u{1F917} Transformers status:"),c4.forEach(t),Bf=f(e),F=s(e,"UL",{});var lo=i(F);Pn=s(lo,"LI",{});var d4=i(Pn);j2=r(d4,"core: not yet implemented in the core"),d4.forEach(t),x2=f(lo),El=s(lo,"LI",{});var Ud=i(El);M2=r(Ud,"but if you want inference "),Dl=s(Ud,"A",{href:!0,rel:!0});var u4=i(Dl);$2=r(u4,"parallelformers"),u4.forEach(t),N2=r(Ud," provides this support for most of our models. So until this is implemented in the core you can use theirs. And hopefully training mode will be supported too."),Ud.forEach(t),z2=f(lo),Ks=s(lo,"LI",{});var Wb=i(Ks);C2=r(Wb,"Deepspeed-Inference also supports our BERT, GPT-2, and GPT-Neo models in their super-fast CUDA-kernel-based inference mode, see more "),Ll=s(Wb,"A",{href:!0,rel:!0});var m4=i(Ll);R2=r(m4,"here"),m4.forEach(t),Wb.forEach(t),lo.forEach(t),Vf=f(e),ye=s(e,"H2",{class:!0});var Id=i(ye);Ke=s(Id,"A",{id:!0,class:!0,href:!0});var v4=i(Ke);wn=s(v4,"SPAN",{});var P4=i(wn);v(Tl.$$.fragment,P4),P4.forEach(t),v4.forEach(t),Z2=f(Id),_n=s(Id,"SPAN",{});var w4=i(_n);B2=r(w4,"DP+PP"),w4.forEach(t),Id.forEach(t),qf=f(e),Je=s(e,"P",{});var Sd=i(Je);V2=r(Sd,"The following diagram from the DeepSpeed "),kl=s(Sd,"A",{href:!0,rel:!0});var _4=i(kl);q2=r(_4,"pipeline tutorial"),_4.forEach(t),F2=r(Sd," demonstrates how one combines DP with PP."),Sd.forEach(t),Ff=f(e),Js=s(e,"P",{});var y4=i(Js);Qs=s(y4,"IMG",{src:!0,alt:!0}),y4.forEach(t),Wf=f(e),ei=s(e,"P",{});var b4=i(ei);W2=r(b4,"Here it\u2019s important to see how DP rank 0 doesn\u2019t see GPU2 and DP rank 1 doesn\u2019t see GPU3. To DP there is just GPUs 0 and 1 where it feeds data as if there were just 2 GPUs. GPU0 \u201Csecretly\u201D offloads some of its load to GPU2 using PP. And GPU1 does the same by enlisting GPU3 to its aid."),b4.forEach(t),Hf=f(e),ti=s(e,"P",{});var g4=i(ti);H2=r(g4,"Since each dimension requires at least 2 GPUs, here you\u2019d need at least 4 GPUs."),g4.forEach(t),Yf=f(e),li=s(e,"P",{});var E4=i(li);Y2=r(E4,"Implementations:"),E4.forEach(t),Xf=f(e),T=s(e,"UL",{});var J=i(T);yn=s(J,"LI",{});var D4=i(yn);Gl=s(D4,"A",{href:!0,rel:!0});var L4=i(Gl);X2=r(L4,"DeepSpeed"),L4.forEach(t),D4.forEach(t),K2=f(J),bn=s(J,"LI",{});var T4=i(bn);Ul=s(T4,"A",{href:!0,rel:!0});var k4=i(Ul);J2=r(k4,"Megatron-LM"),k4.forEach(t),T4.forEach(t),Q2=f(J),gn=s(J,"LI",{});var G4=i(gn);Il=s(G4,"A",{href:!0,rel:!0});var U4=i(Il);e_=r(U4,"Varuna"),U4.forEach(t),G4.forEach(t),t_=f(J),En=s(J,"LI",{});var I4=i(En);Sl=s(I4,"A",{href:!0,rel:!0});var S4=i(Sl);l_=r(S4,"SageMaker"),S4.forEach(t),I4.forEach(t),a_=f(J),Dn=s(J,"LI",{});var A4=i(Dn);Al=s(A4,"A",{href:!0,rel:!0});var O4=i(Al);s_=r(O4,"OSLO"),O4.forEach(t),A4.forEach(t),J.forEach(t),Kf=f(e),ai=s(e,"P",{});var j4=i(ai);i_=r(j4,"\u{1F917} Transformers status: not yet implemented"),j4.forEach(t),Jf=f(e),be=s(e,"H2",{class:!0});var Ad=i(be);Qe=s(Ad,"A",{id:!0,class:!0,href:!0});var x4=i(Qe);Ln=s(x4,"SPAN",{});var M4=i(Ln);v(Ol.$$.fragment,M4),M4.forEach(t),x4.forEach(t),o_=f(Ad),Tn=s(Ad,"SPAN",{});var $4=i(Tn);r_=r($4,"DP+PP+TP"),$4.forEach(t),Ad.forEach(t),Qf=f(e),si=s(e,"P",{});var N4=i(si);n_=r(N4,"To get an even more efficient training a 3D parallelism is used where PP is combined with TP and DP. This can be seen in the following diagram."),N4.forEach(t),ec=f(e),ii=s(e,"P",{});var z4=i(ii);oi=s(z4,"IMG",{src:!0,alt:!0}),z4.forEach(t),tc=f(e),et=s(e,"P",{});var Od=i(et);p_=r(Od,"This diagram is from a blog post "),jl=s(Od,"A",{href:!0,rel:!0});var C4=i(jl);h_=r(C4,"3D parallelism: Scaling to trillion-parameter models"),C4.forEach(t),f_=r(Od,", which is a good read as well."),Od.forEach(t),lc=f(e),ri=s(e,"P",{});var R4=i(ri);c_=r(R4,"Since each dimension requires at least 2 GPUs, here you\u2019d need at least 8 GPUs."),R4.forEach(t),ac=f(e),ni=s(e,"P",{});var Z4=i(ni);d_=r(Z4,"Implementations:"),Z4.forEach(t),sc=f(e),k=s(e,"UL",{});var Q=i(k);pi=s(Q,"LI",{});var Hb=i(pi);xl=s(Hb,"A",{href:!0,rel:!0});var B4=i(xl);u_=r(B4,"DeepSpeed"),B4.forEach(t),m_=r(Hb," - DeepSpeed also includes an even more efficient DP, which they call ZeRO-DP."),Hb.forEach(t),v_=f(Q),kn=s(Q,"LI",{});var V4=i(kn);Ml=s(V4,"A",{href:!0,rel:!0});var q4=i(Ml);P_=r(q4,"Megatron-LM"),q4.forEach(t),V4.forEach(t),w_=f(Q),Gn=s(Q,"LI",{});var F4=i(Gn);$l=s(F4,"A",{href:!0,rel:!0});var W4=i($l);__=r(W4,"Varuna"),W4.forEach(t),F4.forEach(t),y_=f(Q),Un=s(Q,"LI",{});var H4=i(Un);Nl=s(H4,"A",{href:!0,rel:!0});var Y4=i(Nl);b_=r(Y4,"SageMaker"),Y4.forEach(t),H4.forEach(t),g_=f(Q),In=s(Q,"LI",{});var X4=i(In);zl=s(X4,"A",{href:!0,rel:!0});var K4=i(zl);E_=r(K4,"OSLO"),K4.forEach(t),X4.forEach(t),Q.forEach(t),ic=f(e),hi=s(e,"P",{});var J4=i(hi);D_=r(J4,"\u{1F917} Transformers status: not yet implemented, since we have no PP and TP."),J4.forEach(t),oc=f(e),ge=s(e,"H2",{class:!0});var jd=i(ge);tt=s(jd,"A",{id:!0,class:!0,href:!0});var Q4=i(tt);Sn=s(Q4,"SPAN",{});var e5=i(Sn);v(Cl.$$.fragment,e5),e5.forEach(t),Q4.forEach(t),L_=f(jd),An=s(jd,"SPAN",{});var t5=i(An);T_=r(t5,"ZeRO DP+PP+TP"),t5.forEach(t),jd.forEach(t),rc=f(e),lt=s(e,"P",{});var xd=i(lt);k_=r(xd,"One of the main features of DeepSpeed is ZeRO, which is a super-scalable extension of DP. It has already been discussed in "),fi=s(xd,"A",{href:!0});var l5=i(fi);G_=r(l5,"ZeRO Data Parallelism"),l5.forEach(t),U_=r(xd,". Normally it\u2019s a standalone feature that doesn\u2019t require PP or TP. But it can be combined with PP and TP."),xd.forEach(t),nc=f(e),ci=s(e,"P",{});var a5=i(ci);I_=r(a5,"When ZeRO-DP is combined with PP (and optionally TP) it typically enables only ZeRO stage 1 (optimizer sharding)."),a5.forEach(t),pc=f(e),di=s(e,"P",{});var s5=i(di);S_=r(s5,"While it\u2019s theoretically possible to use ZeRO stage 2 (gradient sharding) with Pipeline Parallelism, it will have bad performance impacts. There would need to be an additional reduce-scatter collective for every micro-batch to aggregate the gradients before sharding, which adds a potentially significant communication overhead. By nature of Pipeline Parallelism, small micro-batches are used and instead the focus is on trying to balance arithmetic intensity (micro-batch size) with minimizing the Pipeline bubble (number of micro-batches). Therefore those communication costs are going to hurt."),s5.forEach(t),hc=f(e),at=s(e,"P",{});var Md=i(at);A_=r(Md,"In addition, There are already fewer layers than normal due to PP and so the memory savings won\u2019t be huge. PP already reduces gradient size by "),On=s(Md,"CODE",{});var i5=i(On);O_=r(i5,"1/PP"),i5.forEach(t),j_=r(Md,", and so gradient sharding savings on top of that are less significant than pure DP."),Md.forEach(t),fc=f(e),ui=s(e,"P",{});var o5=i(ui);x_=r(o5,"ZeRO stage 3 is not a good choice either for the same reason - more inter-node communications required."),o5.forEach(t),cc=f(e),mi=s(e,"P",{});var r5=i(mi);M_=r(r5,"And since we have ZeRO, the other benefit is ZeRO-Offload. Since this is stage 1 optimizer states can be offloaded to CPU."),r5.forEach(t),dc=f(e),vi=s(e,"P",{});var n5=i(vi);$_=r(n5,"Implementations:"),n5.forEach(t),uc=f(e),st=s(e,"UL",{});var $d=i(st);it=s($d,"LI",{});var Up=i(it);Rl=s(Up,"A",{href:!0,rel:!0});var p5=i(Rl);N_=r(p5,"Megatron-DeepSpeed"),p5.forEach(t),z_=r(Up," and "),Zl=s(Up,"A",{href:!0,rel:!0});var h5=i(Zl);C_=r(h5,"Megatron-Deepspeed from BigScience"),h5.forEach(t),R_=r(Up,", which is the fork of the former repo."),Up.forEach(t),Z_=f($d),jn=s($d,"LI",{});var f5=i(jn);Bl=s(f5,"A",{href:!0,rel:!0});var c5=i(Bl);B_=r(c5,"OSLO"),c5.forEach(t),f5.forEach(t),$d.forEach(t),mc=f(e),Pi=s(e,"P",{});var d5=i(Pi);V_=r(d5,"Important papers:"),d5.forEach(t),vc=f(e),wi=s(e,"UL",{});var u5=i(wi);xn=s(u5,"LI",{});var m5=i(xn);Vl=s(m5,"A",{href:!0,rel:!0});var v5=i(Vl);q_=r(v5,"Using DeepSpeed and Megatron to Train Megatron-Turing NLG 530B, A Large-Scale Generative Language Model"),v5.forEach(t),m5.forEach(t),u5.forEach(t),Pc=f(e),_i=s(e,"P",{});var P5=i(_i);F_=r(P5,"\u{1F917} Transformers status: not yet implemented, since we have no PP and TP."),P5.forEach(t),wc=f(e),Ee=s(e,"H2",{class:!0});var Nd=i(Ee);ot=s(Nd,"A",{id:!0,class:!0,href:!0});var w5=i(ot);Mn=s(w5,"SPAN",{});var _5=i(Mn);v(ql.$$.fragment,_5),_5.forEach(t),w5.forEach(t),W_=f(Nd),$n=s(Nd,"SPAN",{});var y5=i($n);H_=r(y5,"FlexFlow"),y5.forEach(t),Nd.forEach(t),_c=f(e),Fl=s(e,"P",{});var Yb=i(Fl);Wl=s(Yb,"A",{href:!0,rel:!0});var b5=i(Wl);Y_=r(b5,"FlexFlow"),b5.forEach(t),X_=r(Yb," also solves the parallelization problem in a slightly different approach."),Yb.forEach(t),yc=f(e),Hl=s(e,"P",{});var Xb=i(Hl);K_=r(Xb,"Paper: "),Yl=s(Xb,"A",{href:!0,rel:!0});var g5=i(Yl);J_=r(g5,"\u201CBeyond Data and Model Parallelism for Deep Neural Networks\u201D by Zhihao Jia, Matei Zaharia, Alex Aiken"),g5.forEach(t),Xb.forEach(t),bc=f(e),yi=s(e,"P",{});var E5=i(yi);Q_=r(E5,"It performs a sort of 4D Parallelism over Sample-Operator-Attribute-Parameter."),E5.forEach(t),gc=f(e),x=s(e,"OL",{});var mt=i(x);Nn=s(mt,"LI",{});var D5=i(Nn);ey=r(D5,"Sample = Data Parallelism (sample-wise parallel)"),D5.forEach(t),ty=f(mt),zn=s(mt,"LI",{});var L5=i(zn);ly=r(L5,"Operator = Parallelize a single operation into several sub-operations"),L5.forEach(t),ay=f(mt),Cn=s(mt,"LI",{});var T5=i(Cn);sy=r(T5,"Attribute = Data Parallelism (length-wise parallel)"),T5.forEach(t),iy=f(mt),Rn=s(mt,"LI",{});var k5=i(Rn);oy=r(k5,"Parameter = Model Parallelism (regardless of dimension - horizontal or vertical)"),k5.forEach(t),mt.forEach(t),Ec=f(e),bi=s(e,"P",{});var G5=i(bi);ry=r(G5,"Examples:"),G5.forEach(t),Dc=f(e),gi=s(e,"UL",{});var U5=i(gi);Zn=s(U5,"LI",{});var I5=i(Zn);ny=r(I5,"Sample"),I5.forEach(t),U5.forEach(t),Lc=f(e),Ei=s(e,"P",{});var S5=i(Ei);py=r(S5,"Let\u2019s take 10 batches of sequence length 512. If we parallelize them by sample dimension into 2 devices, we get 10 x 512 which becomes be 5 x 2 x 512."),S5.forEach(t),Tc=f(e),Di=s(e,"UL",{});var A5=i(Di);Bn=s(A5,"LI",{});var O5=i(Bn);hy=r(O5,"Operator"),O5.forEach(t),A5.forEach(t),kc=f(e),Li=s(e,"P",{});var j5=i(Li);fy=r(j5,"If we perform layer normalization, we compute std first and mean second, and then we can normalize data. Operator parallelism allows computing std and mean in parallel. So if we parallelize them by operator dimension into 2 devices (cuda:0, cuda:1), first we copy input data into both devices, and cuda:0 computes std, cuda:1 computes mean at the same time."),j5.forEach(t),Gc=f(e),Ti=s(e,"UL",{});var x5=i(Ti);Vn=s(x5,"LI",{});var M5=i(Vn);cy=r(M5,"Attribute"),M5.forEach(t),x5.forEach(t),Uc=f(e),ki=s(e,"P",{});var $5=i(ki);dy=r($5,"We have 10 batches of 512 length. If we parallelize them by attribute dimension into 2 devices, 10 x 512 will be 10 x 2 x 256."),$5.forEach(t),Ic=f(e),Gi=s(e,"UL",{});var N5=i(Gi);qn=s(N5,"LI",{});var z5=i(qn);uy=r(z5,"Parameter"),z5.forEach(t),N5.forEach(t),Sc=f(e),Ui=s(e,"P",{});var C5=i(Ui);my=r(C5,"It is similar with tensor model parallelism or naive layer-wise model parallelism."),C5.forEach(t),Ac=f(e),Ii=s(e,"P",{});var R5=i(Ii);Si=s(R5,"IMG",{src:!0,alt:!0}),R5.forEach(t),Oc=f(e),Ai=s(e,"P",{});var Z5=i(Ai);vy=r(Z5,"The significance of this framework is that it takes resources like (1) GPU/TPU/CPU vs. (2) RAM/DRAM vs. (3) fast-intra-connect/slow-inter-connect and it automatically optimizes all these  algorithmically deciding which parallelisation to use where."),Z5.forEach(t),jc=f(e),Oi=s(e,"P",{});var B5=i(Oi);Py=r(B5,"One very important aspect is that FlexFlow is designed for optimizing DNN parallelizations for models with static and fixed workloads, since models with dynamic behavior may prefer different parallelization strategies across iterations."),B5.forEach(t),xc=f(e),ji=s(e,"P",{});var V5=i(ji);wy=r(V5,"So the promise is very attractive - it runs a 30min simulation on the cluster of choice and it comes up with the best strategy to utilise this specific environment. If you add/remove/replace any parts it\u2019ll run and re-optimize the plan for that. And then you can train. A different setup will have its own custom optimization."),V5.forEach(t),Mc=f(e),rt=s(e,"P",{});var zd=i(rt);_y=r(zd,"\u{1F917} Transformers status: not yet integrated. We already have our models FX-trace-able via "),Xl=s(zd,"A",{href:!0,rel:!0});var q5=i(Xl);yy=r(q5,"transformers.utils.fx"),q5.forEach(t),by=r(zd,", which is a prerequisite for FlexFlow, so someone needs to figure out what needs to be done to make FlexFlow work with our models."),zd.forEach(t),$c=f(e),De=s(e,"H2",{class:!0});var Cd=i(De);nt=s(Cd,"A",{id:!0,class:!0,href:!0});var F5=i(nt);Fn=s(F5,"SPAN",{});var W5=i(Fn);v(Kl.$$.fragment,W5),W5.forEach(t),F5.forEach(t),gy=f(Cd),Wn=s(Cd,"SPAN",{});var H5=i(Wn);Ey=r(H5,"Which Strategy To Use When"),H5.forEach(t),Cd.forEach(t),Nc=f(e),xi=s(e,"P",{});var Y5=i(xi);Dy=r(Y5,"Here is a very rough outline at which parallelism strategy to use when. The first on each list is typically faster."),Y5.forEach(t),zc=f(e),Mi=s(e,"P",{});var X5=i(Mi);Hn=s(X5,"STRONG",{});var K5=i(Hn);Ly=r(K5,"\u21E8 Single GPU"),K5.forEach(t),X5.forEach(t),Cc=f(e),W=s(e,"UL",{});var ao=i(W);Jl=s(ao,"LI",{});var Rd=i(Jl);Yn=s(Rd,"P",{});var J5=i(Yn);Ty=r(J5,"Model fits onto a single GPU:"),J5.forEach(t),ky=f(Rd),Xn=s(Rd,"OL",{});var Q5=i(Xn);Kn=s(Q5,"LI",{});var e6=i(Kn);Gy=r(e6,"Normal use"),e6.forEach(t),Q5.forEach(t),Rd.forEach(t),Uy=f(ao),Ql=s(ao,"LI",{});var Zd=i(Ql);Jn=s(Zd,"P",{});var t6=i(Jn);Iy=r(t6,"Model doesn\u2019t fit onto a single GPU:"),t6.forEach(t),Sy=f(Zd),ea=s(Zd,"OL",{});var Bd=i(ea);Qn=s(Bd,"LI",{});var l6=i(Qn);Ay=r(l6,"ZeRO + Offload CPU and optionally NVMe"),l6.forEach(t),Oy=f(Bd),ep=s(Bd,"LI",{});var a6=i(ep);jy=r(a6,"as above plus Memory Centric Tiling (see below for details) if the largest layer can\u2019t fit into a single GPU"),a6.forEach(t),Bd.forEach(t),Zd.forEach(t),xy=f(ao),tp=s(ao,"LI",{});var s6=i(tp);lp=s(s6,"P",{});var i6=i(lp);My=r(i6,"Largest Layer not fitting into a single GPU:"),i6.forEach(t),s6.forEach(t),ao.forEach(t),Rc=f(e),$i=s(e,"OL",{});var o6=i($i);Le=s(o6,"LI",{});var so=i(Le);$y=r(so,"ZeRO - Enable "),ta=s(so,"A",{href:!0,rel:!0});var r6=i(ta);Ny=r(r6,"Memory Centric Tiling"),r6.forEach(t),zy=r(so," (MCT). It allows you to run arbitrarily large layers by automatically splitting them and executing them sequentially. MCT reduces the number of parameters that are live on a GPU, but it does not affect the activation memory. As this need is very rare as of this writing a manual override of "),ap=s(so,"CODE",{});var n6=i(ap);Cy=r(n6,"torch.nn.Linear"),n6.forEach(t),Ry=r(so," needs to be done by the user."),so.forEach(t),o6.forEach(t),Zc=f(e),Ni=s(e,"P",{});var p6=i(Ni);sp=s(p6,"STRONG",{});var h6=i(sp);Zy=r(h6,"\u21E8 Single Node / Multi-GPU"),h6.forEach(t),p6.forEach(t),Bc=f(e),H=s(e,"UL",{});var io=i(H);la=s(io,"LI",{});var Vd=i(la);ip=s(Vd,"P",{});var f6=i(ip);By=r(f6,"Model fits onto a single GPU:"),f6.forEach(t),Vy=f(Vd),aa=s(Vd,"OL",{});var qd=i(aa);op=s(qd,"LI",{});var c6=i(op);qy=r(c6,"DDP - Distributed DP"),c6.forEach(t),Fy=f(qd),rp=s(qd,"LI",{});var d6=i(rp);Wy=r(d6,"ZeRO - may or may not be faster depending on the situation and configuration used"),d6.forEach(t),qd.forEach(t),Vd.forEach(t),Hy=f(io),sa=s(io,"LI",{});var Fd=i(sa);np=s(Fd,"P",{});var u6=i(np);Yy=r(u6,"Model doesn\u2019t fit onto a single GPU:"),u6.forEach(t),Xy=f(Fd),Te=s(Fd,"OL",{});var oo=i(Te);pp=s(oo,"LI",{});var m6=i(pp);hp=s(m6,"P",{});var v6=i(hp);Ky=r(v6,"PP"),v6.forEach(t),m6.forEach(t),Jy=f(oo),fp=s(oo,"LI",{});var P6=i(fp);cp=s(P6,"P",{});var w6=i(cp);Qy=r(w6,"ZeRO"),w6.forEach(t),P6.forEach(t),eb=f(oo),ke=s(oo,"LI",{});var ro=i(ke);dp=s(ro,"P",{});var _6=i(dp);tb=r(_6,"TP"),_6.forEach(t),lb=f(ro),up=s(ro,"P",{});var y6=i(up);ab=r(y6,"With very fast intra-node connectivity of NVLINK or NVSwitch all three should be mostly on par, without these PP will be faster than TP or ZeRO. The degree of TP may also make a difference. Best to experiment to find the winner on your particular setup."),y6.forEach(t),sb=f(ro),mp=s(ro,"P",{});var b6=i(mp);ib=r(b6,"TP is almost always used within a single node. That is TP size <= gpus per node."),b6.forEach(t),ro.forEach(t),oo.forEach(t),Fd.forEach(t),ob=f(io),ia=s(io,"LI",{});var Wd=i(ia);vp=s(Wd,"P",{});var g6=i(vp);rb=r(g6,"Largest Layer not fitting into a single GPU:"),g6.forEach(t),nb=f(Wd),oa=s(Wd,"OL",{});var Hd=i(oa);Pp=s(Hd,"LI",{});var E6=i(Pp);pb=r(E6,"If not using ZeRO - must use TP, as PP alone won\u2019t be able to fit."),E6.forEach(t),hb=f(Hd),wp=s(Hd,"LI",{});var D6=i(wp);fb=r(D6,"With ZeRO see the same entry for \u201CSingle GPU\u201D above"),D6.forEach(t),Hd.forEach(t),Wd.forEach(t),io.forEach(t),Vc=f(e),zi=s(e,"P",{});var L6=i(zi);_p=s(L6,"STRONG",{});var T6=i(_p);cb=r(T6,"\u21E8 Multi-Node / Multi-GPU"),T6.forEach(t),L6.forEach(t),qc=f(e),pt=s(e,"UL",{});var Yd=i(pt);ra=s(Yd,"LI",{});var Xd=i(ra);yp=s(Xd,"P",{});var k6=i(yp);db=r(k6,"When you have fast inter-node connectivity:"),k6.forEach(t),ub=f(Xd),na=s(Xd,"OL",{});var Kd=i(na);bp=s(Kd,"LI",{});var G6=i(bp);mb=r(G6,"ZeRO - as it requires close to no modifications to the model"),G6.forEach(t),vb=f(Kd),gp=s(Kd,"LI",{});var U6=i(gp);Pb=r(U6,"PP+TP+DP - less communications, but requires massive changes to the model"),U6.forEach(t),Kd.forEach(t),Xd.forEach(t),wb=f(Yd),pa=s(Yd,"LI",{});var Jd=i(pa);Ep=s(Jd,"P",{});var I6=i(Ep);_b=r(I6,"when you have slow inter-node connectivity and still low on GPU memory:"),I6.forEach(t),yb=f(Jd),Dp=s(Jd,"OL",{});var S6=i(Dp);Lp=s(S6,"LI",{});var A6=i(Lp);bb=r(A6,"DP+PP+TP+ZeRO-1"),A6.forEach(t),S6.forEach(t),Jd.forEach(t),Yd.forEach(t),this.h()},h(){c(te,"name","hf:doc:metadata"),c(te,"content",JSON.stringify(C6)),c(Ge,"id","efficient-training-on-multiple-gpus"),c(Ge,"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"),c(Ge,"href","#efficient-training-on-multiple-gpus"),c(le,"class","relative group"),c(Ue,"id","concepts"),c(Ue,"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"),c(Ue,"href","#concepts"),c(ae,"class","relative group"),c(Ie,"id","scalability-strategy"),c(Ie,"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"),c(Ie,"href","#scalability-strategy"),c(se,"class","relative group"),c(Ae,"id","data-parallelism"),c(Ae,"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"),c(Ae,"href","#data-parallelism"),c(re,"class","relative group"),c(Gt,"href","https://pytorch.org/docs/master/generated/torch.nn.DataParallel.html"),c(Gt,"rel","nofollow"),c(Oe,"id","dp-vs-ddp"),c(Oe,"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"),c(Oe,"href","#dp-vs-ddp"),c(ne,"class","relative group"),c(St,"href","https://pytorch.org/docs/master/notes/ddp.html"),c(St,"rel","nofollow"),c(xt,"href","https://pytorch.org/docs/master/generated/torch.nn.DataParallel.html"),c(xt,"rel","nofollow"),c($t,"href","https://pytorch.org/docs/master/distributed.html"),c($t,"rel","nofollow"),c(Nt,"href","https://www.telesens.co/2019/04/04/distributed-data-parallel-training-using-pytorch-on-aws/"),c(Nt,"rel","nofollow"),c(Ia,"align","left"),c(Sa,"align","right"),c(Aa,"align","left"),c(Oa,"align","right"),c(ja,"align","left"),c(xa,"align","right"),c(Ma,"align","left"),c($a,"align","right"),c(ze,"id","zero-data-parallelism"),c(ze,"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"),c(ze,"href","#zero-data-parallelism"),c(me,"class","relative group"),c(Zt,"href","https://www.microsoft.com/en-us/research/blog/zero-deepspeed-new-system-optimizations-enable-training-models-with-over-100-billion-parameters/"),c(Zt,"rel","nofollow"),ee(Za.src,Jb="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/parallelism-zero.png")||c(Za,"src",Jb),c(Za,"alt","DeepSpeed-Image-1"),c(Ft,"href","https://www.deepspeed.ai/features/#the-zero-redundancy-optimizer"),c(Ft,"rel","nofollow"),c(Wt,"href","https://github.com/facebookresearch/fairscale/#optimizer-state-sharding-zero"),c(Wt,"rel","nofollow"),c(Ht,"href","main_classes/trainer#trainer-integrations"),c(Re,"id","naive-model-parallelism-vertical-and-pipeline-parallelism"),c(Re,"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"),c(Re,"href","#naive-model-parallelism-vertical-and-pipeline-parallelism"),c(Pe,"class","relative group"),c(Kt,"href","https://ai.googleblog.com/2019/03/introducing-gpipe-open-source-library.html"),c(Kt,"rel","nofollow"),ee(Ps.src,Qb="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/parallelism-gpipe-bubble.png")||c(Ps,"src",Qb),c(Ps,"alt","mp-pp"),c(Qt,"href","https://github.com/pytorch/pytorch/pull/50693"),c(Qt,"rel","nofollow"),c(tl,"href","https://pytorch.org/docs/stable/pipeline.html"),c(tl,"rel","nofollow"),c(ll,"href","https://github.com/pytorch/pytorch/blob/master/benchmarks/distributed/pipeline/pipe.py"),c(ll,"rel","nofollow"),c(al,"href","https://fairscale.readthedocs.io/en/latest/tutorials/pipe.html"),c(al,"rel","nofollow"),c(sl,"href","https://www.deepspeed.ai/tutorials/pipeline/"),c(sl,"rel","nofollow"),c(il,"href","https://github.com/NVIDIA/Megatron-LM"),c(il,"rel","nofollow"),c(ol,"href","https://github.com/microsoft/varuna"),c(ol,"rel","nofollow"),c(rl,"href","https://arxiv.org/abs/2111.05972"),c(rl,"rel","nofollow"),c(nl,"href","https://github.com/tunib-ai/oslo"),c(nl,"rel","nofollow"),c(pl,"href","https://docs.aws.amazon.com/sagemaker/latest/dg/model-parallel-core-features.html"),c(pl,"rel","nofollow"),ee(As.src,eg="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/parallelism-sagemaker-interleaved-pipeline.png")||c(As,"src",eg),c(As,"alt","interleaved-pipeline-execution"),c(Xe,"id","tensor-parallelism"),c(Xe,"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"),c(Xe,"href","#tensor-parallelism"),c(_e,"class","relative group"),c(fl,"href","https://github.com/NVIDIA/Megatron-LM"),c(fl,"rel","nofollow"),c(cl,"href","https://arxiv.org/abs/2104.04473"),c(cl,"rel","nofollow"),ee(Ms.src,tg="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/parallelism-tp-parallel_gemm.png")||c(Ms,"src",tg),c(Ms,"alt","Parallel GEMM"),ee($s.src,lg="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/parallelism-tp-independent-gelu.png")||c($s,"src",lg),c($s,"alt","independent GeLU"),ee(Ns.src,ag="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/parallelism-tp-parallel_shard_processing.png")||c(Ns,"src",ag),c(Ns,"alt","parallel shard processing"),ee(zs.src,sg="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/parallelism-tp-parallel_self_attention.png")||c(zs,"src",sg),c(zs,"alt","parallel self-attention"),c(vl,"href","https://github.com/huggingface/transformers/issues/10321#issuecomment-783543530"),c(vl,"rel","nofollow"),c(Pl,"href","https://github.com/anton-l"),c(Pl,"rel","nofollow"),c(wl,"href","https://www.deepspeed.ai/features/#model-parallelism"),c(wl,"rel","nofollow"),c(_l,"href","https://github.com/NVIDIA/Megatron-LM"),c(_l,"rel","nofollow"),c(yl,"href","https://github.com/tunib-ai/parallelformers"),c(yl,"rel","nofollow"),c(bl,"href","https://arxiv.org/abs/2111.05972"),c(bl,"rel","nofollow"),c(gl,"href","https://github.com/tunib-ai/oslo"),c(gl,"rel","nofollow"),c(Dl,"href","https://github.com/tunib-ai/parallelformers"),c(Dl,"rel","nofollow"),c(Ll,"href","https://www.deepspeed.ai/tutorials/inference-tutorial/"),c(Ll,"rel","nofollow"),c(Ke,"id","dppp"),c(Ke,"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"),c(Ke,"href","#dppp"),c(ye,"class","relative group"),c(kl,"href","https://www.deepspeed.ai/tutorials/pipeline/"),c(kl,"rel","nofollow"),ee(Qs.src,ig="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/parallelism-zero-dp-pp.png")||c(Qs,"src",ig),c(Qs,"alt","dp-pp-2d"),c(Gl,"href","https://github.com/microsoft/DeepSpeed"),c(Gl,"rel","nofollow"),c(Ul,"href","https://github.com/NVIDIA/Megatron-LM"),c(Ul,"rel","nofollow"),c(Il,"href","https://github.com/microsoft/varuna"),c(Il,"rel","nofollow"),c(Sl,"href","https://arxiv.org/abs/2111.05972"),c(Sl,"rel","nofollow"),c(Al,"href","https://github.com/tunib-ai/oslo"),c(Al,"rel","nofollow"),c(Qe,"id","dppptp"),c(Qe,"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"),c(Qe,"href","#dppptp"),c(be,"class","relative group"),ee(oi.src,og="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/parallelism-deepspeed-3d.png")||c(oi,"src",og),c(oi,"alt","dp-pp-tp-3d"),c(jl,"href","https://www.microsoft.com/en-us/research/blog/deepspeed-extreme-scale-model-training-for-everyone/"),c(jl,"rel","nofollow"),c(xl,"href","https://github.com/microsoft/DeepSpeed"),c(xl,"rel","nofollow"),c(Ml,"href","https://github.com/NVIDIA/Megatron-LM"),c(Ml,"rel","nofollow"),c($l,"href","https://github.com/microsoft/varuna"),c($l,"rel","nofollow"),c(Nl,"href","https://arxiv.org/abs/2111.05972"),c(Nl,"rel","nofollow"),c(zl,"href","https://github.com/tunib-ai/oslo"),c(zl,"rel","nofollow"),c(tt,"id","zero-dppptp"),c(tt,"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"),c(tt,"href","#zero-dppptp"),c(ge,"class","relative group"),c(fi,"href","#zero-data-parallelism"),c(Rl,"href","https://github.com/microsoft/Megatron-DeepSpeed"),c(Rl,"rel","nofollow"),c(Zl,"href","https://github.com/bigscience-workshop/Megatron-DeepSpeed"),c(Zl,"rel","nofollow"),c(Bl,"href","https://github.com/tunib-ai/oslo"),c(Bl,"rel","nofollow"),c(Vl,"href","https://arxiv.org/abs/2201.11990"),c(Vl,"rel","nofollow"),c(ot,"id","flexflow"),c(ot,"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"),c(ot,"href","#flexflow"),c(Ee,"class","relative group"),c(Wl,"href","https://github.com/flexflow/FlexFlow"),c(Wl,"rel","nofollow"),c(Yl,"href","https://arxiv.org/abs/1807.05358"),c(Yl,"rel","nofollow"),ee(Si.src,rg="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/parallelism-flexflow.jpeg")||c(Si,"src",rg),c(Si,"alt","flex-flow-soap"),c(Xl,"href","https://github.com/huggingface/transformers/blob/master/src/transformers/utils/fx.py"),c(Xl,"rel","nofollow"),c(nt,"id","which-strategy-to-use-when"),c(nt,"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"),c(nt,"href","#which-strategy-to-use-when"),c(De,"class","relative group"),c(ta,"href","https://deepspeed.readthedocs.io/en/latest/zero3.html#memory-centric-tiling"),c(ta,"rel","nofollow")},m(e,n){l(document.head,te),p(e,Sp,n),p(e,le,n),l(le,Ge),l(Ge,no),P(vt,no,null),l(le,Qd),l(le,po),l(po,eu),p(e,Ap,n),p(e,ha,n),l(ha,tu),p(e,Op,n),p(e,fa,n),l(fa,lu),p(e,jp,n),p(e,ae,n),l(ae,Ue),l(Ue,ho),P(Pt,ho,null),l(ae,au),l(ae,fo),l(fo,su),p(e,xp,n),p(e,ca,n),l(ca,iu),p(e,Mp,n),p(e,E,n),l(E,da),l(da,co),l(co,ou),l(da,ru),l(E,nu),l(E,ua),l(ua,uo),l(uo,pu),l(ua,hu),l(E,fu),l(E,ma),l(ma,mo),l(mo,cu),l(ma,du),l(E,uu),l(E,va),l(va,vo),l(vo,mu),l(va,vu),l(E,Pu),l(E,Pa),l(Pa,Po),l(Po,wu),l(Pa,_u),p(e,$p,n),p(e,wa,n),l(wa,yu),p(e,Np,n),p(e,se,n),l(se,Ie),l(Ie,wo),P(wt,wo,null),l(se,bu),l(se,_o),l(_o,gu),p(e,zp,n),p(e,_a,n),l(_a,yo),l(yo,Eu),p(e,Cp,n),p(e,$,n),l($,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,ab),l(ke,sb),l(ke,mp),l(mp,ib),l(H,ob),l(H,ia),l(ia,vp),l(vp,rb),l(ia,nb),l(ia,oa),l(oa,Pp),l(Pp,pb),l(oa,hb),l(oa,wp),l(wp,fb),p(e,Vc,n),p(e,zi,n),l(zi,_p),l(_p,cb),p(e,qc,n),p(e,pt,n),l(pt,ra),l(ra,yp),l(yp,db),l(ra,ub),l(ra,na),l(na,bp),l(bp,mb),l(na,vb),l(na,gp),l(gp,Pb),l(pt,wb),l(pt,pa),l(pa,Ep),l(Ep,_b),l(pa,yb),l(pa,Dp),l(Dp,Lp),l(Lp,bb),Fc=!0},p:$6,i(e){Fc||(w(vt.$$.fragment,e),w(Pt.$$.fragment,e),w(wt.$$.fragment,e),w(kt.$$.fragment,e),w(Ut.$$.fragment,e),w(Ct.$$.fragment,e),w(Rt.$$.fragment,e),w(Bt.$$.fragment,e),w(Vt.$$.fragment,e),w(qt.$$.fragment,e),w(Yt.$$.fragment,e),w(Xt.$$.fragment,e),w(hl.$$.fragment,e),w(Tl.$$.fragment,e),w(Ol.$$.fragment,e),w(Cl.$$.fragment,e),w(ql.$$.fragment,e),w(Kl.$$.fragment,e),Fc=!0)},o(e){_(vt.$$.fragment,e),_(Pt.$$.fragment,e),_(wt.$$.fragment,e),_(kt.$$.fragment,e),_(Ut.$$.fragment,e),_(Ct.$$.fragment,e),_(Rt.$$.fragment,e),_(Bt.$$.fragment,e),_(Vt.$$.fragment,e),_(qt.$$.fragment,e),_(Yt.$$.fragment,e),_(Xt.$$.fragment,e),_(hl.$$.fragment,e),_(Tl.$$.fragment,e),_(Ol.$$.fragment,e),_(Cl.$$.fragment,e),_(ql.$$.fragment,e),_(Kl.$$.fragment,e),Fc=!1},d(e){t(te),e&&t(Sp),e&&t(le),y(vt),e&&t(Ap),e&&t(ha),e&&t(Op),e&&t(fa),e&&t(jp),e&&t(ae),y(Pt),e&&t(xp),e&&t(ca),e&&t(Mp),e&&t(E),e&&t($p),e&&t(wa),e&&t(Np),e&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(ec),e&&t(ii),e&&t(tc),e&&t(et),e&&t(lc),e&&t(ri),e&&t(ac),e&&t(ni),e&&t(sc),e&&t(k),e&&t(ic),e&&t(hi),e&&t(oc),e&&t(ge),y(Cl),e&&t(rc),e&&t(lt),e&&t(nc),e&&t(ci),e&&t(pc),e&&t(di),e&&t(hc),e&&t(at),e&&t(fc),e&&t(ui),e&&t(cc),e&&t(mi),e&&t(dc),e&&t(vi),e&&t(uc),e&&t(st),e&&t(mc),e&&t(Pi),e&&t(vc),e&&t(wi),e&&t(Pc),e&&t(_i),e&&t(wc),e&&t(Ee),y(ql),e&&t(_c),e&&t(Fl),e&&t(yc),e&&t(Hl),e&&t(bc),e&&t(yi),e&&t(gc),e&&t(x),e&&t(Ec),e&&t(bi),e&&t(Dc),e&&t(gi),e&&t(Lc),e&&t(Ei),e&&t(Tc),e&&t(Di),e&&t(kc),e&&t(Li),e&&t(Gc),e&&t(Ti),e&&t(Uc),e&&t(ki),e&&t(Ic),e&&t(Gi),e&&t(Sc),e&&t(Ui),e&&t(Ac),e&&t(Ii),e&&t(Oc),e&&t(Ai),e&&t(jc),e&&t(Oi),e&&t(xc),e&&t(ji),e&&t(Mc),e&&t(rt),e&&t($c),e&&t(De),y(Kl),e&&t(Nc),e&&t(xi),e&&t(zc),e&&t(Mi),e&&t(Cc),e&&t(W),e&&t(Rc),e&&t($i),e&&t(Zc),e&&t(Ni),e&&t(Bc),e&&t(H),e&&t(Vc),e&&t(zi),e&&t(qc),e&&t(pt)}}}const C6={local:"efficient-training-on-multiple-gpus",sections:[{local:"concepts",title:"Concepts"},{local:"scalability-strategy",title:"Scalability Strategy"},{local:"data-parallelism",sections:[{local:"dp-vs-ddp",title:"DP vs DDP"}],title:"Data Parallelism"},{local:"zero-data-parallelism",title:"ZeRO Data Parallelism"},{local:"naive-model-parallelism-vertical-and-pipeline-parallelism",title:"Naive Model Parallelism (Vertical) and Pipeline Parallelism"},{local:"tensor-parallelism",title:"Tensor Parallelism"},{local:"dppp",title:"DP+PP"},{local:"dppptp",title:"DP+PP+TP"},{local:"zero-dppptp",title:"ZeRO DP+PP+TP"},{local:"flexflow",title:"FlexFlow"},{local:"which-strategy-to-use-when",title:"Which Strategy To Use When"}],title:"Efficient Training on Multiple GPUs"};function R6(Kb){return N6(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class q6 extends O6{constructor(te){super();j6(this,te,R6,z6,x6,{})}}export{q6 as default,C6 as metadata};
