# Tag: torch

## How to perform operations on very big torch tensors without splitting them

My Task: I’m trying to calculate the pair-wise distance between every two samples in two big tensors (for k-Nearest-Neighbours), That is – given tensor test with shape (b1,c,h,w) and tensor train with shape (b2,c,h,w), I need || test[i]-train[j] || for every i,j. (where both test[i] and train[j] have shape (c,h,w), as those are sampes in the batch). The Problem both

## How to understand creating leaf tensors in PyTorch?

From PyTorch documentation: b = torch.rand(10, requires_grad=True).cuda() b.is_leaf False # b was created by the operation that cast a cpu Tensor into a cuda Tensor e = torch.rand(10).cuda()….

## torch.unique does not work for float tensors

I am trying to extract the unique elements from a float tensor. I have tried : out = torch.unique(my_tensor) However this method only works for int/long tensor. My tensor is quantizied tensor in a …

## How to know torch version that installed locally in your device

I want to check torch version in my device using Jupyter Notebook. I’m used this but it didn’t work and Jupyter notebook raised an error as below Is there any command to check torch version using Jupyter notebook? Answer I have tried to install new Pytorch version. But, it didn’t work and then I deleted the Pytorch files manually suggested

## How to convert a PyTorch sparse_coo_tensor into a PyTorch dense tensor?

I create a sparse_coo tensor in PyTorch: import torch # create indices i = torch.tensor([[0, 1, 1], [2, 0, 2]]) # create values v = torch.tensor([3, 4, 5], dtype=torch.float32) # …

## PyTorch: Dataloader for time series task

I have a Pandas dataframe with n rows and k columns loaded into memory. I would like to get batches for a forecasting task where the first training example of a batch should have shape (q, k) with q …

## How does the “view” method work in PyTorch?

I am confused about the method view() in the following code snippet. class Net(nn.Module): def __init__(self): super(Net, self).__init__() self.conv1 = nn.Conv2d(3, 6, 5) …