Weird NotImplementedError

username: KleinXin
cooked: <p>I am trying to make some changes to RepLKNet published on CVPR2022. So I seperate the network into several parts by using ‘.children’. My codes are shown below</p>
<pre><code class="lang-auto">import torch
import torch.nn as nn
import torchvision.utils
import torchvision.models as tv_models

from networks import replknet 

if __name__ == "__main__":

   basenet = replknet.create_RepLKNet31B(small_kernel_merged=False,use_checkpoint=True)

   self_stem_block = list(basenet.children())[0]
   self_main_block_0 = list(basenet.children())[1][0]
   self_main_block_1 = list(basenet.children())[1][1]
   self_main_block_2 = list(basenet.children())[1][2]
   self_main_block_3 = list(basenet.children())[1][3]
   self_out_conv = list(basenet.children())[2]
   self_sync_bn = list(basenet.children())[3]
   self_avg_pool = list(basenet.children())[4]
   self_classifier = list(basenet.children())[5]

   x = torch.ones(1,3,224,224).cuda()

   x = self_stem_block(x)

</code></pre>
<p>replknet  is the codes of RepLKNet which can be found <a href="https://github.com/DingXiaoH/RepLKNet-pytorch/blob/main/replknet.py" class="inline-onebox" rel="noopener nofollow ugc">RepLKNet-pytorch/replknet.py at main · DingXiaoH/RepLKNet-pytorch · GitHub</a></p>
<p>The it gives the error</p>
<pre><code class="lang-auto">Traceback (most recent call last):
  File "test_load_model.py", line 66, in &lt;module&gt;
    x = self_stem_block(x)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 1102, in _call_impl
    return forward_call(*input, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 201, in _forward_unimplemented
    raise NotImplementedError
NotImplementedError

</code></pre>
<p>It seems some of the module in RepLKNet does not have forward method implementation.</p>
<p>Anyone knows why? Any suggestion is appreciated.</p>

username: InnovArul
cooked: <aside class="quote no-group" data-username="KleinXin" data-post="1" data-topic="149759">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/k/90db22/48.png" class="avatar"> KleinXin:</div>
<blockquote>
<p><code>x = self_stem_block(x)</code></p>
</blockquote>
</aside>
<p>Probably print the <code>self_stem_block</code> and see what module it is.<br>
If its <code>nn.ModuleList()</code>, there is no forward method for it.<br>
Check  <code>RepLKNet</code>’s <code>forward()</code> method to see how they extract the features and try to follow the same.</p>

username: KleinXin
cooked: <p>Thank you for your reply. Following your suggestion, I changed my codes so that each submodule of the modulelist can be acquired. But it gives me another error as below</p>
<pre><code class="lang-auto">import torch
import torch.nn as nn
import torchvision.utils
import torchvision.models as tv_models

from networks import replknet 

if __name__ == "__main__":

   basenet = replknet.create_RepLKNet31B(small_kernel_merged=False,use_checkpoint=True)

   self_stem_block = list(basenet.children())[0]
   self_main_block_0 = list(basenet.children())[1][0]
   self_main_block_1 = list(basenet.children())[1][1]
   self_main_block_2 = list(basenet.children())[1][2]
   self_main_block_3 = list(basenet.children())[1][3]
   self_out_conv = list(basenet.children())[2]
   self_sync_bn = list(basenet.children())[3]
   self_avg_pool = list(basenet.children())[4]
   self_classifier = list(basenet.children())[5]

   x = torch.ones(1,3,224,224).cuda()

  self_stem_block_0 = self_stem_block[0]

  self_stem_block_0.cuda()

  x = self_stem_block_0(x)

</code></pre>
<pre><code class="lang-auto">Traceback (most recent call last):
File "test_load_model_rlk.py", line 86, in &lt;module&gt;
  x = self_stem_block_0(x)
File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 1102, in _call_impl
  return forward_call(*input, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/container.py", line 141, in forward
  input = module(input)
File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 1102, in _call_impl
  return forward_call(*input, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/batchnorm.py", line 732, in forward
  world_size = torch.distributed.get_world_size(process_group)
File "/usr/local/lib/python3.6/dist-packages/torch/distributed/distributed_c10d.py", line 845, in get_world_size
  return _get_group_size(group)
File "/usr/local/lib/python3.6/dist-packages/torch/distributed/distributed_c10d.py", line 306, in _get_group_size
  default_pg = _get_default_group()
File "/usr/local/lib/python3.6/dist-packages/torch/distributed/distributed_c10d.py", line 411, in _get_default_group
  "Default process group has not been initialized, "
RuntimeError: Default process group has not been initialized, please make sure to call init_process_group.

</code></pre>