A GPipe implementation in PyTorch

sublee: <p>Kakao Brain announces <a href="https://github.com/kakaobrain/torchgpipe" rel="nofollow noopener">torchgpipe</a>, an implementation of <a href="https://arxiv.org/abs/1811.06965" rel="nofollow noopener">GPipe</a> in PyTorch as a handy library.</p>
<pre><code class="lang-python">from torchgpipe import GPipe
model = nn.Sequential(a, b, c, d)
model = GPipe(model, balance=[1, 1, 1, 1], chunks=8)
output = model(input)
</code></pre>
<p>GPipe is a scalable pipeline parallelism library published by Google Brain. It leverages the training of a giant model which requires much memory. For instance, Google trained AmoebaNet-B with 557M parameters over GPipe.</p>
<aside class="onebox whitelistedgeneric">
  <header class="source">
      <img src="https://github.githubassets.com/favicon.ico" class="site-icon" width="32" height="32">
      <a href="https://github.com/kakaobrain/torchgpipe" target="_blank" rel="nofollow noopener">GitHub</a>
  </header>
  <article class="onebox-body">
    <img src="https://avatars0.githubusercontent.com/u/25736994?s=400&amp;amp;v=4" class="thumbnail onebox-avatar" width="400" height="400">

<h3><a href="https://github.com/kakaobrain/torchgpipe" target="_blank" rel="nofollow noopener">kakaobrain/torchgpipe</a></h3>

<p>A GPipe implementation in PyTorch. Contribute to kakaobrain/torchgpipe development by creating an account on GitHub.</p>


  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>


ddd: <p>Hi, I’m trying to use torchgpipe on some other models. But the training time increased with GPipe. And I can’t reproduce the paper’s result with torchgpipe’s example resnet101. I think I might measure the training time in a wrong way. How did you measure the training time of resnet101 on GPipe? Thanks ahead!</p>

pietern: <p>I would expect the training time to take a hit, because you’re moving much more data around compared to a direct forward/backward. All of that overhead will come at a performance penalty. If I understand correctly, pipelining with this approach is best suited for allowing extremely large models to train if you have limited memory available.</p>

sublee: <p>Hi, thank you for your question.</p>
<p>There are some conditions to optimize a model with GPipe:</p>
<ul>
<li>The model requires a large amount of memory.</li>
<li>The original batch size is not so small. Because we need a micro-batch which is not too small. If a micro-batch is too small, GPU wouldn’t be utilized.</li>
<li>Well balanced. The imbalance between partitions makes GPipe underutilized.</li>
</ul>
<p>I just published <a href="https://github.com/kakaobrain/torchgpipe/tree/master/examples/resnet101_performance_benchmark" rel="nofollow noopener">my ResNet-101 performance benchmark</a>. If you have the same environment with me, I expect you get the same result. Even you don’t have the same environment, the code will be helpful. Especially, you can check the balance of ResNet-101 what I’ve used, and how I measured the training time.</p>

ddd: <p>Yeah, I totally agreed. I guess this approach only suits some models. It’s just in the paper they achieved really great result on AmoebaNet, in terms of both memory usage and training time, which made me doubt my result.</p>

ddd: <p>Thanks a lot for your expaination! My GPU memory is too small for a large batch size which limits my tests. I guess the main purpose of GPipe is to enable us to train extremely large model not to accelerate the training process.</p>
<p>I noticed that in the your experiments, pipeline methods use different batch size. Isn’t this going to affect the model performance?</p>

sublee: <p>Good question. Yes, it affects. My experiment reproduces a performance benchmark in the original paper. The benchmark also uses adjusted batch size to maximize throughput regardless of the model accuracy.</p>
<blockquote>
<p>In our experiments, we mea- sured the effects of pipeline parallelism and recomputation on the model throughput of ResNet-101 and AmoebaNet-D (4, 512). We fixed the image size at 224 × 224. <em>We adjusted the mini-batch size to maximize the throughput.</em></p>
</blockquote>

ddd: <p>I see, thank you so muck!</p>

sublee: <p>I just released v0.0.2 of torchgpipe with <a href="https://torchgpipe.readthedocs.io/en/v0.0.2/" rel="nofollow noopener">the detailed documentation</a>. This version includes the automatic balancing.</p>