Pytorch compile not working

divinho: <p>While training I get</p>
<pre><code class="lang-auto">The CUDA Graph is empty. This ususally means that the graph was attempted to be captured on wrong device or stream.
</code></pre>
<p>When I try and run<br>
<code>explanation, out_guards, graphs, ops_per_graph = dynamo.explain(self.encoder, input_tensor, lens)</code></p>
<p>I get an error</p>
<pre><code class="lang-auto">*** torch._dynamo.exc.TorchRuntimeError: 
[..]
.. line 382 in &lt;graph break in forward&gt;
[..]
x = self.out(x.transpose(1, 2).contiguous().view(b, t, c * f))
</code></pre>
<p>I’m doing single node distributed training, which I presume is causing this: <code>skipping cudagraphs due to multiple devices</code> warning.</p>
<p>Also lots of <code>skipping incompatible /usr/lib/libcuda.so when searching for -lcuda</code> (presume that’s unrelated and could be fixed with LD_LIBRARY_PATH set to have matching cuda entries to what pytorch has installed)</p>
<p>This is with a model conformer model (has convolution and attention layers).</p>
<p>Any ideas?</p>

marksaroufim: <p>I don’t believe CUDA graphs is supported with distributed and torch.compile yet, I presume you don’t see this error if you use the default mode?</p>

torchhost: <p><a class="mention" href="/u/marksaroufim">@marksaroufim</a> good to know. May I ask is there official statement that CUDA graphs is not supporting torch.compile yet and when to support in the future? Thanks!</p>

marksaroufim: <p>No official statement but I can speak on behalf of the team. CUDA graphs is supported if you use <code>mode="reduce-overhead"</code> but only for single nodes. If you’re curious about more granular updates feel free to open an issue on Github and tag <span class="mention">@eelison</span></p>
<p>I put most of the gotchas with compile here <a href="https://pytorch.org/docs/master/compile/index.html" class="inline-onebox" rel="noopener nofollow ugc">torch.compile — PyTorch master documentation</a></p>

divinho: <p>To be clear I’m just using torch compile. I assume CUDA graphs was used internally by torch compile, is that not the case? <a class="mention" href="/u/marksaroufim">@marksaroufim</a></p>
<blockquote>
<p>CUDA graphs is supported if you use <code>mode="reduce-overhead"</code> but only for single nodes.</p>
</blockquote>
<p>Is torch compile expected to work for single node multi GPU training? That’s what I’m doing. (I was using that mode too)</p>
<p>When is multinode expected to work, is it weeks or months/years?</p>

marksaroufim: <p><a class="mention" href="/u/wconstab">@wconstab</a> can probably give you a more definite timeline</p>
<p>And to be clear I misspoke above I meant single GPU</p>

wconstab: <p>RE graph breaks caused here</p>
<blockquote>
<p>x = self.out(x.transpose(1, 2).contiguous().view(b, t, c * f))</p>
</blockquote>
<p>I’m not quite sure what causes the graph break without knowing what self.out is.  In general, graph breaks aren’t hard errors so this may be OK.</p>
<p>RE</p>
<blockquote>
<p>The CUDA Graph is empty. This ususally means that the graph was attempted to be captured on wrong device or stream</p>
</blockquote>
<p>and</p>
<blockquote>
<p>skipping cudagraphs due to multiple devices</p>
</blockquote>
<p>First, skipping cudagraphs is not generally a hard error either - you should still get some speedup from compilation even if you don’t use cudagraphs.  Second, I’ll need more info about what kind of distributed APIs you’re using in your model.</p>
<p>Cudagraphs is not supported with FSDP currently, but I am going to have to check whether it works with DDP + compile.  I think it probably should, but haven’t tested it.</p>
<p>Are you using DDP (DistributedDataParallel)?  In this case you’d have one process per gpu, not multiple gpus per process. This is the recommended way to do it.  DataParallel is not supported by torch.compile… (but DDP is more or less equivalent or better, you just have to update your code to use it)</p>

divinho: <p>Thank you for the replies!</p>
<blockquote>
<p>I’m not quite sure what causes the graph break without knowing what self.out is. In general, graph breaks aren’t hard errors so this may be OK.</p>
</blockquote>
<p>self.out is a linear layer followed by a relative positional encoding.</p>
<blockquote>
<p>Are you using DDP (DistributedDataParallel)? In this case you’d have one process per gpu, not multiple gpus per process.</p>
</blockquote>
<p>Yes, I’m using standard pytorch DDP with NCCL.</p>
<p>So if I understand you correctly I should see a speedup even with the cuda graph error when doing single node multi GPU? In my case I definitely am bottlenecked by having a complicated model that’s doing many separate kernel launches.</p>
<p>And to clarify multi node DDP doesnt work yet with torch compile or yes?</p>

wconstab: <p>You could file a github issue on pytorch/pytorch providing a repro (full script that we can run to locally repro the error), but otherwise it’s hard to know what’s going on in your case.</p>
<blockquote>
<p>So if I understand you correctly I should see a speedup even with the cuda graph error when doing single node multi GPU? In my case I definitely am bottlenecked by having a complicated model that’s doing many separate kernel launches.</p>
</blockquote>
<p>Well, how much cudagraphs helps depends on how much your model is cpu/overhead bound in the first place. From your description, it sounds like you may benefit from cudagraphs.  But you may still expect speedup from compilation even without cudagraphs.  It just depends what amount of fusion the compiler can do and whether that ends up being significant in your case.</p>
<blockquote>
<p>And to clarify multi node DDP doesnt work yet with torch compile or yes?</p>
</blockquote>
<p>Multi-node DDP does work with torch.compile.  See <a href="https://dev-discuss.pytorch.org/t/torchdynamo-update-9-making-ddp-work-with-torchdynamo/860" rel="noopener nofollow ugc">this post</a> for more information</p>