显卡不够时,如何训练大型网络
生活随笔
收集整理的這篇文章主要介紹了
显卡不够时,如何训练大型网络
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
https://mp.weixin.qq.com/s?__biz=MzIwNzc2NTk0NQ%3D%3D&chksm=970c2143a07ba855562ca86bfa19b78a26fe2670cac7876feee49748dcaf5ea9b20a9d371c13&idx=1&mid=2247485845&scene=21&sn=b4ea4f518bfdf4a812fb8e00fbfe4845#wechat_redirect
原文在這里
<section style="font-size: 16px;white-space: normal;caret-color: rgb(0, 0, 0);color: rgb(0, 0, 0);box-sizing: border-box;" data-mpa-powered-by="yiban.io"><section style="box-sizing: border-box;font-size: 16px;"><section style="text-align: center;margin-top: 10px;margin-right: 0%;margin-left: 0%;box-sizing: border-box;" powered-by="xiumi.us"><section style="max-width: 100%;vertical-align: middle;display: inline-block;line-height: 0;width: 15%;box-shadow: rgb(0, 0, 0) 0px 0px 0px;border-width: 0px;height: auto;box-sizing: border-box;"><img data-ratio="1" data-src="https://mmbiz.qpic.cn/mmbiz_jpg/5fknb41ib9qFMeJWjsOibhRL3JquicibH6eAEnfE6Uy594RBwRyG7BH4yfWWKtibajVDbxxfG5DzqkvlJUvhzwCCvRQ/640?wx_fmt=jpeg" data-type="jpeg" data-w="1080" style="vertical-align: middle; box-sizing: border-box; width: 100% !important; height: auto !important; visibility: visible !important;" _width="100%" class="" src="https://mmbiz.qpic.cn/mmbiz_jpg/5fknb41ib9qFMeJWjsOibhRL3JquicibH6eAEnfE6Uy594RBwRyG7BH4yfWWKtibajVDbxxfG5DzqkvlJUvhzwCCvRQ/640?wx_fmt=jpeg&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" crossorigin="anonymous" data-fail="0"></section></section><section style="text-align: center;margin-right: 0%;margin-bottom: 15px;margin-left: 0%;box-sizing: border-box;" powered-by="xiumi.us"><section style="display: inline-block;width: 80%;vertical-align: top;box-shadow: rgb(181, 180, 180) 2.82843px 2.82843px 5px;border-style: solid;border-width: 1px;border-radius: 0px;border-color: rgb(62, 62, 62);padding: 8px;box-sizing: border-box;"><section style="margin-right: 0%;margin-left: 0%;box-sizing: border-box;" powered-by="xiumi.us"><section style="font-size: 14px;box-sizing: border-box;"><p style="box-sizing: border-box;">一只小狐貍帶你解鎖 <strong style="box-sizing: border-box;">煉丹術&NLP </strong>秘籍</p></section></section></section></section></section><p style="text-align: left;"><span style="text-align: left;color: rgb(89, 89, 89);font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, "PingFang SC", Cambria, Cochin, Georgia, Times, "Times New Roman", serif;letter-spacing: 0px;"><br></span></p><p style="text-align: left;"><span style="text-align: left;color: rgb(89, 89, 89);font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, "PingFang SC", Cambria, Cochin, Georgia, Times, "Times New Roman", serif;letter-spacing: 0px;">前陣子微軟開源了DeepSpeed訓練框架,從測試效果來看有10倍的速度提升,而且對內存進行了各種優化,最大可以訓練100B(illion)參數的模型。</span><span style="text-align: left;color: rgb(89, 89, 89);font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, "PingFang SC", Cambria, Cochin, Georgia, Times, "Times New Roman", serif;letter-spacing: 0px;">同時發布了這個框架訓練出的17B模型 Turing-NLG,處于目前壕賽事的頂端。</span><br></p></section><section data-tool="mdnice編輯器" data-website="https://www.mdnice.com"><figure data-tool="mdnice編輯器" style="margin-top: 10px;margin-bottom: 10px;"><img data-ratio="0.562962962962963" data-type="jpeg" data-w="1080" data-src="https://mmbiz.qpic.cn/mmbiz_jpg/y3eXggUiaulIOYfhm4iaiaP0ibt6ucyWbu2arAEmuqRCtMNic0LKkL8t7PKldzzrI4QUc7vpwKCxxIWnN1jiaI2NTdcQ/640?wx_fmt=jpeg" style="display: block; margin-right: auto; margin-left: auto; width: 677px !important; height: auto !important; visibility: visible !important;" _width="677px" class="" src="https://mmbiz.qpic.cn/mmbiz_jpg/y3eXggUiaulIOYfhm4iaiaP0ibt6ucyWbu2arAEmuqRCtMNic0LKkL8t7PKldzzrI4QUc7vpwKCxxIWnN1jiaI2NTdcQ/640?wx_fmt=jpeg&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" crossorigin="anonymous" data-fail="0"></figure><section style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin-top: 5px;margin-bottom: 5px;text-align: left;">訓100B的模型就先別想了(狗頭),先把110M的BERT-base訓好上線吧。本文主要介紹模型訓練中速度和內存的優化策略,針對以下幾種情況:</section><ol style="" class="list-paddingleft-2"><li><section style="box-sizing: border-box;line-height: 26px;color: rgb(1, 1, 1);margin-top: 5px;margin-bottom: 5px;text-align: left;"><span style="font-size: 14px;">我明天就要答辯了,今天必須把這十個實驗跑完</span></section></li><li><section style="box-sizing: border-box;line-height: 26px;color: rgb(1, 1, 1);margin-top: 5px;margin-bottom: 5px;text-align: left;"><span style="font-size: 14px;">我的模型有些大,好不容易放到一張卡上,訓完一億樣本之前我就可以領N+1了</span></section></li><li><section style="box-sizing: border-box;line-height: 26px;color: rgb(1, 1, 1);margin-top: 5px;margin-bottom: 5px;text-align: left;"><span style="font-size: 14px;">我想出了一個絕妙的T6模型,卻加載不進12GB的卡里,又拿不到今年的best paper了</span></section></li></ol><section style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin-top: 5px;margin-bottom: 5px;text-align: left;">(以上純屬虛構,如有雷同請趕緊看下文)</section><section style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin-top: 5px;margin-bottom: 5px;text-align: left;">現實總是殘酷的,其實限制大模型訓練只有兩個因素:<strong style="color: rgb(71, 193, 168);">時間和空間(=GPU=錢)</strong>,根據不同情況可以使用的方案大致如下:</section><figure data-tool="mdnice編輯器" style="margin-top: 10px;margin-bottom: 10px;"><img data-ratio="0.5760869565217391" data-type="jpeg" data-w="1472" data-src="https://mmbiz.qpic.cn/mmbiz_jpg/y3eXggUiaulIOYfhm4iaiaP0ibt6ucyWbu2afLoOzUg7zbI3gzsVibgjaFUlDZSGuKuREWmwVXficpMk9kUxbjns99fg/640?wx_fmt=jpeg" style="display: block; margin-right: auto; margin-left: auto; width: 677px !important; height: auto !important; visibility: visible !important;" _width="677px" class="" src="https://mmbiz.qpic.cn/mmbiz_jpg/y3eXggUiaulIOYfhm4iaiaP0ibt6ucyWbu2afLoOzUg7zbI3gzsVibgjaFUlDZSGuKuREWmwVXficpMk9kUxbjns99fg/640?wx_fmt=jpeg&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" crossorigin="anonymous" data-fail="0"></figure><h3 data-tool="mdnice編輯器" style="font-weight: bold;font-size: 20px;color: rgb(89, 89, 89);margin-top: 5px;margin-bottom: 5px;text-align: left;"><span style="font-size: 18px;">1. 梯度累加 Gradient Accumulation</span></h3><section style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin-top: 5px;margin-bottom: 5px;text-align: left;">如果只有單卡,且可以加載模型,但batch受限的話可以使用梯度累加,進行N次前向后反向更新一次參數,相當于擴大了N倍的batch size。</section><section style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin-top: 5px;margin-bottom: 5px;text-align: left;">正常的訓練代碼是這樣的:</section><pre data-tool="mdnice編輯器" style="margin-top: 10px;margin-bottom: 10px;"><section style="overflow-x: auto;padding: 16px;color: rgb(51, 51, 51);background: rgb(248, 248, 248);display: -webkit-box;font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;margin-top: 5px;margin-bottom: 5px;text-align: left;">for i, (inputs, labels) in enumerate(training_set):<br> loss = model(inputs, labels) # 計算loss<br> optimizer.zero_grad() # 清空梯度<br> loss.backward() # 反向計算梯度<br> optimizer.step() # 更新參數<br></section></pre><section style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin-top: 5px;margin-bottom: 5px;text-align: left;">加入梯度累加后:</section><pre data-tool="mdnice編輯器" style="margin-top: 10px;margin-bottom: 10px;"><section style="overflow-x: auto;padding: 16px;color: rgb(51, 51, 51);background: rgb(248, 248, 248);display: -webkit-box;font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;margin-top: 5px;margin-bottom: 5px;text-align: left;">for i, (inputs, labels) in enumerate(training_set):<br> loss = model(inputs, labels) # 計算loss<br> loss = loss / accumulation_steps # Normalize our loss (if averaged)<br> loss.backward() # 反向計算梯度,累加到之前梯度上<br> if (i+1) % accumulation_steps == 0:<br> optimizer.step() # 更新參數<br> model.zero_grad() # 清空梯度<br></section></pre><section style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin-top: 5px;margin-bottom: 5px;text-align: left;">要注意的是,batch擴大后,如果想保持樣本權重相等,<strong style="color: rgb(71, 193, 168);">學習率也要線性擴大或者適當調整</strong>。另外<strong style="color: rgb(71, 193, 168);">batchnorm也會受到影響</strong>,小batch下的均值和方差肯定不如大batch的精準,可以調整BN中的momentum參數解決[2]。</section><h3 data-tool="mdnice編輯器" style="font-weight: bold;font-size: 20px;color: rgb(89, 89, 89);margin-top: 5px;margin-bottom: 5px;text-align: left;"><span style="font-size: 18px;">2. 梯度檢查點 Gradient Checkpointing</span></h3><section style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin-top: 5px;margin-bottom: 5px;text-align: left;">如果只有一張卡,又想訓大模型,可以嘗試壓縮模型所占顯存。</section><section style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin-top: 5px;margin-bottom: 5px;text-align: left;">梯度檢查點是一種以時間換空間的方法,通過減少保存的激活值壓縮模型占用空間,但是在計算梯度時必須從新計算沒有存儲的激活值。</section><section style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin-top: 5px;margin-bottom: 5px;text-align: left;">細節可以參考陳天奇的Training Deep Nets with Sublinear Memory Cost[3]。</section><section style="text-align: left;margin-top: 5px;margin-bottom: 5px;"><img class="rich_pages __bg_gif" data-ratio="0.22365988909426987" data-type="gif" data-w="541" data-src="https://mmbiz.qpic.cn/mmbiz_gif/y3eXggUiaulLcBuc6aEJibEvjmmBgq7a4YTdUKsfiaia1WKlZ36LZcLqA6EiarWwOSELXC8LskoP3tHIa85nOfMpr8w/640?wx_fmt=gif" style="width: 541px !important; height: auto !important; visibility: visible !important;" _width="541px" src="https://mmbiz.qpic.cn/mmbiz_gif/y3eXggUiaulLcBuc6aEJibEvjmmBgq7a4YTdUKsfiaia1WKlZ36LZcLqA6EiarWwOSELXC8LskoP3tHIa85nOfMpr8w/640?wx_fmt=gif&tp=webp&wxfrom=5&wx_lazy=1" data-order="0" data-fail="0"></section><figure data-tool="mdnice編輯器" style="margin-top: 10px;margin-bottom: 10px;"><figcaption style="margin-top: 5px;text-align: center;color: rgb(136, 136, 136);font-size: 14px;"></figcaption></figure><section style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin-top: 5px;margin-bottom: 5px;text-align: left;">注:第一行節點是前向,第二行是反向</section><h3 data-tool="mdnice編輯器" style="font-weight: bold;font-size: 20px;color: rgb(89, 89, 89);margin-top: 5px;margin-bottom: 5px;text-align: left;"><span style="font-size: 18px;">3. 混合精度訓練 Mixed Precision Training</span></h3><section style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin-top: 5px;margin-bottom: 5px;text-align: left;">混合精度訓練在單卡和多卡情況下都可以使用,通過cuda計算中的half2類型提升運算效率。<strong style="color: rgb(71, 193, 168);">一個half2類型中會存儲兩個FP16的浮點數,在進行基本運算時可以同時進行,因此FP16的期望速度是FP32的兩倍</strong>。舉個Gelu的FP16優化栗子:</section><pre data-tool="mdnice編輯器" style="margin-top: 10px;margin-bottom: 10px;"><section style="overflow-x: auto;padding: 16px;color: rgb(51, 51, 51);background: rgb(248, 248, 248);display: -webkit-box;font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;margin-top: 5px;margin-bottom: 5px;text-align: left;"><span style="color: rgb(153, 153, 136);font-style: italic;line-height: 26px;">//FP32的gelu運算</span><span style="line-height: 26px;"><span style="font-weight: bold;line-height: 26px;">float</span> <span style="color: rgb(153, 0, 0);font-weight: bold;line-height: 26px;">gelu</span><span style="line-height: 26px;">(<span style="font-weight: bold;line-height: 26px;">float</span> x)</span><br></span>{<br> <span style="font-weight: bold;line-height: 26px;">float</span> cdf = <span style="color: rgb(0, 128, 128);line-height: 26px;">0.5f</span> * (<span style="color: rgb(0, 128, 128);line-height: 26px;">1.0f</span> + tanhf((<span style="color: rgb(0, 128, 128);line-height: 26px;">0.7978845608028654f</span> * (x + <span style="color: rgb(0, 128, 128);line-height: 26px;">0.044715f</span> * x * x * x))));<br> <span style="font-weight: bold;line-height: 26px;">return</span> x * cdf;<br>}<br><span style="color: rgb(153, 153, 136);font-style: italic;line-height: 26px;">//FP16的gelu運算</span><span style="line-height: 26px;">half2 <span style="color: rgb(153, 0, 0);font-weight: bold;line-height: 26px;">gelu</span><span style="line-height: 26px;">(half2 val)</span><br></span>{<br> half2 val_pow3 = __hmul2(val, __hmul2(val, val)); <span style="color: rgb(153, 153, 136);font-style: italic;line-height: 26px;">//同時計算兩個x*x*x</span><br> float2 tmp_pow = __half22float2(val_pow3);<br> float2 cdf = __half22float2(val);<br><span style="color: rgb(153, 153, 136);font-style: italic;line-height: 26px;"> //由于tanhf不支持half2類型,只能分開算</span><br> cdf.x = <span style="color: rgb(0, 128, 128);line-height: 26px;">0.5f</span> * (<span style="color: rgb(0, 128, 128);line-height: 26px;">1.0f</span> + tanhf((<span style="color: rgb(0, 128, 128);line-height: 26px;">0.7978845608028654f</span> * (cdf.x + <span style="color: rgb(0, 128, 128);line-height: 26px;">0.044715f</span> * tmp_pow.x))));<br> cdf.y = <span style="color: rgb(0, 128, 128);line-height: 26px;">0.5f</span> * (<span style="color: rgb(0, 128, 128);line-height: 26px;">1.0f</span> + tanhf((<span style="color: rgb(0, 128, 128);line-height: 26px;">0.7978845608028654f</span> * (cdf.y + <span style="color: rgb(0, 128, 128);line-height: 26px;">0.044715f</span> * tmp_pow.y))));<br> <span style="color: rgb(153, 153, 136);font-style: italic;line-height: 26px;">//同時計算兩個x * cdf;</span><span style="font-weight: bold;line-height: 26px;">return</span> __hmul2(val, __float22half2_rn(cdf));<br>}<br></section></pre><section style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin-top: 5px;margin-bottom: 5px;text-align: left;">混合精度訓練[5]不是很難理解,但要注意以下幾點:</section><ol style="" class="list-paddingleft-2"><li><section style="box-sizing: border-box;line-height: 26px;color: rgb(1, 1, 1);margin-top: 5px;margin-bottom: 5px;text-align: left;"><span style="font-size: 14px;">混合精度訓練不是單純地把FP32轉成FP16去計算就可以了,只用FP16會造成80%的精度損失</span></section></li><li><section style="box-sizing: border-box;line-height: 26px;color: rgb(1, 1, 1);margin-top: 5px;margin-bottom: 5px;text-align: left;"><span style="font-size: 14px;">Loss scaling:由于梯度值都很小,用FP16會下溢,因此先用FP32存儲loss并放大,使得梯度也得到放大,可以用FP16存儲,更新時變成FP32再縮放</span></section></li><li><section style="box-sizing: border-box;line-height: 26px;color: rgb(1, 1, 1);margin-top: 5px;margin-bottom: 5px;text-align: left;"><span style="font-size: 14px;">在涉及到累加操作時,比如BatchNorm、Softmax,FP16會上溢,需要用FP32保存,一般使用GPU中TensorCore的FP16*FP16+FP32=FP32運算</span></section></li></ol><section style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin-top: 5px;margin-bottom: 5px;text-align: left;"><strong style="color: rgb(71, 193, 168);">整體流程:FP32權重 -> FP16權重 -> FP16計算前向 -> FP32的loss,擴大 -> 轉為FP16 -> FP16反向計算梯度 -> 縮放為FP32的梯度更新權重</strong></section><figure data-tool="mdnice編輯器" style="margin-top: 10px;margin-bottom: 10px;"><img data-ratio="0.32850678733031674" data-type="jpeg" data-w="1105" data-src="https://mmbiz.qpic.cn/mmbiz_jpg/y3eXggUiaulIOYfhm4iaiaP0ibt6ucyWbu2aDAWmS1bHbVVtQKRFN6X4m2eNzdcv28LLr4PPUhTgLZXJica9MU9zTbA/640?wx_fmt=jpeg" style="display: block; margin-right: auto; margin-left: auto; width: 677px !important; height: auto !important; visibility: visible !important;" _width="677px" class="" src="https://mmbiz.qpic.cn/mmbiz_jpg/y3eXggUiaulIOYfhm4iaiaP0ibt6ucyWbu2aDAWmS1bHbVVtQKRFN6X4m2eNzdcv28LLr4PPUhTgLZXJica9MU9zTbA/640?wx_fmt=jpeg&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" crossorigin="anonymous" data-fail="0"></figure><section style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin-top: 5px;margin-bottom: 5px;text-align: left;"><br></section><section style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin-top: 5px;margin-bottom: 5px;text-align: left;">!!手工分割線:接下來就是壕賽道了!!</section><h3 data-tool="mdnice編輯器" style="font-weight: bold;font-size: 20px;color: rgb(89, 89, 89);margin-top: 5px;margin-bottom: 5px;text-align: left;"><span style="font-size: 18px;">4. 分布式訓練 Distributed Training</span></h3><section style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin-top: 5px;margin-bottom: 5px;text-align: left;">分布式訓練就是多張卡并行訓練,一般有以下兩種情況:</section><ul style="" class="list-paddingleft-2"><li><section style="box-sizing: border-box;margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);"><section style="box-sizing: border-box;padding-top: 8px;padding-bottom: 8px;color: rgb(89, 89, 89);line-height: normal;margin-top: 5px;margin-bottom: 5px;text-align: left;"><span style="font-size: 14px;">Multi-GPU:單機多卡,通過PCIE、NVlink、GPU Direct P2P來通信</span></section></section></li><li><section style="box-sizing: border-box;margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);"><section style="box-sizing: border-box;padding-top: 8px;padding-bottom: 8px;color: rgb(89, 89, 89);line-height: normal;margin-top: 5px;margin-bottom: 5px;text-align: left;"><span style="font-size: 14px;">Multi-Node:多機多卡,通過Sockets (Ethernet) 或者InfiniBand with GPU Direct RDMA通信</span></section></section></li></ul><figure data-tool="mdnice編輯器" style="margin-top: 10px;margin-bottom: 10px;"><img data-ratio="0.35064935064935066" data-type="jpeg" data-w="462" data-src="https://mmbiz.qpic.cn/mmbiz_jpg/y3eXggUiaulIOYfhm4iaiaP0ibt6ucyWbu2aUXew41XC9wkX01Tiaibwul9ib3DI4wXt0d9icLeEkib2rSYmMMTibevNwic3Q/640?wx_fmt=jpeg" style="display: block; margin-right: auto; margin-left: auto; width: 677px !important; height: auto !important; visibility: visible !important;" _width="677px" class="" src="https://mmbiz.qpic.cn/mmbiz_jpg/y3eXggUiaulIOYfhm4iaiaP0ibt6ucyWbu2aUXew41XC9wkX01Tiaibwul9ib3DI4wXt0d9icLeEkib2rSYmMMTibevNwic3Q/640?wx_fmt=jpeg&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" crossorigin="anonymous" data-fail="0"></figure><section style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin-top: 5px;margin-bottom: 5px;text-align: left;">實踐中可以使用英偉達的NCCL通信框架,多機通過IB(InfiniBand)可以接近機內的通信速度[6]。底層的東西就不多說了(我也不太懂),實際上對于煉丹師來說就是找運維爸爸提供幫助,并借助開源框架配置上服務器地址就行了。</section><section style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin-top: 5px;margin-bottom: 5px;text-align: left;"><strong style="color: rgb(71, 193, 168);">并行訓練有多種優化策略,主要目的就是減少計算中的參數同步(Sync)和數據傳輸。</strong></section><section style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin-top: 5px;margin-bottom: 5px;text-align: left;">目前32GB的卡最多能放1.3B參數的模型,塞得下的話可以使用數據并行的方式,否則可以把不同層放在不同機器上進行訓練。兩種方式的區別看下圖[7]就明白啦:</section><figure data-tool="mdnice編輯器" style="margin-top: 10px;margin-bottom: 10px;"><img data-ratio="0.6499388004895961" data-type="jpeg" data-w="1634" data-src="https://mmbiz.qpic.cn/mmbiz_jpg/y3eXggUiaulIOYfhm4iaiaP0ibt6ucyWbu2aFLtnECibYXhgnGkicDjDDiaicGE6xbYORK0IkyCdHJDtD7wzuGcsgQkqlA/640?wx_fmt=jpeg" style="display: block; margin-right: auto; margin-left: auto; width: 677px !important; height: auto !important; visibility: visible !important;" _width="677px" class="" src="https://mmbiz.qpic.cn/mmbiz_jpg/y3eXggUiaulIOYfhm4iaiaP0ibt6ucyWbu2aFLtnECibYXhgnGkicDjDDiaicGE6xbYORK0IkyCdHJDtD7wzuGcsgQkqlA/640?wx_fmt=jpeg&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" crossorigin="anonymous" data-fail="0"></figure><h4 data-tool="mdnice編輯器" style="font-weight: bold;font-size: 18px;margin-top: 5px;margin-bottom: 5px;text-align: left;">4.1 數據并行 Data Parallelism</h4><section style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin-top: 5px;margin-bottom: 5px;text-align: left;">數據并行有兩種方式[9]:</section><figure data-tool="mdnice編輯器" style="margin-top: 10px;margin-bottom: 10px;"><img data-ratio="0.39400428265524623" data-type="jpeg" data-w="1868" data-src="https://mmbiz.qpic.cn/mmbiz_jpg/y3eXggUiaulIOYfhm4iaiaP0ibt6ucyWbu2a0u5UaTFZibm72F75qfdqaf7xsGfibYwibQCoebOiaWG1Rpm8FjY1YKnpBw/640?wx_fmt=jpeg" style="display: block; margin-right: auto; margin-left: auto; width: 677px !important; height: auto !important; visibility: visible !important;" _width="677px" class="" src="https://mmbiz.qpic.cn/mmbiz_jpg/y3eXggUiaulIOYfhm4iaiaP0ibt6ucyWbu2a0u5UaTFZibm72F75qfdqaf7xsGfibYwibQCoebOiaWG1Rpm8FjY1YKnpBw/640?wx_fmt=jpeg&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" crossorigin="anonymous" data-fail="0"></figure><section style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin-top: 5px;margin-bottom: 5px;text-align: left;"><strong style="color: rgb(71, 193, 168);">Parameter Server</strong></section><section style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin-top: 5px;margin-bottom: 5px;text-align: left;">集群中有一個master和多個worker,master需要等待所有節點計算完畢統一計算梯度,在master上更新參數,之后把新的參數廣播給worker。這種方式的主要瓶頸在master,因此也可以異步訓練,即不等待其他節點,收到一個worker的梯度后就更新參數,但這樣其他worker在舊參數上算完后的梯度會作用到新參數上,導致模型優化過頭,陷入次優解。</section><section style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin-top: 5px;margin-bottom: 5px;text-align: left;"><strong style="color: rgb(71, 193, 168);">Ring All-Reduce</strong></section><section style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin-top: 5px;margin-bottom: 5px;text-align: left;">集群中所有worker形成一個閉環,把數據分成K份,計算完一份就把累加好的梯度傳給下家,同時接受上家的梯度,迭代到最后所有worker的梯度都是相等的,可以同步更新參數,比PS架構要高效,是目前的主流方式。下圖[10]展示了Scatter Reduce和All Gather兩個階段:</section><figure data-tool="mdnice編輯器" style="margin-top: 10px;margin-bottom: 10px;"><img data-ratio="0.7511737089201878" data-type="jpeg" data-w="852" data-src="https://mmbiz.qpic.cn/mmbiz_jpg/y3eXggUiaulIOYfhm4iaiaP0ibt6ucyWbu2a70ottBD6icd4grLib626zBe5cttcD5rpEXoqf1rT5hOu4T9ld18TZpNw/640?wx_fmt=jpeg" style="display: block; margin-right: auto; margin-left: auto; width: 677px !important; height: auto !important; visibility: visible !important;" _width="677px" class="" src="https://mmbiz.qpic.cn/mmbiz_jpg/y3eXggUiaulIOYfhm4iaiaP0ibt6ucyWbu2a70ottBD6icd4grLib626zBe5cttcD5rpEXoqf1rT5hOu4T9ld18TZpNw/640?wx_fmt=jpeg&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" crossorigin="anonymous" data-fail="0"><section style="text-align: left;color: rgb(136, 136, 136);font-size: 14px;margin-top: 5px;margin-bottom: 5px;">preview</section></figure><figure data-tool="mdnice編輯器" style="margin-top: 10px;margin-bottom: 10px;"><img data-ratio="0.7511737089201878" data-type="jpeg" data-w="852" data-src="https://mmbiz.qpic.cn/mmbiz_jpg/y3eXggUiaulIOYfhm4iaiaP0ibt6ucyWbu2aicZKJ3a9DIcDrs23BOlDeyNAzhZQFlwROAAiamd5hX2FD4lqkKfQTdLg/640?wx_fmt=jpeg" style="display: block; margin-right: auto; margin-left: auto; width: 677px !important; height: auto !important; visibility: visible !important;" _width="677px" class="" src="https://mmbiz.qpic.cn/mmbiz_jpg/y3eXggUiaulIOYfhm4iaiaP0ibt6ucyWbu2aicZKJ3a9DIcDrs23BOlDeyNAzhZQFlwROAAiamd5hX2FD4lqkKfQTdLg/640?wx_fmt=jpeg&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" crossorigin="anonymous" data-fail="0"></figure><h4 data-tool="mdnice編輯器" style="font-weight: bold;font-size: 18px;margin-top: 5px;margin-bottom: 5px;text-align: left;">4.2 模型并行 Model Parallelism</h4><section style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin-top: 5px;margin-bottom: 5px;text-align: left;">模型并行目前并不常見,一是因為大部分模型單卡都放得下,二是因為通訊開銷比數據并行多,因為反向傳播需要把loss對每層激活值的梯度都傳回去,樣本數量大的話激活值也有很多。</section><section style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin-top: 5px;margin-bottom: 5px;text-align: left;"><strong style="color: rgb(71, 193, 168);">Pipelined Parallelism</strong></section><section style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin-top: 5px;margin-bottom: 5px;text-align: left;">Pipeline的并行方式就是把模型的不同層放到不同機器上,順序地進行前向和反向計算。19年谷歌和微軟先后放出了GPipe[11]和PipeDream[12]的論文和源碼,給大家梳理一下他們的心路歷程:</section><section style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin-top: 5px;margin-bottom: 5px;text-align: left;">首先來看最naive的模型并行方式,實在是有些浪費生命:</section><figure data-tool="mdnice編輯器" style="margin-top: 10px;margin-bottom: 10px;"><img data-ratio="0.34859675036927623" data-type="jpeg" data-w="1354" data-src="https://mmbiz.qpic.cn/mmbiz_jpg/y3eXggUiaulIOYfhm4iaiaP0ibt6ucyWbu2at1ic4lC8Bt6nCvXmnSt75g7943S3AbHaWGJfIcd3gRTGm1n5Ra7Ep3g/640?wx_fmt=jpeg" style="display: block; margin-right: auto; margin-left: auto; width: 677px !important; height: auto !important; visibility: visible !important;" _width="677px" class="" src="https://mmbiz.qpic.cn/mmbiz_jpg/y3eXggUiaulIOYfhm4iaiaP0ibt6ucyWbu2at1ic4lC8Bt6nCvXmnSt75g7943S3AbHaWGJfIcd3gRTGm1n5Ra7Ep3g/640?wx_fmt=jpeg&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" crossorigin="anonymous" data-fail="0"></figure><section style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin-top: 5px;margin-bottom: 5px;text-align: left;">注:反向需要計算對參數和激活值的偏導,所以耗時更長。</section><section style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin-top: 5px;margin-bottom: 5px;text-align: left;">所以谷歌GPipe提出了一個改進,其實就是把數據分片,像allreduce一樣計算完一些就傳給下個節點,最后<strong style="color: rgb(71, 193, 168);">同步</strong>更新參數,但這樣看還是不能挽救我們的青春:</section><figure data-tool="mdnice編輯器" style="margin-top: 10px;margin-bottom: 10px;"><img data-ratio="0.31417624521072796" data-type="jpeg" data-w="1566" data-src="https://mmbiz.qpic.cn/mmbiz_jpg/y3eXggUiaulIOYfhm4iaiaP0ibt6ucyWbu2aibu8uJ62uOVgNkRs5B94icsJwQwIsxeEew9XicvMC7h7ql2gdb23HYBoA/640?wx_fmt=jpeg" style="display: block; margin-right: auto; margin-left: auto; width: 677px !important; height: auto !important; visibility: visible !important;" _width="677px" class="" src="https://mmbiz.qpic.cn/mmbiz_jpg/y3eXggUiaulIOYfhm4iaiaP0ibt6ucyWbu2aibu8uJ62uOVgNkRs5B94icsJwQwIsxeEew9XicvMC7h7ql2gdb23HYBoA/640?wx_fmt=jpeg&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" crossorigin="anonymous" data-fail="0"></figure><section style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin-top: 5px;margin-bottom: 5px;text-align: left;">于是微軟提出了PipeDream,其實就是<strong style="color: rgb(71, 193, 168);">把同步變為了小數據上的異步</strong>,計算完一個數據分片就立刻反向,反向完了就更新梯度,誰也別等誰,大家一起瘋狂干起來:</section><figure data-tool="mdnice編輯器" style="margin-top: 10px;margin-bottom: 10px;"><img data-ratio="0.3203631647211414" data-type="jpeg" data-w="1542" data-src="https://mmbiz.qpic.cn/mmbiz_jpg/y3eXggUiaulIOYfhm4iaiaP0ibt6ucyWbu2ahP8rBzvLlFPudh3JicicjRXvpPIvTKicItFic8WWJlmWHwsuTQReMs53OA/640?wx_fmt=jpeg" style="display: block; margin-right: auto; margin-left: auto; width: 677px !important; height: auto !important; visibility: visible !important;" _width="677px" class="" src="https://mmbiz.qpic.cn/mmbiz_jpg/y3eXggUiaulIOYfhm4iaiaP0ibt6ucyWbu2ahP8rBzvLlFPudh3JicicjRXvpPIvTKicItFic8WWJlmWHwsuTQReMs53OA/640?wx_fmt=jpeg&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" crossorigin="anonymous" data-fail="0"></figure><section style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin-top: 5px;margin-bottom: 5px;text-align: left;">但這樣就有一個問題,就是大家越干越亂,比如worker1在計算5的前向時用的是1反向后的參數,但之后計算5反向的梯度時參數早就被2/3/4更新了。于是作者加入了<strong style="color: rgb(71, 193, 168);">Weight stashing</strong>機制,把每個數據對應的參數都存起來!這樣worker1在5反向的時候就可以從百寶箱里拿出之前的參數,進行更新:</section><figure data-tool="mdnice編輯器" style="margin-top: 10px;margin-bottom: 10px;"><img data-ratio="0.34392265193370164" data-type="jpeg" data-w="1448" data-src="https://mmbiz.qpic.cn/mmbiz_jpg/y3eXggUiaulIOYfhm4iaiaP0ibt6ucyWbu2alolenxicbrKtTu0wBqnN8VfToclpvibrIevT6z2xfmMJjRQ8lVSliap9g/640?wx_fmt=jpeg" style="display: block; margin-right: auto; margin-left: auto; width: 677px !important; height: auto !important; visibility: visible !important;" _width="677px" class="" src="https://mmbiz.qpic.cn/mmbiz_jpg/y3eXggUiaulIOYfhm4iaiaP0ibt6ucyWbu2alolenxicbrKtTu0wBqnN8VfToclpvibrIevT6z2xfmMJjRQ8lVSliap9g/640?wx_fmt=jpeg&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" crossorigin="anonymous" data-fail="0"></figure><section style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin-top: 5px;margin-bottom: 5px;text-align: left;">那問題又來了:worker1上5的前向是用1的參數,但worker3上是用3的,最后匯總的時候不就又亂了?于是作者又加入了<strong style="color: rgb(71, 193, 168);">Vertical Sync</strong>機制,強制所有worker在計算5的時候都用1的參數。這樣在最后匯總模型的時候,就能拿到一致的參數了。但這樣同步會導致很多計算作廢,比如5更新時用的1的權重,但2/3/4的權重都白計算了,所以默認是不用Vertical Sync的,這樣每層雖然不完全一致,但由于weight stashing,所有的參數都是有效的。</section><section style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin-top: 5px;margin-bottom: 5px;text-align: left;"><strong style="color: rgb(71, 193, 168);">Tensor Slicing</strong></section><section style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin-top: 5px;margin-bottom: 5px;text-align: left;">神經網絡可以看作一個復合函數,本質就是各個tensor之間的計算,我們定義好的CNN、RNN其實就是計算函數的集合。從這個角度來思考,<strong style="color: rgb(71, 193, 168);">模型并行其實就是把各個tensor計算分散到不同的機器上</strong>。這方面的研究有18年的FlexFLow和Mesh-TensorFlow,英偉達的威震天[13]也是使用這個策略。下面以Transformer為例說明一下如何拆分。</section><section style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin-top: 5px;margin-bottom: 5px;text-align: left;">Transformer主要有self-attention和FFN組成,對于FFN中的第一層Y=GLUE(XA)可以有兩種拆分方式:</section><figure data-tool="mdnice編輯器" style="margin-top: 10px;margin-bottom: 10px;"><img data-ratio="0.54" data-type="jpeg" data-w="2000" data-src="https://mmbiz.qpic.cn/mmbiz_jpg/y3eXggUiaulIOYfhm4iaiaP0ibt6ucyWbu2a1c07YEXdDEltUWPEkqVQsDO70JC32usGjL1fVGVVSIHKUJepowP0EA/640?wx_fmt=jpeg" style="display: block; margin-right: auto; margin-left: auto; width: 677px !important; height: auto !important; visibility: visible !important;" _width="677px" class="" src="https://mmbiz.qpic.cn/mmbiz_jpg/y3eXggUiaulIOYfhm4iaiaP0ibt6ucyWbu2a1c07YEXdDEltUWPEkqVQsDO70JC32usGjL1fVGVVSIHKUJepowP0EA/640?wx_fmt=jpeg&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" crossorigin="anonymous" data-fail="0"></figure><section style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin-top: 5px;margin-bottom: 5px;text-align: left;">可以看到,第一種需要在計算GLUE時同步,因此威震天通過第二種方式進行tensor切片,self-attention也采用類似的策略,這樣只需要在前向時通過g聚合,反向時通過f聚合就可以了:</section><figure data-tool="mdnice編輯器" style="margin-top: 10px;margin-bottom: 10px;"><img data-ratio="1.0839002267573696" data-type="jpeg" data-w="882" data-src="https://mmbiz.qpic.cn/mmbiz_jpg/y3eXggUiaulIOYfhm4iaiaP0ibt6ucyWbu2a6LNMnhMNpqAu37BsIEly0yvblUPDzdhpMPg96RhicTzhE7zyzYxUzZg/640?wx_fmt=jpeg" style="display: block; margin-right: auto; margin-left: auto; width: 677px !important; height: auto !important; visibility: visible !important;" _width="677px" class="" src="https://mmbiz.qpic.cn/mmbiz_jpg/y3eXggUiaulIOYfhm4iaiaP0ibt6ucyWbu2a6LNMnhMNpqAu37BsIEly0yvblUPDzdhpMPg96RhicTzhE7zyzYxUzZg/640?wx_fmt=jpeg&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" crossorigin="anonymous" data-fail="0"></figure><section style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin-top: 5px;margin-bottom: 5px;text-align: left;">剩下的Layernorm和dropout還是需要同步后計算:</section><figure data-tool="mdnice編輯器" style="margin-top: 10px;margin-bottom: 10px;"><img data-ratio="0.38045375218150085" data-type="jpeg" data-w="1146" data-src="https://mmbiz.qpic.cn/mmbiz_jpg/y3eXggUiaulIOYfhm4iaiaP0ibt6ucyWbu2aVqOaAia9pfWwtMTMNAv3vUleLkPrKmWO5ZWOryibh3LhRKOS8Cm4upVw/640?wx_fmt=jpeg" style="display: block; margin-right: auto; margin-left: auto; width: 677px !important; height: auto !important; visibility: visible !important;" _width="677px" class="" src="https://mmbiz.qpic.cn/mmbiz_jpg/y3eXggUiaulIOYfhm4iaiaP0ibt6ucyWbu2aVqOaAia9pfWwtMTMNAv3vUleLkPrKmWO5ZWOryibh3LhRKOS8Cm4upVw/640?wx_fmt=jpeg&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" crossorigin="anonymous" data-fail="0"></figure><section style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin-top: 5px;margin-bottom: 5px;text-align: left;">同時,作者也在vocab的維度對embedding進行了切分,并把最后的MLM預測和cross-entropy融合到一起,減少網絡通信量(否則需要傳輸batch_size*seq_len *vocab_size個prob,改過后只傳batch_size *seq_len個loss值)。</section><section style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin-top: 5px;margin-bottom: 5px;text-align: left;">隨著模型越來越大,分布式訓練甚至推理肯定是一個趨勢,在工程上還有很多可以優化的點,不僅是上面介紹的分布式策略,還有網絡通信優化、內存優化等。</section><h3 data-tool="mdnice編輯器" style="font-weight: bold;font-size: 20px;color: rgb(89, 89, 89);margin-top: 5px;margin-bottom: 5px;text-align: left;"><span style="font-size: 18px;">5. 加速優化器 LAMB</span></h3><section style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin-top: 5px;margin-bottom: 5px;text-align: left;">上文提到的數據并行雖然可以接近線性地提升訓練速度,但過大的Batch會降低模型精度和收斂速度(對數據的擬合變差)。因此谷歌在19年推出了LAMB[14]優化器,全稱為<strong style="color: rgb(71, 193, 168);">Layer-wise Adaptive Moments optimizer for Batch training</strong>,針對大batch做了優化,在分布式訓練的場景下可訓65536/32768的樣本,減少迭代次數,從而縮短訓練時間,感受一下金錢的味道:</section><figure data-tool="mdnice編輯器" style="margin-top: 10px;margin-bottom: 10px;"><img data-ratio="0.4912023460410557" data-type="jpeg" data-w="1364" data-src="https://mmbiz.qpic.cn/mmbiz_jpg/y3eXggUiaulIOYfhm4iaiaP0ibt6ucyWbu2a1PbMnNJ3NwTnMb7Emk0s2jNGyGWRJHGXkkJTvD9BUFzW7laarOZTicw/640?wx_fmt=jpeg" style="display: block; margin-right: auto; margin-left: auto; width: 677px !important; height: auto !important; visibility: visible !important;" _width="677px" class="" src="https://mmbiz.qpic.cn/mmbiz_jpg/y3eXggUiaulIOYfhm4iaiaP0ibt6ucyWbu2a1PbMnNJ3NwTnMb7Emk0s2jNGyGWRJHGXkkJTvD9BUFzW7laarOZTicw/640?wx_fmt=jpeg&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" crossorigin="anonymous" data-fail="0"></figure><section style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin-top: 5px;margin-bottom: 5px;text-align: left;">LAMB主要是綜合了Adam和LARS(Layerwise Adaptive Rate Scaling),對學習率進行調整。上文提到當batch變大時學習率也需要變大,這樣會導致收斂不穩定,LARS通過給LR乘上權重與梯度的norm比值來解決這個問題[15]:</section><section style="text-align: left;overflow: auto;margin-top: 5px;margin-bottom: 5px;"><svg xmlns="http://www.w3.org/2000/svg" role="img" focusable="false" viewBox="0 -1563.2 7351 2627" aria-hidden="true" style="-webkit-overflow-scrolling: touch;vertical-align: -2.407ex;width: 16.631ex;height: 5.943ex;max-width: 300% !important;"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><g data-mml-node="math"><g data-mml-node="msub"><g data-mml-node="mi"><path data-c="3BB" d="M166 673Q166 685 183 694H202Q292 691 316 644Q322 629 373 486T474 207T524 67Q531 47 537 34T546 15T551 6T555 2T556 -2T550 -11H482Q457 3 450 18T399 152L354 277L340 262Q327 246 293 207T236 141Q211 112 174 69Q123 9 111 -1T83 -12Q47 -12 47 20Q47 37 61 52T199 187Q229 216 266 252T321 306L338 322Q338 323 288 462T234 612Q214 657 183 657Q166 657 166 673Z"></path></g><g data-mml-node="mi" transform="translate(583, -150) scale(0.707)"><path data-c="6C" d="M117 59Q117 26 142 26Q179 26 205 131Q211 151 215 152Q217 153 225 153H229Q238 153 241 153T246 151T248 144Q247 138 245 128T234 90T214 43T183 6T137 -11Q101 -11 70 11T38 85Q38 97 39 102L104 360Q167 615 167 623Q167 626 166 628T162 632T157 634T149 635T141 636T132 637T122 637Q112 637 109 637T101 638T95 641T94 647Q94 649 96 661Q101 680 107 682T179 688Q194 689 213 690T243 693T254 694Q266 694 266 686Q266 675 193 386T118 83Q118 81 118 75T117 65V59Z"></path></g></g><g data-mml-node="mo" transform="translate(1121.5, 0)"><path data-c="3D" d="M56 347Q56 360 70 367H707Q722 359 722 347Q722 336 708 328L390 327H72Q56 332 56 347ZM56 153Q56 168 72 173H708Q722 163 722 153Q722 140 707 133H70Q56 140 56 153Z"></path></g><g data-mml-node="mi" transform="translate(2177.3, 0)"><path data-c="3B7" d="M21 287Q22 290 23 295T28 317T38 348T53 381T73 411T99 433T132 442Q156 442 175 435T205 417T221 395T229 376L231 369Q231 367 232 367L243 378Q304 442 382 442Q436 442 469 415T503 336V326Q503 302 439 53Q381 -182 377 -189Q364 -216 332 -216Q319 -216 310 -208T299 -186Q299 -177 358 57L420 307Q423 322 423 345Q423 404 379 404H374Q288 404 229 303L222 291L189 157Q156 26 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 114 189T154 366Q154 405 128 405Q107 405 92 377T68 316T57 280Q55 278 41 278H27Q21 284 21 287Z"></path></g><g data-mml-node="mfrac" transform="translate(2674.3, 0)"><g data-mml-node="mrow" transform="translate(1366, 709.5)"><g data-mml-node="mo"><path data-c="7C" d="M139 -249H137Q125 -249 119 -235V251L120 737Q130 750 139 750Q152 750 159 735V-235Q151 -249 141 -249H139Z"></path></g><g data-mml-node="mo" transform="translate(278, 0)"><path data-c="7C" d="M139 -249H137Q125 -249 119 -235V251L120 737Q130 750 139 750Q152 750 159 735V-235Q151 -249 141 -249H139Z"></path></g><g data-mml-node="msup" transform="translate(556, 0)"><g data-mml-node="mi"><path data-c="78" d="M52 289Q59 331 106 386T222 442Q257 442 286 424T329 379Q371 442 430 442Q467 442 494 420T522 361Q522 332 508 314T481 292T458 288Q439 288 427 299T415 328Q415 374 465 391Q454 404 425 404Q412 404 406 402Q368 386 350 336Q290 115 290 78Q290 50 306 38T341 26Q378 26 414 59T463 140Q466 150 469 151T485 153H489Q504 153 504 145Q504 144 502 134Q486 77 440 33T333 -11Q263 -11 227 52Q186 -10 133 -10H127Q78 -10 57 16T35 71Q35 103 54 123T99 143Q142 143 142 101Q142 81 130 66T107 46T94 41L91 40Q91 39 97 36T113 29T132 26Q168 26 194 71Q203 87 217 139T245 247T261 313Q266 340 266 352Q266 380 251 392T217 404Q177 404 142 372T93 290Q91 281 88 280T72 278H58Q52 284 52 289Z"></path></g><g data-mml-node="mi" transform="translate(572, 363) scale(0.707)"><path data-c="6C" d="M117 59Q117 26 142 26Q179 26 205 131Q211 151 215 152Q217 153 225 153H229Q238 153 241 153T246 151T248 144Q247 138 245 128T234 90T214 43T183 6T137 -11Q101 -11 70 11T38 85Q38 97 39 102L104 360Q167 615 167 623Q167 626 166 628T162 632T157 634T149 635T141 636T132 637T122 637Q112 637 109 637T101 638T95 641T94 647Q94 649 96 661Q101 680 107 682T179 688Q194 689 213 690T243 693T254 694Q266 694 266 686Q266 675 193 386T118 83Q118 81 118 75T117 65V59Z"></path></g></g><g data-mml-node="mo" transform="translate(1388.7, 0)"><path data-c="7C" d="M139 -249H137Q125 -249 119 -235V251L120 737Q130 750 139 750Q152 750 159 735V-235Q151 -249 141 -249H139Z"></path></g><g data-mml-node="mo" transform="translate(1666.7, 0)"><path data-c="7C" d="M139 -249H137Q125 -249 119 -235V251L120 737Q130 750 139 750Q152 750 159 735V-235Q151 -249 141 -249H139Z"></path></g></g><g data-mml-node="mrow" transform="translate(220, -813.7)"><g data-mml-node="mo"><path data-c="7C" d="M139 -249H137Q125 -249 119 -235V251L120 737Q130 750 139 750Q152 750 159 735V-235Q151 -249 141 -249H139Z"></path></g><g data-mml-node="mo" transform="translate(278, 0)"><path data-c="7C" d="M139 -249H137Q125 -249 119 -235V251L120 737Q130 750 139 750Q152 750 159 735V-235Q151 -249 141 -249H139Z"></path></g><g data-mml-node="mi" transform="translate(556, 0)"><path data-c="2207" d="M46 676Q46 679 51 683H781Q786 679 786 676Q786 674 617 326T444 -26Q439 -33 416 -33T388 -26Q385 -22 216 326T46 676ZM697 596Q697 597 445 597T193 596Q195 591 319 336T445 80L697 596Z"></path></g><g data-mml-node="TeXAtom" data-mjx-texclass="ORD" transform="translate(1389, 0)"><g data-mml-node="mi"><path data-c="4C" d="M228 637Q194 637 192 641Q191 643 191 649Q191 673 202 682Q204 683 217 683Q271 680 344 680Q485 680 506 683H518Q524 677 524 674T522 656Q517 641 513 637H475Q406 636 394 628Q387 624 380 600T313 336Q297 271 279 198T252 88L243 52Q243 48 252 48T311 46H328Q360 46 379 47T428 54T478 72T522 106T564 161Q580 191 594 228T611 270Q616 273 628 273H641Q647 264 647 262T627 203T583 83T557 9Q555 4 553 3T537 0T494 -1Q483 -1 418 -1T294 0H116Q32 0 32 10Q32 17 34 24Q39 43 44 45Q48 46 59 46H65Q92 46 125 49Q139 52 144 61Q147 65 216 339T285 628Q285 635 228 637Z"></path></g><g data-mml-node="mo" transform="translate(681, 0)"><path data-c="28" d="M94 250Q94 319 104 381T127 488T164 576T202 643T244 695T277 729T302 750H315H319Q333 750 333 741Q333 738 316 720T275 667T226 581T184 443T167 250T184 58T225 -81T274 -167T316 -220T333 -241Q333 -250 318 -250H315H302L274 -226Q180 -141 137 -14T94 250Z"></path></g><g data-mml-node="msup" transform="translate(1070, 0)"><g data-mml-node="mi"><path data-c="78" d="M52 289Q59 331 106 386T222 442Q257 442 286 424T329 379Q371 442 430 442Q467 442 494 420T522 361Q522 332 508 314T481 292T458 288Q439 288 427 299T415 328Q415 374 465 391Q454 404 425 404Q412 404 406 402Q368 386 350 336Q290 115 290 78Q290 50 306 38T341 26Q378 26 414 59T463 140Q466 150 469 151T485 153H489Q504 153 504 145Q504 144 502 134Q486 77 440 33T333 -11Q263 -11 227 52Q186 -10 133 -10H127Q78 -10 57 16T35 71Q35 103 54 123T99 143Q142 143 142 101Q142 81 130 66T107 46T94 41L91 40Q91 39 97 36T113 29T132 26Q168 26 194 71Q203 87 217 139T245 247T261 313Q266 340 266 352Q266 380 251 392T217 404Q177 404 142 372T93 290Q91 281 88 280T72 278H58Q52 284 52 289Z"></path></g><g data-mml-node="mi" transform="translate(572, 363) scale(0.707)"><path data-c="6C" d="M117 59Q117 26 142 26Q179 26 205 131Q211 151 215 152Q217 153 225 153H229Q238 153 241 153T246 151T248 144Q247 138 245 128T234 90T214 43T183 6T137 -11Q101 -11 70 11T38 85Q38 97 39 102L104 360Q167 615 167 623Q167 626 166 628T162 632T157 634T149 635T141 636T132 637T122 637Q112 637 109 637T101 638T95 641T94 647Q94 649 96 661Q101 680 107 682T179 688Q194 689 213 690T243 693T254 694Q266 694 266 686Q266 675 193 386T118 83Q118 81 118 75T117 65V59Z"></path></g></g><g data-mml-node="mo" transform="translate(1902.7, 0)"><path data-c="29" d="M60 749L64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12T224 -76T186 -143T145 -194T113 -227T90 -246Q87 -249 86 -250H74Q66 -250 63 -250T58 -247T55 -238Q56 -237 66 -225Q221 -64 221 250T66 725Q56 737 55 738Q55 746 60 749Z"></path></g></g><g data-mml-node="mo" transform="translate(3680.7, 0)"><path data-c="7C" d="M139 -249H137Q125 -249 119 -235V251L120 737Q130 750 139 750Q152 750 159 735V-235Q151 -249 141 -249H139Z"></path></g><g data-mml-node="mo" transform="translate(3958.7, 0)"><path data-c="7C" d="M139 -249H137Q125 -249 119 -235V251L120 737Q130 750 139 750Q152 750 159 735V-235Q151 -249 141 -249H139Z"></path></g></g><rect width="4436.7" height="60" x="120" y="220"></rect></g></g></g></svg></section><section style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin-top: 5px;margin-bottom: 5px;text-align: left;">這里的norm都是取一層的權重計算,所以是layerwise。可以這樣理解上面的公式:剛開始訓練時,權重比較小,而loss和梯度比較大,所以學習率開始較小,但隨著權重變大&梯度變小會慢慢warmup。當對一些樣本擬合很好,loss接近0時,梯度變小,學習率又會增大,跳出局部最優,防止過擬合。</section><section style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin-top: 5px;margin-bottom: 5px;text-align: left;">LAMB融合了這種layerwise的自適應思想:</section><figure data-tool="mdnice編輯器" style="margin-top: 10px;margin-bottom: 10px;"><img data-ratio="0.6851851851851852" data-type="jpeg" data-w="972" data-src="https://mmbiz.qpic.cn/mmbiz_jpg/y3eXggUiaulIOYfhm4iaiaP0ibt6ucyWbu2afYBviaZycLvv4MfRib3kKPqDqgEWBLkPqH2NDdJPT8mX74OkyzRfNicTg/640?wx_fmt=jpeg" style="display: block; margin-right: auto; margin-left: auto; width: 677px !important; height: auto !important; visibility: visible !important;" _width="677px" class="" src="https://mmbiz.qpic.cn/mmbiz_jpg/y3eXggUiaulIOYfhm4iaiaP0ibt6ucyWbu2afYBviaZycLvv4MfRib3kKPqDqgEWBLkPqH2NDdJPT8mX74OkyzRfNicTg/640?wx_fmt=jpeg&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" crossorigin="anonymous" data-fail="0"></figure><section style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin-top: 5px;margin-bottom: 5px;text-align: left;">圖中的公式稍稍有改動,一個是給權重norm加了映射,本質都是起scale的作用;另一個是梯度公式中加了weight decay,也就是目標函數中的L2正則化。</section><h3 data-tool="mdnice編輯器" style="font-weight: bold;font-size: 20px;color: rgb(89, 89, 89);margin-top: 5px;margin-bottom: 5px;text-align: left;"><span style="font-size: 18px;">總結</span></h3><section style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin-top: 5px;margin-bottom: 5px;text-align: left;">本文介紹了從速度和內存去優化模型訓練的幾種方式,實踐中各種都是可以混合起來的,比如混合精度+數據并行、數據并行+模型并行、數據并行+梯度檢查點等。DeepSpeed里基本涵蓋了本文所講的策略,用pytorch的同學可以安排起來了~</section><section style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin-top: 5px;margin-bottom: 5px;text-align: left;">最后,在介紹各種策略的時候,由于篇幅原因也有省略一些假設和最終效果,感興趣的同學們可以深入研讀參考資料里的內容~如果路過的大佬們發現哪里有錯誤煩請指出~<br><br></section><section style="box-sizing: border-box;font-size: 16px;"><section style="transform: rotate(0deg);-webkit-transform: rotate(0deg);-moz-transform: rotate(0deg);-o-transform: rotate(0deg);box-sizing: border-box;" powered-by="xiumi.us"><section style="margin-top: 10px;margin-bottom: 10px;padding-left: 4px;box-sizing: border-box;"><section style="display: inline-block;vertical-align: bottom;width: 100%;margin-bottom: 0.2em;box-sizing: border-box;"><section style="border-top: 1px solid rgb(249, 110, 87);width: 90%;box-sizing: border-box;height: 1px;line-height: 0;"><br></section><section style="width: 8px;height: 8px;margin-top: -4px;margin-right: -4px;border-radius: 100%;background-color: rgb(249, 110, 87);box-sizing: border-box;line-height: 0;"><br></section></section><section style="text-align: right;margin-top: -1.5em;box-sizing: border-box;"><section style="width: 2em;height: 2em;line-height: 2em;display: inline-block;vertical-align: top;border-radius: 100%;background-color: rgb(250, 187, 187);text-align: center;color: rgb(255, 255, 255);box-sizing: border-box;"><p style="box-sizing: border-box;">可</p></section><section style="width: 2em;height: 2em;line-height: 2em;display: inline-block;vertical-align: top;border-radius: 100%;background-color: rgb(250, 187, 187);text-align: center;color: rgb(255, 255, 255);box-sizing: border-box;"><p style="box-sizing: border-box;">能</p></section><section style="width: 2em;height: 2em;line-height: 2em;display: inline-block;vertical-align: top;border-radius: 100%;background-color: rgb(250, 187, 187);text-align: center;color: rgb(255, 255, 255);box-sizing: border-box;"><p style="box-sizing: border-box;">喜</p></section><section style="width: 2em;height: 2em;line-height: 2em;display: inline-block;vertical-align: top;border-radius: 100%;background-color: rgb(250, 187, 187);text-align: center;color: rgb(255, 255, 255);box-sizing: border-box;"><p style="box-sizing: border-box;">歡</p></section></section></section></section></section><ul class="list-paddingleft-2" style=""><li><p style="max-width: 100%;min-height: 1em;overflow-wrap: break-word !important;box-sizing: border-box !important;"><a target="_blank" href="http://mp.weixin.qq.com/s?__biz=MzIwNzc2NTk0NQ==&mid=2247485842&idx=1&sn=cc24542d51e17533781d5c60bd693cec&chksm=970c2144a07ba852979cc39d1be332109046a7e8e28fa61d4efc5be052461f4a3ce3dc083809&scene=21#wechat_redirect" textvalue="詳解醫學頂刊《柳葉刀》最新發表新型冠狀病毒研究論文" data-itemshowtype="0" tab="innerlink" data-linktype="2" hasload="1"><span style="max-width: 100%;color: rgb(112, 177, 231);-webkit-tap-highlight-color: rgba(0, 0, 0, 0);cursor: pointer;font-size: 15px;overflow-wrap: break-word !important;box-sizing: border-box !important;">如何讓BERT擁有視覺感知能力?兩種方式將視頻信息注入BERT</span></a></p></li><li><p style="max-width: 100%;min-height: 1em;text-align: left;overflow-wrap: break-word !important;box-sizing: border-box !important;"><a target="_blank" href="http://mp.weixin.qq.com/s?__biz=MzIwNzc2NTk0NQ==&mid=2247485278&idx=1&sn=d1a13149b7cd8b60694c716ca8580cff&chksm=970c2f88a07ba69e1b20bc0666be615a07c18f96182f1b27f93aef082f61751f7a373d4b902e&scene=21#wechat_redirect" textvalue="深度神經網絡為何會有災難性遺忘?如何進行有效的持續學習?" data-itemshowtype="0" tab="innerlink" data-linktype="2" hasload="1"><span style="max-width: 100%;color: rgb(112, 177, 231);-webkit-tap-highlight-color: rgba(0, 0, 0, 0);cursor: pointer;font-size: 15px;overflow-wrap: break-word !important;box-sizing: border-box !important;">模型訓練太慢?顯存不夠用?這個算法讓你的GPU老樹開新花</span><span style="max-width: 100%;color: rgb(112, 177, 231);-webkit-tap-highlight-color: rgba(0, 0, 0, 0);cursor: pointer;font-size: 15px;overflow-wrap: break-word !important;box-sizing: border-box !important;"></span></a></p></li><li><p style="max-width: 100%;min-height: 1em;text-align: left;overflow-wrap: break-word !important;box-sizing: border-box !important;"><a target="_blank" href="http://mp.weixin.qq.com/s?__biz=MzIwNzc2NTk0NQ==&mid=2247485019&idx=1&sn=4b2d8f8f5bcb58437b262f87f8c4e393&chksm=970c2e8da07ba79be4d264f66509295755ebc9d286a0bbb24326b9d4b14ea3bce41966482477&scene=21#wechat_redirect" textvalue="萬萬沒想到,我的煉丹爐玩壞了" data-itemshowtype="0" tab="innerlink" style="text-align: left;white-space: normal;" data-linktype="2" hasload="1"><span style="color: rgb(112, 177, 231);-webkit-tap-highlight-color: rgba(0, 0, 0, 0);cursor: pointer;font-size: 15px;">訓練效率低?GPU利用率上不去?快來看看別人家的tricks吧~</span></a><br></p></li><li><p style="max-width: 100%;min-height: 1em;text-align: left;overflow-wrap: break-word !important;box-sizing: border-box !important;"><a target="_blank" href="http://mp.weixin.qq.com/s?__biz=MzIwNzc2NTk0NQ==&mid=2247485051&idx=1&sn=c3380421fbdf63debf16512e2915f242&chksm=970c2eada07ba7bb8fa16a99d8a64536568cb18551346484e0a4d828b3cb831238c7ddadab8d&scene=21#wechat_redirect" textvalue="模型訓練太慢?顯存不夠用?混合精度訓練了解一下" data-itemshowtype="0" tab="innerlink" data-linktype="2" hasload="1"><span style="max-width: 100%;color: rgb(112, 177, 231);font-size: 15px;-webkit-tap-highlight-color: rgba(0, 0, 0, 0);cursor: pointer;text-indent: 29.3333px;overflow-wrap: break-word !important;box-sizing: border-box !important;">如何打造高質量的NLP數據集</span><span style="max-width: 100%;color: rgb(112, 177, 231);font-size: 15px;-webkit-tap-highlight-color: rgba(0, 0, 0, 0);cursor: pointer;text-indent: 29.3333px;overflow-wrap: break-word !important;box-sizing: border-box !important;"></span></a></p></li><li><p style="max-width: 100%;min-height: 1em;text-align: left;overflow-wrap: break-word !important;box-sizing: border-box !important;"><a target="_blank" href="http://mp.weixin.qq.com/s?__biz=MzIwNzc2NTk0NQ==&mid=2247485371&idx=1&sn=7e1e738b79d78320010ef993daa4a003&chksm=970c2f6da07ba67b061d0c33342e98f4c389f9b60b0b43b4e0df4b42c4ab2a3b19936a3f2e6c&scene=21#wechat_redirect" textvalue="如何與GPU服務器優雅交互" data-itemshowtype="0" tab="innerlink" data-linktype="2" style="max-width: 100%;overflow-wrap: break-word !important;box-sizing: border-box !important;" hasload="1"><span style="max-width: 100%;color: rgb(112, 177, 231);-webkit-tap-highlight-color: rgba(0, 0, 0, 0);cursor: pointer;font-size: 15px;overflow-wrap: break-word !important;box-sizing: border-box !important;">萬萬沒想到,我的煉丹爐玩壞了</span></a></p></li></ul><p style="max-width: 100%;min-height: 1em;text-align: left;overflow-wrap: break-word !important;box-sizing: border-box !important;"><span style="font-family: mp-quote, -apple-system-font, BlinkMacSystemFont, "Helvetica Neue", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;"></span><br></p><section mpa-from-tpl="t" style="white-space: normal;font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, "PingFang SC", Cambria, Cochin, Georgia, Times, "Times New Roman", serif;font-size: 16px;text-align: left;color: rgb(62, 62, 62);"><section data-role="outer" mpa-from-tpl="t"><section style="margin-top: 5px;margin-bottom: 5px;"><section mpa-from-tpl="t" style="display: flex;justify-content: center;align-items: center;"><section mpa-from-tpl="t" style="width: 2.5em;transform: rotate(0deg);"><img data-ratio="1.1428571428571428" data-src="https://mmbiz.qpic.cn/mmbiz_png/5fknb41ib9qEkpef92EuDauK6TMoQeqAxH91oa4b26nj87mpBln2hy8HnCicjx53EQ9OtXsuiciaux9tN6445rcdJA/640?wx_fmt=png" data-type="png" data-w="63" data-width="100%" style="display: block; width: 40px !important; height: auto !important; visibility: visible !important;" _width="40px" src="https://mmbiz.qpic.cn/mmbiz_png/5fknb41ib9qEkpef92EuDauK6TMoQeqAxH91oa4b26nj87mpBln2hy8HnCicjx53EQ9OtXsuiciaux9tN6445rcdJA/640?wx_fmt=png&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" crossorigin="anonymous" class="" data-fail="0"></section><section mpa-from-tpl="t" style="margin-left: -8px;padding-bottom: 2px;border-bottom: 1px solid rgb(232, 193, 49);"><section data-brushtype="text" mpa-from-tpl="t" style="margin-top: 15px;padding-bottom: 5px;color: rgb(102, 102, 102);letter-spacing: 1.5px;border-bottom: 1px solid rgb(232, 193, 49);">參考文獻</section></section></section></section></section></section><section style="line-height: normal;"><span style="font-size: 13px;color: rgb(136, 136, 136);"></span></section><section style="line-height: normal;text-align: left;"><span style="font-size: 13px;color: rgb(136, 136, 136);">[1] 微軟Turing-NLG:</span><span style="font-size: 13px;color: rgb(136, 136, 136);">https://www.microsoft.com/en-us/research/blog/turing-nlg-a-17-billion-parameter-language-model-by-microsoft/</span></section><section style="line-height: normal;text-align: left;"><span style="font-size: 13px;color: rgb(136, 136, 136);">[2] 梯度累加:</span><span style="font-size: 13px;color: rgb(136, 136, 136);">https://www.zhihu.com/question/303070254/answer/573037166</span></section><section style="line-height: normal;text-align: left;"><span style="font-size: 13px;color: rgb(136, 136, 136);">[3] 陳天奇 Training Deep Nets with Sublinear Memory Cost: </span><span style="font-size: 13px;color: rgb(136, 136, 136);">https://www.zhihu.com/question/274635237/answer/755102181</span></section><section style="line-height: normal;text-align: left;"><span style="font-size: 13px;color: rgb(136, 136, 136);">[4] 高開遠 Reformer解讀:</span><span style="font-size: 13px;color: rgb(136, 136, 136);">https://zhuanlan.zhihu.com/p/104935987</span></section><section style="line-height: normal;text-align: left;"><span style="font-size: 13px;color: rgb(136, 136, 136);">[5] 混合精度訓練:</span><span style="font-size: 13px;color: rgb(136, 136, 136);">https://zhuanlan.zhihu.com/p/84219777</span></section><section style="line-height: normal;text-align: left;"><span style="font-size: 13px;color: rgb(136, 136, 136);">[6] 英偉達NCCL:</span><span style="font-size: 13px;color: rgb(136, 136, 136);">https://www.zhihu.com/question/63219175/answer/206697974</span></section><section style="line-height: normal;text-align: left;"><span style="font-size: 13px;color: rgb(136, 136, 136);">[7] 數據并行與模型并行:</span><span style="font-size: 13px;color: rgb(136, 136, 136);">https://www.zhihu.com/question/53851014/answer/158794752</span></section><section style="line-height: normal;text-align: left;"><span style="font-size: 13px;color: rgb(136, 136, 136);">[8] 分布式之數據并行:</span><span style="font-size: 13px;color: rgb(136, 136, 136);">https://zhuanlan.zhihu.com/p/68615246</span></section><section style="line-height: normal;text-align: left;"><span style="font-size: 13px;color: rgb(136, 136, 136);">[9] AllReduce:</span><span style="font-size: 13px;color: rgb(136, 136, 136);">https://zhuanlan.zhihu.com/p/100012827</span></section><section style="line-height: normal;text-align: left;"><span style="font-size: 13px;color: rgb(136, 136, 136);">[10] AllReduce細節:</span><span style="font-size: 13px;color: rgb(136, 136, 136);">https://zhuanlan.zhihu.com/p/56991108</span></section><section style="line-height: normal;text-align: left;"><span style="font-size: 13px;color: rgb(136, 136, 136);">[11] GPipe:</span><span style="font-size: 13px;color: rgb(136, 136, 136);">https://arxiv.org/pdf/1811.06965.pdf</span></section><section style="line-height: normal;text-align: left;"><span style="font-size: 13px;color: rgb(136, 136, 136);">[12] PipeDream:</span><span style="font-size: 13px;color: rgb(136, 136, 136);">https://arxiv.org/pdf/1806.03377.pdf</span></section><section style="line-height: normal;text-align: left;"><span style="font-size: 13px;color: rgb(136, 136, 136);">[13] Megatron-LM:</span><span style="font-size: 13px;color: rgb(136, 136, 136);">https://arxiv.org/abs/1909.08053</span></section><section style="line-height: normal;text-align: left;"><span style="font-size: 13px;color: rgb(136, 136, 136);">[14] LAMB:</span><span style="font-size: 13px;color: rgb(136, 136, 136);">https://arxiv.org/abs/1904.00962v3</span></section><section style="line-height: normal;text-align: left;"><span style="font-size: 13px;color: rgb(136, 136, 136);">[15] LAMB解讀:</span><span style="font-size: 13px;color: rgb(136, 136, 136);">https://towardsdatascience.com/an-intuitive-understanding-of-the-lamb-optimizer-46f8c0ae4866</span></section><p style="text-align: left;"><br></p><section style="box-sizing: border-box;"><section style="transform: rotate(0deg);box-sizing: border-box;" powered-by="xiumi.us"><section style="box-sizing: border-box;"><section style="font-size: 16px;display: inline-block;vertical-align: top;width: 35%;background-image: url("https://mmbiz.qpic.cn/mmbiz_gif/5fknb41ib9qFlRb7zLrDsRgynkVacVczeqjMaehuwhf9qfIIoHmD6Inc9AUr47H7ibEFQV5nPKG0vNIhqMqGDdnw/640?wx_fmt=gif");background-position: 50% 50%;background-repeat: no-repeat;background-size: 100%;background-attachment: scroll;box-sizing: border-box;"><section style="text-align: center;margin: 20px 0%;box-sizing: border-box;" powered-by="xiumi.us"><section style="max-width: 100%;vertical-align: middle;display: inline-block;line-height: 0;width: 70%;box-sizing: border-box;"><img data-ratio="1" data-src="https://mmbiz.qpic.cn/mmbiz_jpg/5fknb41ib9qFlRb7zLrDsRgynkVacVczeCDBtLvvLxImY5pWPdFUnDpXdBZGRAuRQtmQlewdzic6OBJwhZIr6D7Q/640?wx_fmt=jpeg" data-type="jpeg" data-w="258" style="vertical-align: middle; box-sizing: border-box; width: 165px !important; height: 165px !important;" _width="100%" class="img_loading" src="https://img-blog.csdnimg.cn/2022010611153455606.gif" crossorigin="anonymous"></section></section></section><section style="display: inline-block;vertical-align: top;width: 65%;box-sizing: border-box;"><section style="font-size: 13px;margin: 20px 0% 8px;box-sizing: border-box;" powered-by="xiumi.us"><section style="display: inline-block;height: 2em;padding: 0.3em 0.5em;vertical-align: top;background-color: rgb(249, 178, 166);color: rgb(255, 255, 255);box-sizing: border-box;"><p style="box-sizing: border-box;">夕小瑤的賣萌屋</p></section><section style="width: 0.5em;display: inline-block;height: 2em;vertical-align: top;border-bottom: 1em solid rgb(249, 178, 166);border-top: 1em solid rgb(249, 178, 166);border-right: 1em solid transparent !important;box-sizing: border-box;"><section style="line-height: 0;color: rgba(0, 0, 0, 0);width: 0px;"><svg viewBox="0 0 1 1" style="vertical-align:top;"><text>_</text></svg></section></section></section><section style="box-sizing: border-box;" powered-by="xiumi.us"><p style="font-size: 14px;white-space: normal;box-sizing: border-box;"><span style="font-size: 13px;">關注&星標小夕,帶你解鎖煉丹秘籍</span></p><p style="white-space: normal;box-sizing: border-box;"><span style="font-size: 13px;">訂閱號主頁下方<strong>「撩一下」</strong>有驚喜哦</span></p></section></section></section></section></section></section></div>
總結
以上是生活随笔為你收集整理的显卡不够时,如何训练大型网络的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: bert速度提升fastbert
- 下一篇: fastbert解读