akankshakshurai/cuda-error-resolution-analysis huggingface dataset:
Undefined symbol: _Py_ZeroStruct

username: mahmoodn
cooked: <p>Although I have successfully installed pytorch with both python2.7 and python3, when I run a program, I get this error:</p>
<pre><code class="lang-auto">$ python3 main.py
Traceback (most recent call last):
  File "main.py", line 3, in &lt;module&gt;
    import torch
  File "/home/mnaderan/.local/lib/python3.6/site-packages/torch/__init__.py", line 81, in &lt;module&gt;
    from torch._C import *
ImportError: /home/mnaderan/.local/lib/python3.6/site-packages/torch/lib/libtorch_python.so: undefined symbol: _Py_ZeroStruct
Segmentation fault (core dumped)
</code></pre>
<p>The output of <code>python3 setup.py install --user</code> is <a href="https://pastebin.com/MzrGE5G5" rel="nofollow noopener">here</a> and <a href="https://pastebin.com/Py43ra2P" rel="nofollow noopener">here</a>.</p>
Steps to Create Quantized Model

username: mohit7
cooked: <p>Can anyone give the details and steps need to do quantization.<br>
As there is some confusion - for MobilenetV2 example there is different ways and in the other example there is different example.<br>
Is there some general way?</p>

username: raghuramank100
cooked: <p>Hi Mohit,<br>
Are you interested in quantizing CV models? Are you targeting mobile devices?<br>
If so, you can follow the tutorial here: <a href="https://pytorch.org/tutorials/advanced/static_quantization_tutorial.html" rel="nofollow noopener">https://pytorch.org/tutorials/advanced/static_quantization_tutorial.html</a></p>
<p>In general, you can start with post training quantization (the available options depend on whether it is server or mobile). You can get the recommended qconfig to use for post training quantization by calling:</p>
<pre><code class="lang-auto"># Gets the recommended qconfig for post training quantization
model.qconfig = torch.quantization.get_default_qconfig('fbgemm') #'fbgemm' for server and 'qnnpack' for mobile
#Also, remember to set your backend engine to match what you use here:
torch.backends.quantization.engine = 'fbgemm' 
</code></pre>
<p>If the accuracy is not good enough, you will have to do quantization aware training, which is more involved. You can see reference code at: <a href="https://github.com/pytorch/vision/blob/master/references/classification/train_quantization.py" rel="nofollow noopener">https://github.com/pytorch/vision/blob/master/references/classification/train_quantization.py</a></p>

username: mohit7
cooked: <p>Hey <a class="mention" href="/u/raghuramank100">@raghuramank100</a> , instead of giving wrong answers don’t give the answers. It is misguiding to others. The API you mentioned doesn’t even exist. I wasted my 2 hours on this.<br>
Thanks,<br>
Mohit Ranawat</p>

username: raghuramank100
cooked: <p>Hi Mohit,<br>
Looks like I made a mistake in the instructions. This should work:</p>
<pre><code class="lang-python">qconfig = torch.quantization.get_default_qconfig('fbgemm')
print(torch.backends.quantized.supported_engines) # Prints the quantized backends that are supported
# Set the backend to what is needed. This needs to be consistent with the option you used to select the qconfig
torch.backends.quantized.engine='fbgemm'
</code></pre>
How do you save your model's code?

username: MLaurenceFournier
cooked: <p>Hi all,<br>
Coming from Keras (TensorFlow), I used to have a somewhat robust way to save/load models trained in previous development iterations. Now using PyTorch, I learned that it’s preferable to save only the model parameters contained in the model.state_dict(). I would like to be able to edit my model code, retrain the model and then perform various experiments on this last model and also its predecessors. I can only think of two naive approaches:</p>
<ol>
<li>Have a model definition function that supports a version argument. Save the model version with the model state dict and, during loading, use it to build the good model.</li>
</ol>
<p>pros: explicit<br>
cons: would get messy pretty quickly, would require lots of discipline to keep the old code unchanged</p>
<ol start="2">
<li>Save the code of the model with the model state dict. During loading, dynamically use this code to build the model.</li>
</ol>
<p>pros: less messy<br>
cons: would probably get complex if the model definition function and its dependencies don’t fit in a single file (which, excluding libraries, is not my case for now)</p>
<p>Cleary both approaches could still break if I change my python environment (update the project dependencies) but I guess I can live with that. Do you think these approaches are viable? Do you know better?</p>

username: Kushaj
cooked: <p>I don’t think it is possible to save raw written code. Torchscript can be used, where the model is converted to torchscript and that can be saved.</p>

username: MLaurenceFournier
cooked: <p>Thank you. I will definitely look into torchscript eventually. For now, I just save the code of my model building function as a string (obtains with the inspect module). When loading, I use exec. This is probably not a really clean way to serialize a function but it works for my needs. The dill package might be a better way. I also realized my question is really specific to the way I work, where each revision only defines one version of the model.</p>
Upgrading from CPU only to GPU

username: wrvprvnb
cooked: <p>I have torch and torchvision installed through both conda and pip, although both are CPU based. Since I have a GPU now, I want conda version to be upgraded to GPU version. Any help on the steps to do it?</p>

username: ptrblck
cooked: <p>You can install the binaries with CUDA by selecting your OS, CUDA version etc. from <a href="https://pytorch.org/get-started/locally/">the website</a>.</p>

username: wrvprvnb
cooked: <p>thanks for the quick response. doing that will remove cpu version as well?</p>

username: ptrblck
cooked: <p>I would guess so (haven’t tested it in the past weeks though).<br>
If you want to keep multiple PyTorch versions, I would recommend to create virtual environments.</p>
ONNX to Caffe2 in C++

username: SPark9625
cooked: <p>I saved a pytorch model using onnx, following the instructions shown <a href="https://pytorch.org/tutorials/advanced/super_resolution_with_caffe2.html" rel="nofollow noopener">here</a></p>
<p>Now I would like to load this model in C++. I’ve spent a whole day googling and trying out different things without any luck.</p>
<p>I’ve tried <code>CAFFE_ENFORCE(ReadProtoFromFile(path, &amp;init_net));</code>, where <code>path</code> is a std::string pointing to the onnx file, but this throws an error which I assume is because <code>ReadProtoFromFile</code> is expecting path to a protobuf file.</p>
<p>Ideally I would like to get the <code>init_net</code> and <code>run_net</code> set and use the <code>Predictor</code> API for inference. If someone could give me a pointer, that’d be great.</p>
<p>Any help is highly appreciated. Help!</p>

username: alexbuyval
cooked: <p>Hi,</p>
<p>you may run the following command:</p>
<pre><code class="lang-auto">convert-onnx-to-caffe2 model.onnx --output predict_net.pb --init-net-output init_net.pb
</code></pre>
<p>to convert an onnx model to caffe model’s files</p>

username: Marat
cooked: <p>Thanks for your answer but is there any possibility to obtain caffe2 in text format because as I know TensorRT parser requires TXT format?</p>
Extend RNNBase class with c++ backend

username: wahouh
cooked: <p>Hi,</p>
<p>I have written in c++ the forward and backward functions for a custom recurrent neural network thanks to this tutorial : <a href="https://pytorch.org/tutorials/advanced/cpp_extension.html" rel="nofollow noopener">https://pytorch.org/tutorials/advanced/cpp_extension.html</a> .</p>
<p>To benefit the pytorch API I would like to extend the RNNBase class from torch.nn.modules.rnn to make it behave exactly like a normal RNN. How would it be possible ?<br>
As I understand it there is some kind of backend to register as Variable Function but I don’t understand how the binding is made.</p>
<p>Thanks for the help !</p>
Torchvision.__version__ causing "attribute error - module has no attribute __version__"

username: AghiadHaloul
cooked: <p>Hi, I’m wondering what is the alternative for <code>__version__ </code> in torchvision? It used to work normally but now it doesn’t and I’m not able to find the alternative in the documentation.</p>
<p>Error received when calling <code>print(torchvision.__version__)</code> is</p>
<blockquote>
<p>AttributeError: module ‘torchvision’ has no attribute ‘<strong>version</strong>’</p>
</blockquote>
<p>Thanks!</p>

username: ptrblck
cooked: <p>It might be a tough question, but do you remember which version you’ve installed (or when from which source)?<br>
The command still works for <code>0.5.0a0+28003e9</code>.<br>
Are you able to use <code>torchvision</code> besides this missing piece?</p>

username: AghiadHaloul
cooked: <p>I switched my anaconda environment and updated my packages and now it is working with torchvision 0.4.2 and torch 1.3.1.</p>
<p>I was running torchvision version is 0.4.1, it seems to be the latest I can get through pip for some reason.</p>
<blockquote>
<p>pip install --upgrade torchvision</p>
</blockquote>
<p>returns</p>
<pre><code class="lang-auto">Requirement already up-to-date: torchvision in c:\users\...\lib\site-packages (0.4.1)
Requirement already satisfied, skipping upgrade: pillow&gt;=4.1.1 in c:\users\...\lib\site-packages (from torchvision) (6.2.1)
Requirement already satisfied, skipping upgrade: torch in c:\users\...\lib\site-packages (from torchvision) (1.0.1)
Requirement already satisfied, skipping upgrade: numpy in c:\users\...\lib\site-packages (from torchvision) (1.17.4)
Requirement already satisfied, skipping upgrade: six in c:\users\...\lib\site-packages (from torchvision) (1.13.0)

</code></pre>
<p>Everything is working now, however  I’m still unable to find the command in the documentation, which is why I thought the syntax might have changed.</p>
Nvlink error (nccl)

username: yuanqing_miao
cooked: <p>Hi!  I was wondering whether the installation of nccl is alright if there is no Nvlink?</p>
<p>I came across Nvlink error while I am installing pytorch from the source. I don’t have an Nvlink. To solve the problem, I turned off the switch “NCCL”. Will it affect the use of Multi-GPU? Is there any substitution of Nvlink when installing NCCL?</p>

username: gfrogat
cooked: <p>NCCL does not require NV{Link,Switch} but also works with PCIe. If you don’t have it properly installed Multi-GPU performance will likely be poor.</p>
<p>Can you please post the error that you got during compilation?</p>
<p>If you are compiling from source, did you update the submodules (e.g. because you are building a specific PyTorch release)?</p>
Reference request about pytorch tutorial

username: skyline
cooked: <p>I have read the recent pytorch tutorial book.But I want to know more about data type in pytorch, how the computational graph work,how to define function and new module in pytorch. Is there some easy to digest  resources for these topics with good example?</p>

username: albanD
cooked: <p>You can find in the doc some notes about <a href="https://pytorch.org/docs/stable/notes/autograd.html">the autograd</a>, how to <a href="https://pytorch.org/docs/stable/notes/extending.html">extend function and modules</a> and <a href="https://pytorch.org/docs/stable/tensors.html">tensors</a>.</p>
How to use torch.autograd.backward()

username: VictoriaYyz
cooked: <p>I have a network, for example input-&gt;conv1-&gt;bn1-&gt;relu-&gt;pool1. Now I have the gradient of pool1, and I want to calculate all the gradients of the network w.r.t the input, can it works: torch.autograd.backward(network, grad_tensors=pool1_gradient) ?</p>
<p>Hope someone can give answers, thanks!</p>

username: albanD
cooked: <p>Hi,</p>
<p>You can check <a href="https://pytorch.org/docs/stable/autograd.html?highlight=backward#torch.autograd.backward">the doc</a> but backward takes the output of your forward (not the network) and you can give <code>grad_tensors=pool1_gradient</code> indeed.</p>

username: VictoriaYyz
cooked: <p>Thanks for reply, I wonder if I use torch.autograd.backward(pool1_output, grad_tensors=pool1_gradient) , gradients of all layers w.r.t the input can be computed or just the gradient of pool1 is computed?</p>

username: albanD
cooked: <p>When you call <code>.backward()</code>, it will populate the <code>.grad</code> field for all the leaf Tensor (such as nn.Parameter) that were used to compute your output.</p>
ONNX model has been generated with INT64 weights?

username: student-2018AI
cooked: <p>hi,</p>
<p>when train  a classifier by using  pre-trained resnet18  and then convert the pytorch to onnx,<br>
i meet a error : " WARNING: Your ONNX model has been generated with INT64 weights".</p>
<p>how does the INT64 weight come up?<br>
my pytorch version is 1.1.0 ,torchvision is 0.3.0 and python3.6.</p>
Cannot move PackedSequence to GPU

username: eplu
cooked: <p>I am having trouble moving a PackedSequence to my GPU after creating the PackedSequence by calling torch.nn.utils.rnn.pack_padded_sequence.</p>
<p>First, I create PackedSequence by running:</p>
<pre><code class="lang-auto">packed = torch.nn.utils.rnn.pad_packed_sequence(data, lengths, enforce_sorted=False, batch_first=False)
</code></pre>
<p>where data is a data and lengths are float and long tensors respectively &amp; both have CPU backends. At this point, packed.is_cuda returns false.</p>
<p>Later I move packed onto the GPU by running:</p>
<pre><code class="lang-auto">packed = packed.to(device)
</code></pre>
<p>Here, device was created using <code>device = torch.device('cuda')</code>. At this point, packed.is_cuda returns true. But when I pass packed to the forward function in an RNN, it gives the following error:</p>
<p>RuntimeError: Expected object of backend CUDA but got backend CPU for argument <span class="hashtag">#3</span> ‘index’</p>
<p>When I re-write my code to move data to the gpu before packing, everything works as expected. My conclusion is that either PackedSequence.to(…) is broken, there’s something wrong with my cuda configuration, or this is poorly documented intended behavior.</p>
<p>Is this intentional? Has anyone else had this problem?</p>
<p>To avoid the error, I’ve switched to moving my tensors to the gpu in my dataloader collate_fn before calling pack_padded_sequence. For now, I’ve switched to 0 workers in my Dataloader, since I heard that cuda doesn’t interface with multi-threading well. This significantly slows my training code, so I’m looking for a more efficient work around if one exists.</p>

username: arturs.polis
cooked: <p>I’ve ran into the same issue, and it feels like a bug in PackedSequence, which it looks like it’s fixed:</p>
<p><a href="https://github.com/pytorch/pytorch/commit/527b10c2d1b605828df3b4844436ef0636d2c5e6#diff-53d2b0eacfe473028583255d9bf67f59" rel="nofollow noopener">here</a>, and if my reading of Github info is correct, it should be available latest in PyTorch 1.4.0 (?)</p>
Nvlink error ( installing from source )

username: yuanqing_miao
cooked: <p>I am trying to install pytorch from source. However, I come across an nvlink error. I was wondering whether it’s due to my inappropriate environment or something else like the carelessness of your development.<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/8/a/8ab444eabc542958da44cad85a3a25423236c547.png" data-download-href="https://discuss.pytorch.org/uploads/default/8ab444eabc542958da44cad85a3a25423236c547" title="image"><img src="https://discuss.pytorch.org/uploads/default/original/3X/8/a/8ab444eabc542958da44cad85a3a25423236c547.png" alt="image" data-base62-sha1="jN27bA5rrWdqcKJ482apMizwiaz" width="690" height="119" data-dominant-color="181818"><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">1651×286 45.3 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><br>
Could anyone help me with this nvlink error?</p>

username: txfs1926
cooked: <p>Hi,<br>
you can try to turn-off NCCL support in CmakeLists.txt.</p>

username: yuanqing_miao
cooked: <p>Oh, exciting!  I solved it! Thank you for your help!</p>

username: yuanqing_miao
cooked: <p>Hello, I still have problems with the installation. If I turn-off NCCL, I won’t be able to use multi-GPU, will I?</p>
<p>And I have NVCC error:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/0/5/05e54e7fb44b24812eb808413343daa5df2bdfa6.png" data-download-href="https://discuss.pytorch.org/uploads/default/05e54e7fb44b24812eb808413343daa5df2bdfa6" title="image"><img src="https://discuss.pytorch.org/uploads/default/original/3X/0/5/05e54e7fb44b24812eb808413343daa5df2bdfa6.png" alt="image" data-base62-sha1="Q9FOZbliAWfxHhsKarlsNz6zQy" width="690" height="97" data-dominant-color="0A0A0A"><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">1453×205 12 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><br>
Could anyone help me with that?</p>