Stuck at `nn.init.orthogonal_()`

syedmech47: <p>In a pytorch model, one of the line is to initialise the weights of a module using orthogonal. But sometimes, on Linux, when initialising the model which internally initialises the modules, the system is stuck at the init orthogonal_ line for a very long time.</p>
<p>Here is the model code, which is calling another module.</p><aside class="onebox githubblob" data-onebox-src="https://github.com/PlakshaMGH/XMem/blob/2070d72bfffaf3c61dcf7fa90c3fd0ede00b9552/model/network.py#L33">
  <header class="source">

      <a href="https://github.com/PlakshaMGH/XMem/blob/2070d72bfffaf3c61dcf7fa90c3fd0ede00b9552/model/network.py#L33" target="_blank" rel="noopener nofollow ugc">github.com</a>
  </header>

  <article class="onebox-body">
    <h4><a href="https://github.com/PlakshaMGH/XMem/blob/2070d72bfffaf3c61dcf7fa90c3fd0ede00b9552/model/network.py#L33" target="_blank" rel="noopener nofollow ugc">PlakshaMGH/XMem/blob/2070d72bfffaf3c61dcf7fa90c3fd0ede00b9552/model/network.py#L33</a></h4>



    <pre class="onebox"><code class="lang-py">
      <ol class="start lines" start="23" style="counter-reset: li-counter 22 ;">
          <li>    super().__init__()</li>
          <li>    model_weights = self.init_hyperparameters(config, model_path, map_location)</li>
          <li></li>
          <li>    self.single_object = config.get('single_object', False)</li>
          <li>    print(f'Single object mode: {self.single_object}')</li>
          <li></li>
          <li>    self.key_encoder = KeyEncoder()</li>
          <li>    self.value_encoder = ValueEncoder(self.value_dim, self.hidden_dim, self.single_object)</li>
          <li></li>
          <li>    # Projection from f16 feature space to key/value space</li>
          <li class="selected">    self.key_proj = KeyProjection(1024, self.key_dim)</li>
          <li></li>
          <li>    self.decoder = Decoder(self.value_dim, self.hidden_dim)</li>
          <li></li>
          <li>    if model_weights is not None:</li>
          <li>        self.load_weights(model_weights, init_as_zero_if_needed=True)</li>
          <li></li>
          <li>def encode_key(self, frame, need_sk=True, need_ek=True): </li>
          <li>    # Determine input shape</li>
          <li>    if len(frame.shape) == 5:</li>
          <li>        # shape is b*t*c*h*w</li>
      </ol>
    </code></pre>



  </article>

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

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

<p>The orthogonal_ is being called in this module. I had to add print statement above and below every line, to check where exactly the code is getting stuck, and at this line is where it gets stuck.</p><aside class="onebox githubblob" data-onebox-src="https://github.com/PlakshaMGH/XMem/blob/2070d72bfffaf3c61dcf7fa90c3fd0ede00b9552/model/modules.py#L204">
  <header class="source">

      <a href="https://github.com/PlakshaMGH/XMem/blob/2070d72bfffaf3c61dcf7fa90c3fd0ede00b9552/model/modules.py#L204" target="_blank" rel="noopener nofollow ugc">github.com</a>
  </header>

  <article class="onebox-body">
    <h4><a href="https://github.com/PlakshaMGH/XMem/blob/2070d72bfffaf3c61dcf7fa90c3fd0ede00b9552/model/modules.py#L204" target="_blank" rel="noopener nofollow ugc">PlakshaMGH/XMem/blob/2070d72bfffaf3c61dcf7fa90c3fd0ede00b9552/model/modules.py#L204</a></h4>



    <pre class="onebox"><code class="lang-py">
      <ol class="start lines" start="194" style="counter-reset: li-counter 193 ;">
          <li>class KeyProjection(nn.Module):</li>
          <li>    def __init__(self, in_dim, keydim):</li>
          <li>        super().__init__()</li>
          <li></li>
          <li>        self.key_proj = nn.Conv2d(in_dim, keydim, kernel_size=3, padding=1)</li>
          <li>        # shrinkage</li>
          <li>        self.d_proj = nn.Conv2d(in_dim, 1, kernel_size=3, padding=1)</li>
          <li>        # selection</li>
          <li>        self.e_proj = nn.Conv2d(in_dim, keydim, kernel_size=3, padding=1)</li>
          <li></li>
          <li class="selected">        nn.init.orthogonal_(self.key_proj.weight.data)</li>
          <li>        nn.init.zeros_(self.key_proj.bias.data)</li>
          <li>    </li>
          <li>    def forward(self, x, need_s, need_e):</li>
          <li>        shrinkage = self.d_proj(x)**2 + 1 if (need_s) else None</li>
          <li>        selection = torch.sigmoid(self.e_proj(x)) if (need_e) else None</li>
          <li></li>
          <li>        return self.key_proj(x), shrinkage, selection</li>
          <li></li>
          <li></li>
          <li>class Decoder(nn.Module):</li>
      </ol>
    </code></pre>



  </article>

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

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

<p>Any help would be highly appreciated.</p>