checking torch + cuda installed correctly
Run this script
.
..
If return 'False' then you need to fix your system.
Thank you.
torch tensor padding example code:
refer to code:
.
..
www.marearts.com
Thank you. 🙇🏻♂️
How to print the full contents of a PyTorch tensor
refer to code:
..
..
In this example, we set the precision to 10 to display up to 10 decimal places, and set threshold, edgeitems, linewidth, and profile to None to display all the elements of the tensor. You can adjust these settings to your preference, depending on the size and precision of your tensor.
Thank you.
www.marearts.com
RuntimeError: CUDA error: CUBLAS_STATUS_INVALID_VALUE when calling `cublasSgemm( handle, opa, opb, m, n, k, &alpha, a, lda, b, ldb, &beta, c, ldc)`
I was suffering above (title) error during few hours.
The reason is wrong cuda version installed with pytorch.
My cuda version is 11.6, but install version is 11.7.
So I print it -> "torch.__version__"
It returend -> "1.13.1+cu117"
You can check your cuda version using this command
> nvidia-smi
so, remove all torch, torchvision packaged
> pip uninstall torch torchvision
and install again
ex)
pip3 install torch torchvision torchaudio --extra-index-url \https://download.pytorch.org/whl/cu116
Then it works well.
Thank you.
🙇🏻♂️
SSLCertVerificationError when downloading pytorch model or datasets via torchvision
I tried to download resnet101 model via torchvision model
ex) torchvision.models.resnet101(pretrained=True)
But it has such a error
---------------------------------------------------------------------------
SSLCertVerificationError Traceback (most recent call last)
F........
This line would solve this issue :..
..
Thank you.
www.marearts.com
'your model' object has no attribute 'seek'. You can only torch.load from a file that is seekable. Please pre-load the data into a buffer like io.BytesIO and try to load from it instead.
I tired to save sub model in seq-to-seq model which is encoder part.
What I used for save and load is like follow code and I failed with error like title.
* Failed case
..
..
* error message
..
My solution is to use 'state_dict()' to save model.
Refer to bellow code which was solution for me.
..
..
Thank you.
www.marearts.com
LSTM Autoencoder pytorch
Code
...
...
Test class and show summary
..
..
output
..
Refer to my ugly drawing
Thank you.
www.marearts.com
time-distributed dense (TDD, TimeDistributed) layer in PyTorch
refer to code:
..
..
Thank you.
www.marearts.com
torch repeat example
Refer to code
..
..
>>
input :torch.Size([100, 140, 5]), repeat:torch.Size([100, 140, 5]) input :torch.Size([100, 140, 5]), repeat:torch.Size([100, 1400, 5]) input :torch.Size([100, 140, 5]), repeat:torch.Size([100, 140, 50]) input :torch.Size([100, 140, 5]), repeat:torch.Size([1000, 140, 5])
Thank you.www.marearts.com
pytorch module list example
ex1)
..
ex2)
..
print module list
>
ModuleList( (0): Linear(in_features=10, out_features=10, bias=True) (1): Linear(in_features=10, out_features=10, bias=True) (2): Linear(in_features=10, out_features=10, bias=True) (3): Linear(in_features=10, out_features=10, bias=True) (4): Linear(in_features=10, out_features=10, bias=True) (5): Linear(in_features=10, out_features=10, bias=True) (6): Linear(in_features=10, out_features=10, bias=True) (7): Linear(in_features=10, out_features=10, bias=True) (8): Linear(in_features=10, out_features=10, bias=True) (9): Linear(in_features=10, out_features=10, bias=True) )
Warning: find_unused_parameters=True was specified in DDP constructor, but did not find any unused parameters. This flag results in an extra traversal of the autograd graph every iteration, which can adversely affect performance
Try #1
..
Try #2
..
Thank you.
skip sanity val check in pytorch lightning
set trainer like this:
list tensor to batch tensor, Pytorch
4 length list tensor -> 4 x 200 x 200 x 3 tensor
--
--
output
--
Thank you.
www.marearts.com
🙇🏻♂️
How to combine multiple criterions to a loss function? Multiple loss function for single model.
You can simply reference below code:
ex1)
b = nn.MSELoss()(output_x, x_labels) a = nn.CrossEntropyLoss()(output_y, y_labels) loss = a + b loss.backward()
ex2)
b = nn.MSELoss() a = nn.CrossEntropyLoss() loss_a = a(output_x, x_labels) loss_b = b(output_y, y_labels) loss = loss_a + loss_b loss.backward()
And there are many opinions in here:
https://discuss.pytorch.org/t/how-to-combine-multiple-criterions-to-a-loss-function/348/27
Thank you.
www.marearts.com
🙇🏻♂️
pytorch cuda definition
Their syntax varies slightly, but they are equivalent:
|
⠀ |
.to(name) |
.to(device) |
.cuda() |
|
CPU |
to('cpu') |
to(torch.device('cpu')) |
cpu() |
|
Current GPU |
to('cuda') |
to(torch.device('cuda')) |
cuda() |
|
Specific GPU |
to('cuda:1') |
to(torch.device('cuda:1')) |
cuda(device=1) |
Note: the current cuda device is 0 by default, but this can be set with torch.cuda.set_device().
check pytorch, Tensorflow can use GPU
test tensorflow which can use GPU
#method 1
import tensorflow as tf
tf.test.is_built_with_cuda()
> Ture
#method 2
from tensorflow.python.client import device_lib
device_lib.list_local_devices()
> ..test pytorch can use GPU
#method 3
import torch
torch.cuda.is_available()
>>> True
torch.cuda.current_device()
>>> 0
torch.cuda.device(0)
>>> <torch.cuda.device at 0x7efce0b03be0>
torch.cuda.device_count()
>>> 1
torch.cuda.get_device_name(0)
>>> 'GeForce GTX 950M'
Thank you.www.MareArts.com
Pytorch, Infinite DataLoader using iter & next
RuntimeError: set_sizes_contiguous is not allowed on Tensor created from .data or .detach(), in Pytorch 1.1.0
change old -> new
old
NEW

