akankshakshurai/cuda-error-resolution-analysis huggingface dataset:
AttributeError: Please Help!

annabanana: <p>Hi, I am running a script that uses torch and I keep getting this error:</p>
<p>AttributeError: partially initialized module ‘torch’ has no attribute ‘Tensor’ (most likely due to a circular import)</p>
<p>So far I have tried uninstalling and reinstalling torch, but that has not worked. I am unsure what else to try and any help would be greatly appreciated.</p>

ptrblck: <p>Are you executing your script in a folder containing a <code>torch.py</code> script or inside the PyTorch source code directory?</p>

annabanana: <p>Hi,<br>
I am not doing either of these things. I am executing it in a script located in a github repo I cloned, and this repo doesn’t have a torch.py folder.</p>
<p>I noticed that my torch.py script is located here and not in my torch folder:</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/2/d/2dfb595c8a24ba3c2f4a99d4faf492858b68e519.png" data-download-href="https://discuss.pytorch.org/uploads/default/2dfb595c8a24ba3c2f4a99d4faf492858b68e519" title="image"><img src="https://discuss.pytorch.org/uploads/default/original/3X/2/d/2dfb595c8a24ba3c2f4a99d4faf492858b68e519.png" alt="image" data-base62-sha1="6yLZWpgtda1f4BHPFhwOyUqslap" width="690" height="49" data-dominant-color="393A3A"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">760×54 3.35 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>Is this incorrect? Or do you have any other advice for this kind of issue?</p>

ptrblck: <p>The <code>backends/torch.py</code> file should not be a problem unless you are executing your custom script from the same folder (I don’t think you have created your script in the <code>opt_einsum</code> repository).<br>
In this case, unfortunately I don’t know what might be causing the issues assuming your current working directory does not contain files conflicting with the <code>torch</code> namespace.</p>
Freezing all the layers except specific layers

Tm4: <p>I have a model and I trained that on a dataset. But I changed its last two layers and I want to do a fine-tuning. In other words, I want to freeze all the layers of the model except those two layers (self.conv_6 and self.sigmoid)and training the model on that dataset again.</p>
<p>This is my model:</p>
<pre><code>class model(nn.Module):
def __init__(self, pretrained=False):
    super(model, self).__init__()
    
    self.conv_1 = nn.Conv3d(1024, 1024, kernel_size=(3,1,1), stride=(2,1,1), padding=(1,0,0))
    self.conv_2 = nn.Conv3d(1024, 1024, kernel_size=(3,1,1), stride=(2,1,1), padding=(1,0,0))
    self.conv_3 = nn.Conv3d(1024, 1024, kernel_size=(3,1,1), stride=(2,1,1), padding=(1,0,0))
    self.conv_4 = nn.Conv3d(1024, 1024, kernel_size=(3,1,1), stride=(2,1,1), padding=(1,0,0))
    self.conv_5 = nn.Conv3d(1024, 1024, kernel_size=(3,1,1), stride=(2,1,1), padding=(1,0,0))
    self.conv_6 = nn.Conv3d(1024, 1024, kernel_size=(3,1,1), stride=(2,1,1), padding=(1,0,0))

    
    self.sigmoid = nn.Sigmoid()
    
def forward(self, x):
    
    
    x = self.conv_1(x)
	x = self.conv_2(x)
    x = self.conv_3(x)
    x = self.conv_4(x)
    x = self.conv_5(x)
	
    x = self.conv_6(x)
    y = self.sigmoid(x) 
    return y
</code></pre>
<p>How I can freeze all the layers except those two layers?</p>

ptrblck: <p>Yes, you can freeze all layers via:</p>
<pre><code class="lang-python">for param in model.parameters():
    param.requires_grad = False
</code></pre>
<p>and then unfreeze the trainable layer:</p>
<pre><code class="lang-python">for param in model.conv_6.parameters():
    param.requires_grad = True
</code></pre>
<p><code>nn.Sigmoid</code> does not contain any trainable parameters to you cannot freeze or train it.</p>

Tm4: <p><a class="mention" href="/u/ptrblck">@ptrblck</a>  , Thank you for your answer. In this regard, one question raised for me. Where I should use your lines of codes. Inside the model or in the training code. Also, if I should use in training script,  which part of that I should use them?</p>

ptrblck: <p>You can freeze the parameters right after the model creation and before the training.<br>
If needed you can then freeze or unfreeze additional parameters during the training, e.g. after each training iteration.</p>