23,883 questions
3
votes
2
answers
57
views
why can't I pass input and target tensors directly to nn.CrossEntropyLoss?
on Python 3.13, torch 2.10.0+cu130
import torch
loss = nn.CrossEntropyLoss()
loss(torch.tensor((.1, .2)), torch.tensor((.3, .4)))
returns -
tensor(0.4811)
but why does
nn.CrossEntropyLoss(torch....
1
vote
0
answers
43
views
Why does BatchNorm1d fail with batch size 1 in training mode?
I am training a small PyTorch model and want to use nn.BatchNorm1d.
When the batch size is 1 and the model is in training mode, I get the error below;
ValueError: Expected more than 1 value per ...
0
votes
0
answers
36
views
Trained and loaded CycleGAN model is giving distorted output images
I trained a CycleGAN model on Google Colab using this repository - https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix
The model should enhance dark images. I tested the model on my test dataset ...
0
votes
0
answers
50
views
GluonTS DeepAREstimator fails to load checkpoint in PyTorch 2.6
I am currently working on a project where I have to use GluonTS (the DeepAREstimator and DLinearEstimator). At the beginning it worked well. But now, even when I use the example code from the GluonTS ...
2
votes
2
answers
51
views
"from torch_geometric.data import Data" throwing an error
If I run a py module with only these imports (no additional code) it works fine and the output is Process finished with exit code 0:
import torch.utils.data
from torch.utils.data.dataloader import ...
0
votes
0
answers
28
views
post training quantized model gets the error "Copying from quantized Tensor to non-quantized Tensor is not allowed" even though I'm not copying tensor
I got a pretrained resnet 18 model from this lane detection repo in order to use it as an ADAS(advanced driver assistance systems) function for an electric car making competition. My current goal is ...
0
votes
0
answers
31
views
How to properly handle LSTM states during training with SliceSampler in TorchRL?
I am implementing a Reinforcement Learning environment using torchrl where the agent uses an LSTM-based policy. My goal is to train the agent on sequences sampled from a replay buffer. While I have ...
0
votes
0
answers
45
views
Why does .view() fail after permuting dimensions for a GRU?
I'm trying to train a character-level GRU on Linux kernel source but the training loop keeps crashing with this error:
RuntimeError: view size is not compatible with input tensor's size and stride (...
1
vote
1
answer
63
views
PyTorch and NVIdia Flare is taking all computing resource on machine learning experiments
I am utilizing PyTorch for federated experiments. As my experiments involves 50 datasets with models, so, I have to run multiple ML models experiments parallelly.
The code for training ML model is ...
0
votes
0
answers
35
views
torch dataloader next-method when using multiple workers
I have a Dataset that is based on IterableDataSet, looking like that
class MyDataSet(torch.utils.data.IterableDataset):
def __init__(self):
# doing init stuff here
def __iter__(self):
...
Advice
2
votes
2
replies
46
views
Why do we use requires_grad=True in the input here?
# Example of target with class indices
loss = nn.CrossEntropyLoss()
input = torch.randn(3, 5, requires_grad=True) <=============== WHY ?
target = torch.empty(3, dtype=torch.long).random_(5)
output =...
6
votes
0
answers
109
views
Docker load fails with wrong diff id calculated on extraction for large CUDA/PyTorch image (Ubuntu 22.04 + CUDA 12.8 + PyTorch 2.8)
About
I am trying to create a Docker image with the same Dockerfile with Python 3.10, CUDA 12.8, and PyTorch 2.8 that is portable between two machines:
Local Machine: NVIDIA RTX 5070 (Blackwell ...
0
votes
0
answers
116
views
Memory access fault by GPU node-1 (Agent handle: 0x26f5dbf0) on address 0x7749d0333000. Reason: Write access to a read-only page
I am currently on a project to segment 3D-LSM images using self-supervised model and i have been trying to perform a dryrun(testing pre-training) on the AMD GPU droplet on digitalocean. the configs of ...
1
vote
1
answer
47
views
Why does PyTorch GPU matmul give correct results without torch.cuda.synchronize()?
I'm learning GPU programming with PyTorch and I'm confused about when torch.cuda.synchronize() is actually necessary.
I have this code that compares CPU and GPU matrix multiplication:
import torch
...
-1
votes
0
answers
27
views
RuntimeError: "element 0 of tensors does not require grad" when using custom autograd function with create_graph=True
I am implementing a custom activation function (a variant of Swish) in PyTorch to optimize memory usage. I implemented it using torch.autograd.Function by defining both the forward and backward static ...