Shared_memory for Mesh object : Pytorch3d

username: ucalyptus1
cooked: <p>I was curious as to how to do this?</p>
<pre><code class="lang-auto">import torch.multiprocessing as mp
from pytorch3d.ops import sample_points_from_meshes
def Sample(mesh_obj,n_points,device):
  return sample_points_from_meshes(mesh_obj,n_points).to(device)
def creator_parallel(mesh_obj:Meshes,n_points:int,length:int):
  num_of_processes = length
  mesh_obj.share_memory() #main requirement
  processes = []
  for rank in range(num_of_processes):
    p = mp.Process(target=Sample,args=(mesh_obj,n_points,device))
    p.start()
    processes.append(p)
  for p in processes:
      p.join()
  
creator_parallel(trg_mesh,1000,50)

</code></pre>

username: albertotono
cooked: <p>Are you running into a lack of GPU memory in the Google Colab?</p>

username: ucalyptus1
cooked: <p>Yes, <a class="mention" href="/u/albertotono">@albertotono</a>. That’s the case plus I’m wanting to explore Multiproc ways to do this.</p>

username: albertotono
cooked: <aside class="quote no-group" data-username="ucalyptus1" data-post="1" data-topic="96227">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ucalyptus1/48/28986_2.png" class="avatar"> ucalyptus1:</div>
<blockquote>
<p><code>mesh_obj,n_points,device</code></p>
</blockquote>
</aside>
<p>Ok. in your task you are trying to use multiprocessing for transforming Pytorch3d meshes to points.</p>
<p>In the <a href="https://towardsdatascience.com/this-is-hogwild-7cc80cd9b944" rel="noopener nofollow ugc">Hogwild implementation</a> it has been mainly used for training the model like also reported <a href="https://pytorch.org/docs/stable/notes/multiprocessing.html" rel="noopener nofollow ugc">here</a>.</p>
<p>When a <a href="https://pytorch.org/docs/stable/tensors.html#torch.Tensor" rel="noopener nofollow ugc"> <code>Tensor</code> </a> is sent to another process, the <a href="https://pytorch.org/docs/stable/tensors.html#torch.Tensor" rel="noopener nofollow ugc"> <code>Tensor</code> </a> data is shared. You can also change <a href="https://pytorch.org/docs/stable/autograd.html#torch.Tensor.grad" rel="noopener nofollow ugc"> <code>torch.Tensor.grad</code> </a> to not  <code>None</code> , to share it.</p>
<p>But those implementations are focused on Models and training procedure inside the model…so I will implement directly there.</p>
<p>Also this I hope it helps</p><aside class="onebox discoursetopic" data-onebox-src="https://forums.fast.ai/t/distributed-and-parallel-training-explained/73892">
  <header class="source">
      <img src="https://forums.fast.ai/uploads/default/optimized/3X/b/3/b395de7a2ba00b82865031c97a8cadf3d80e71e5_2_32x32.png" class="site-icon" width="" height="">

      <a href="https://forums.fast.ai/t/distributed-and-parallel-training-explained/73892" target="_blank" rel="noopener nofollow ugc" title="09:16PM - 25 June 2020">fast.ai Course Forums – 25 Jun 20</a>
  </header>

  <article class="onebox-body">
    <img src="https://forums.fast.ai/uploads/default/optimized/3X/b/8/b86c305a4aefb18531b2a2889692c3a76c626107_2_1024x403.png" class="thumbnail" width="" height="">

<div class="title-wrapper">
  <h3><a href="https://forums.fast.ai/t/distributed-and-parallel-training-explained/73892" target="_blank" rel="noopener nofollow ugc">Distributed and parallel training... explained</a></h3>
  <div class="topic-category">
      <span class="badge-wrapper bullet">
        <span class="badge-category-bg" style="background-color: #0088CC;"></span>
        <span class="badge-category clear-badge">
          <span class="category-name">Part 1 (2020)</span>
        </span>
      </span>
  </div>
</div>

  <p>[ EDIT - 06/29/2020 ] Do not follow this post about Data Parallel (DP) and Distributed Data Parallel (DDP) training in PyTorch and fastai v2: it contains wrong code. Instead, you should look at the Distributed and parallel training fastai v2...</p>

  <p>
    <span class="label1">Reading time: 13 mins 🕑</span>
      <span class="label2">Likes: 28 ❤</span>
  </p>

  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>