How do you use PyTorch PackedSequence in code?

Can someone give a full working code (not a snippet, but something that runs on a variable-length recurrent neural network) on how would you use the PackedSequence method in PyTorch? There do not...

Why do we need to call zero_grad() in PyTorch?

The method zero_grad() needs to be called during training. But the documentation is not very helpful | zero_grad(self) | Sets gradients of all model parameters to zero. Why do we need to...

How to check if pytorch is using the GPU?

I would like to know if pytorch is using my GPU. It's possible to detect with nvidia-smi if there is any activity from the GPU during the process, but I want something written in a python...

How to use multiple GPUs in pytorch?

I am learning pytorch and follow this tutorial. I use this command to use a GPU. device = torch.device("**cuda:0**" if torch.cuda.is_available() else "cpu") But, I want to use two GPUs in...

Label Smoothing in PyTorch

I'm building a ResNet-18 classification model for the Stanford Cars dataset using transfer learning. I would like to implement label smoothing to penalize overconfident predictions and improve...

PyTorch - Getting the 'TypeError: pic should be PIL Image or ndarray. Got <class 'numpy.ndarray'>' error

I am getting the error TypeError: pic should be PIL Image or ndarray. Got <class 'numpy.ndarray'> when I try to load a non-image dataset through the DataLoader. The versions of torch and...

Conda downgrade numpy version

I need to downgrade numpy version: python -c "import numpy; print(numpy.__version__)" 1.16.4 conda install numpy==1.14.3 Collecting package metadata (current_repodata.json): done Solving...

How to clear GPU memory after PyTorch model training without restarting kernel

I am training PyTorch deep learning models on a Jupyter-Lab notebook, using CUDA on a Tesla K80 GPU to train. While doing training iterations, the 12 GB of GPU memory are used. I finish training...

Module Not Found Error when importing Pytorch_Transformers

After downloading pytorch_transformers through Anaconda and executing the import command through the Jupyter Notebook, I am facing several errors related to missing modules. I tried searching...

RuntimeError: Input type (torch.FloatTensor) and weight type (torch.cuda.FloatTensor) should be the same

I am trying to train the following CNN as follows, but I keep getting the same error regarding .cuda() and I am not sure how to fix it. Here is a chunk of my code so far. import matplotlib.pyplot...

How to specify pytorch / cuda version in pipenv

I am trying to install a specific version of pytorch that is compatible with a specific cuda driver version with pipenv. The pytorch website shows how to to this with pip: pip3 install...

AttributeError: module 'tensorflow' has no attribute 'value'

I am training pytorch-yolov3 in custom dataset. I prepared all the required txt, data and names files . while runninng following command: python3 train.py --model_def config/yolov3.cfg...

totally clear GPU memory

I can't seem to clear the GPU memory after sending a single variable to the GPU. import torch tm =...

How do i iterate over pytorch 2d tensors?

X = np.array([ [-2,4,-1], [4,1,-1], [1, 6, -1], [2, 4, -1], [6, 2, -1], ]) for epoch in range(1,epochs): for i, x in enumerate(X): X = torch.tensor([ [-2,4,-1], ...

OSError: [E050] Can't find model 'de'. It doesn't seem to be a shortcut link, a Python package or a valid path to a data directory

So I am trying to make a seq to seq model for translating german to english using pytorch on online notebook like kaggle notebook and google colab import torch import torch.nn as nn import...

trouble with using tokenizer.encode_plus

#jupyter notebook I'm trying to study BERT Classifier with https://colab.research.google.com/drive/1pTuQhug6Dhl9XalKB0zUGf4FIdYFlpcX#scrollTo=2bBdb3pt8LuQ In that colab, starting with "Tokenize...

values in torch.nn.conv2d and torch.nn.Linear

I am confiused how to get the out_channels in torch.nn.Conv2d and the in_features, out_features in torch.nn.Linear. For example I have a non-color 28*28 image input. the in_channels =...

Runtime error while trying dynamic quantization on transformer model

I am trying to do dynamic quantization(quantizes the weights and the activations) on a pytorch pre-trained model from huggingface library. I have referred this link and found dynamic quantization...

Error when loading torch.hub.load('pytorch/fairseq', 'roberta.large.mnli') on AWS EC2

I'm trying to run some code using Torch (and Roberta language model) on an EC2 instance on AWS. The compilation seems to fail, does anyone have a pointer to fix? Confirm that Torch is correctly...

How to merge two torch.utils.data dataloaders with a single operation

I have two dataloaders and I would like to merge them without redefining the datasets, in my case train_dataset and val_dataset. train_loader = DataLoader(train_dataset, batch_size = 512,...

Pip does not recognize torchaudio libary

When i try the command: pip install torchaudio i get this error: ERROR: Could not find a version that satisfies the requirement torchaudio ERROR: No matching distribution found for...

Cannot fix ImportError: cannot import name 'ToTensorV2' from 'albumentations.pytorch' on Colab

I tried all three solutions from this question to solve the problem, but still receive an error: ImportError: cannot import name 'ToTensorV2' from 'albumentations.pytorch'...

Google Colab + Pytorch: RuntimeError: No CUDA GPUs are available

Screenshot of error: Hello, I am trying to run this Pytorch application, which is a CNN for classifying dog and cat pics. I am using Google Colab for the GPU, but for some reason, I get...

Python: tqdm not showing progress bar

I have written the PyTorch code for the fit function of my network. But when I use tqdm in the loop within it, it does not increase from 0% the reason for which I am unable to understand. Here is...

Python: BERT Error - Some weights of the model checkpoint at were not used when initializing BertModel

I am creating an entity extraction model in PyTorch using bert-base-uncased but when I try to run the model I get this error: Error: Some weights of the model checkpoint at...

Unexpected input data type. Actual: (tensor(double)) , expected: (tensor(float))

I am learning this new ONNX framework that allows us to deploy the deep learning (and others) model into production. However, there is one thing I am missing. I thought that the main reason for...

How to run Pytorch on Macbook pro (M1) GPU?

I tried to train a model using PyTorch on my Macbook pro. It uses the new generation apple M1 CPU. However, PyTorch couldn't recognize my GPUs. GPU available: False, used: False TPU available:...

"CUDA out of memory" in PyTorch

I have 16 GB of RAM AND GPU 2060 6 GB trying to run the "transformers gpt2 model" on GPU when I run the code with CPU its work but take a long time (2 - 4) min so I tried to move to GPU but...

Can't install Pytorch in Pycharm terminal, Python 3.10 .win 10

I go to pytorch site and take this pip3 install torch==1.10.0+cu113 torchvision==0.11.1+cu113 torchaudio===0.10.0+cu113 -f https://download.pytorch.org/whl/cu113/torch_stable.html I have windows...

Efficient way to get "neuron-edge-neuron" values in a neural network

I'm working on a visual networks project where I'm trying to plot several node-edge-node values in an interactive graph. I have several neural networks (this is one example): import torch import...