pytorch

ValueError: Expected target size (128, 44), got torch.Size([128, 100]), LSTM Pytorch

醉酒当歌 提交于 2021-02-10 18:34:42
问题 I want to build a model, that predicts next character based on the previous characters. I have spliced text into sequences of integers with length = 100(using dataset and dataloader). Dimensions of my input and target variables are: inputs dimension: (batch_size,sequence length). In my case (128,100) targets dimension: (batch_size,sequence length). In my case (128,100) After forward pass I get dimension of my predictions: (batch_size, sequence_length, vocabulary_size) which is in my case (128

ValueError: Expected target size (128, 44), got torch.Size([128, 100]), LSTM Pytorch

可紊 提交于 2021-02-10 18:31:53
问题 I want to build a model, that predicts next character based on the previous characters. I have spliced text into sequences of integers with length = 100(using dataset and dataloader). Dimensions of my input and target variables are: inputs dimension: (batch_size,sequence length). In my case (128,100) targets dimension: (batch_size,sequence length). In my case (128,100) After forward pass I get dimension of my predictions: (batch_size, sequence_length, vocabulary_size) which is in my case (128

How can I calculate FLOPs and Params without 0 weights neurons affected?

北城以北 提交于 2021-02-10 16:17:00
问题 My Prune code is shown below, after running this, I will get a file named 'pruned_model.pth'. import torch from torch import nn import torch.nn.utils.prune as prune import torch.nn.functional as F from cnn import net ori_model = '/content/drive/My Drive/ECG_weight_prune/checkpoint_dir/model.pth' save_path = '/content/drive/My Drive/ECG_weight_prune/checkpoint_dir/pruned_model.pth' device = torch.device("cuda" if torch.cuda.is_available() else "cpu") model = net().to(device) model.load_state

Add blocks of values to a tensor at specific locations in PyTorch

心不动则不痛 提交于 2021-02-10 14:42:03
问题 I have a list of indices: indx = torch.LongTensor([ [ 0, 2, 0], [ 0, 2, 4], [ 0, 4, 0], [ 0, 10, 14], [ 1, 4, 0], [ 1, 8, 2], [ 1, 12, 0] ]) And I have a tensor of 2x2 blocks: blocks = torch.FloatTensor([ [[1.5818, 2.3108], [2.6742, 3.0024]], [[2.0472, 1.6651], [3.2807, 2.7413]], [[1.5587, 2.1905], [1.9231, 3.5083]], [[1.6007, 2.1426], [2.4802, 3.0610]], [[1.9087, 2.1021], [2.7781, 3.2282]], [[1.5127, 2.6322], [2.4233, 3.6836]], [[1.9645, 2.3831], [2.8675, 3.3770]] ]) What I want to do is to

Add blocks of values to a tensor at specific locations in PyTorch

依然范特西╮ 提交于 2021-02-10 14:38:43
问题 I have a list of indices: indx = torch.LongTensor([ [ 0, 2, 0], [ 0, 2, 4], [ 0, 4, 0], [ 0, 10, 14], [ 1, 4, 0], [ 1, 8, 2], [ 1, 12, 0] ]) And I have a tensor of 2x2 blocks: blocks = torch.FloatTensor([ [[1.5818, 2.3108], [2.6742, 3.0024]], [[2.0472, 1.6651], [3.2807, 2.7413]], [[1.5587, 2.1905], [1.9231, 3.5083]], [[1.6007, 2.1426], [2.4802, 3.0610]], [[1.9087, 2.1021], [2.7781, 3.2282]], [[1.5127, 2.6322], [2.4233, 3.6836]], [[1.9645, 2.3831], [2.8675, 3.3770]] ]) What I want to do is to

How to return intermideate gradients (for non-leaf nodes) in pytorch?

送分小仙女□ 提交于 2021-02-10 14:25:44
问题 My question is concerning the syntax of pytorch register_hook . x = torch.tensor([1.], requires_grad=True) y = x**2 z = 2*y x.register_hook(print) y.register_hook(print) z.backward() outputs: tensor([2.]) tensor([4.]) this snippet simply prints the gradient of z w.r.t x and y , respectively. Now my (most likely trivial) question is how to return the intermediate gradients (rather than only printing)? UPDATE: It appears that calling retain_grad() solves the issue for leaf nodes. ex. y.retain

Error converting Pegasus to the ONNX format from Transformers

◇◆丶佛笑我妖孽 提交于 2021-02-10 14:21:55
问题 I am trying to convert the Pegasus newsroom in HuggingFace's transformers model to the ONNX format. I followed this guide published by Huggingface. After installing the prereqs, I ran this code: !rm -rf onnx/ from pathlib import Path from transformers.convert_graph_to_onnx import convert convert(framework="pt", model="google/pegasus-newsroom", output=Path("onnx/google/pegasus-newsroom.onnx"), opset=11) and got these errors: ValueError Traceback (most recent call last) <ipython-input-9

PyTorch having trouble detecting CUDA

我怕爱的太早我们不能终老 提交于 2021-02-10 07:47:08
问题 I am running CNN on PyTorch. The torch.cuda.is_available() function returned false and no GPU is detected. However, I can run Keras model with GPU. Here is my system information: OS: Ubuntu 18.04.3 Python 3.7.3 (Conda) GPU: GTX1080Ti Nvidia driver: 430.50 When I check nvidia-smi, the output said that the CUDA version is 10.1. However, the nvcc -V command tells me that it is CUDA 9.1. I downloaded NVIDIA-Linux-x86_64-430.50.run from the official site and install it with command line. I

PyTorch get indices of value in two-dimensional tensor

可紊 提交于 2021-02-10 05:29:05
问题 Given the following tensor (or any random tensor with two dimension), I want to get the index of '101': tens = tensor([[ 101, 146, 1176, 21806, 1116, 1105, 18621, 119, 102, 0, 0, 0, 0], [ 101, 1192, 1132, 1136, 1184, 146, 1354, 1128, 1127, 117, 1463, 119, 102], [ 101, 6816, 1905, 1132, 14918, 119, 102, 0, 0, 0, 0, 0, 0]]) From the related answers I know that I can do something like this: idxs = torch.tensor([(i == 101).nonzero() for i in tens]) But this seems messy and potentially quite slow.

Filter out np.nan values from pytorch 1d tensor

旧巷老猫 提交于 2021-02-10 05:15:17
问题 I have a 1d tensor looking kinda like this: import numpy as np import torch my_list = [0, 1, 2, np.nan, np.nan, 4] tensor = torch.Tensor(my_list) How do i filter out the nan-values, so it becomes a tensor of size 4? 回答1: You can use torch.isnan my_list = [0, 1, 2, np.nan, np.nan, 4] tensor = torch.Tensor(my_list) tensor[~torch.isnan(tensor)] tensor([0., 1., 2., 4.]) 来源: https://stackoverflow.com/questions/61503138/filter-out-np-nan-values-from-pytorch-1d-tensor