akankshakshurai/cuda-error-resolution-analysis huggingface dataset:
RuntimeError: input.size(-1) must be equal to input_size. 3DCNN+GRU

username: talhaanwarch
cooked: <p>Hi. I am passing an input of shape <code>torch.Size([6, 8, 3, 16, 120, 120])</code> to 3D CNN + GRU architecture<br>
. I have trained model with shape <code>torch.Size([4, 8, 3, 16, 120, 120])</code> What i think the first index is a batch size and it can be variable. But i am not sure why changing it is throwing error.</p>
<p>This is my forward function. I am using batch first in GRU layer</p>
<pre><code class="lang-auto">x=x.reshape(-1,*x.shape[2::])
x=self.video_model(x.float())
x=x.reshape(4,-1,x.shape[1])
x,x1=self.gru(x.permute(0,2,1))
</code></pre>
What is k in kFloat, kInt, kUint?

username: Dorozhko-Anton
cooked: <p>What does the k prefix stands for in many libtorch types ?<br>
<a href="https://pytorch.org/cppdocs/api/file_torch_csrc_api_include_torch_types.h.html#file-torch-csrc-api-include-torch-types-h" class="onebox" target="_blank" rel="nofollow noopener">https://pytorch.org/cppdocs/api/file_torch_csrc_api_include_torch_types.h.html#file-torch-csrc-api-include-torch-types-h</a></p>

username: tom
cooked: <p>It’s pure speculation, but my take is that it could be “konstant” in <a href="https://en.wikipedia.org/wiki/Hungarian_notation" rel="nofollow noopener">Hungarian Notation</a>.<br>
I think these came with ATen, but <a class="mention" href="/u/zdevito">@zdevito</a> would know know a lot more than me.</p>
<p>Best regards</p>
<p>Thomas</p>

username: indigoviolet
cooked: <p>I have a sort of n00b question related to this: <code>at::kLong</code>, <code>at::kFloat</code> etc don’t appear to be defined anywhere in the pytorch codebase.</p>
<p>I’m guessing this is because they get defined according to your system somehow at build time, but I’d love a pointer to where this definition is created, and what I need to do to see this definition for my system.</p>

username: indigoviolet
cooked: <p>Answering my own question: these constants are defined via a macro here: <a href="https://github.com/pytorch/pytorch/blob/71f9e99e293d0eff8da665b69543d044a6a4454d/c10/core/ScalarType.h#L177-L181" class="inline-onebox" rel="noopener nofollow ugc">pytorch/ScalarType.h at 71f9e99e293d0eff8da665b69543d044a6a4454d · pytorch/pytorch · GitHub</a></p>

username: Essence
cooked: <p>I’ve been confused by kInt all the day, thank you very much! <img src="https://discuss.pytorch.org/images/emoji/apple/smiling_face_with_three_hearts.png?v=12" title=":smiling_face_with_three_hearts:" class="emoji" alt=":smiling_face_with_three_hearts:" loading="lazy" width="20" height="20"></p>
Custom Vulkan / GLSL Extension tutorial

username: tvercaut
cooked: <p>Hi,</p>
<p>I have seen the “Custom C++ and CUDA Extensions” tutorial here:<br>
<a href="https://pytorch.org/tutorials/advanced/cpp_extension.html" class="onebox" target="_blank" rel="noopener nofollow ugc">https://pytorch.org/tutorials/advanced/cpp_extension.html</a></p>
<p>However, it doesn’t cover Vulkan / GLSL yet. Is expanding the tutorial for Vulkan / GLSL planned?</p>
<p>In the meantime, would anyone have pointers on how to best do extend PyTorch with a GLSL shader similar to those already in the main repo (<a href="https://github.com/pytorch/pytorch/tree/master/aten/src/ATen/native/vulkan/glsl" class="inline-onebox" rel="noopener nofollow ugc">pytorch/aten/src/ATen/native/vulkan/glsl at master · pytorch/pytorch · GitHub</a>)?</p>
<p>Many thanks,<br>
Tom</p>
How to install torch_tensorrt in ubuntu?

username: iamexperimentingnow
cooked: <p><a class="mention" href="/u/ptrblck">@ptrblck</a>  could you please help me here, I’m trying to install torch_tensorrt python package in ubuntu 20.04</p>
<p>I used the below command to install the package<br>
<code>pip3 install torch-tensorrt -f https://github.com/NVIDIA/Torch-TensorRT/releases</code></p>
<p>when I try to import the torch_tensorrt module,<br>
<code> import torch_tensorrt</code></p>
<h4>
<a name="error-1" class="anchor" href="#error-1"></a>Error</h4>
<p>ImportError: libnvinfer_plugin.so.8: cannot open shared object file: No such file or directory</p>
<h3>
<a name="system-details-2" class="anchor" href="#system-details-2"></a>system details</h3>
<p>PyTorch Version (e.g., 1.0): 1.11.0<br>
OS (e.g., Linux): LINUX<br>
How you installed PyTorch (conda, pip, libtorch, source): conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch<br>
Python version: 3.7.13<br>
CUDA version: 11.3.1</p>

username: iamexperimentingnow
cooked: <p>I have fixed this hence we can consider this as closed.</p>

username: anhdungitvn
cooked: <p><a class="mention" href="/u/iamexperimentingnow">@iamexperimentingnow</a> Hi, how could you fix this error?<br>
I got the same.</p>

username: iamexperimentingnow
cooked: <p>its still not working for me, I will fix and share you  the steps.</p>

username: narendasan
cooked: <p>For future notice, this error is caused by the TensorRT shared objects not being in the system LD_LIBRARY_PATH</p>

username: IncrediBlame
cooked: <p>I also had those missing libraries problem with <code>torch-tensorrt</code>: <code>libtorch_cuda_cu.so</code>, <code>libcudart.so.11.0</code>, <code>libnvinfer.so.8</code>, etc…</p>
<p>Turns out when you<br>
<code>pip install torch-tensorrt==1.2.0 --find-links https://github.com/pytorch/TensorRT/releases/expanded_assets/v1.2.0</code><br>
it pulls its preferred version of <code>torch</code> in, in my case it was <code>1.12.1</code>, but it installed the old version of Cuda, namely <code>1.12.1+cu102</code>, when it actually needs Cuda 11.0+.</p>
<p>So  what i did is:<br>
<code>pip install torch==1.12.1+cu113 torchvision==0.13.1+cu113 torchaudio==0.12.1 --extra-index-url https://download.pytorch.org/whl/cu113</code><br>
<code>pip install nvidia-pyindex</code><br>
<code>pip install nvidia-tensorrt</code><br>
<code>pip install torch-tensorrt==1.2.0 --find-links https://github.com/pytorch/TensorRT/releases/expanded_assets/v1.2.0</code><br>
and the errors stopped.</p>
Other inputs into a conv2d layer

username: Omroth
cooked: <p>I have some input data that’s the same for every pixel of my input image, and I want the Conv2D layer to have access to it.  Does it have to be in a channel, where that channel is the same value for every pixel?  Or is there another approach?</p>

username: Andrei_Cristea
cooked: <p>Depending on the model, I would guess that you can pass the uniform input directly to your fully connected layer (after all the convolutions). It feels like it’s probably overkill to broadcast it out to the size of the entire input.</p>
<p>How you encode that input isn’t obvious, but you can start with just a Linear layer that connects the input value to the same fully connected layer that the convolutions connect to.</p>

username: Omroth
cooked: <p>Thanks for the help.</p>
<p>The issue is that there isn’t a fully connected layer - the output is an image.</p>
Looking for a practical example of making KFP app using torchx

username: helloybz
cooked: <p>Hi.</p>
<p>Where can I find a good practical example of building KubeFlow Pipeline app using torchx?</p>
<p>I’ve been through the documents for torchx, and now I get how torchx work.<br>
However, I have no idea how to design my app with torchx.</p>
<hr>
<p>I’ve already developed my pytorch app to support functions below:</p>
<ul>
<li>Fetch data from Feature store</li>
<li>EDA for the fetched data</li>
<li>Preprocessing the fetched data</li>
<li>Training model</li>
<li>Validate model</li>
</ul>
<p>And, the each function has its own CLI, such as</p>
<pre><code class="lang-auto">my_app load_data --feature_store_root [URI]  --local_storage_root [URI]...
my_app run_eda --local_storage_root [URI] ...
my_app train ...
...
</code></pre>
<hr>
<p>Now, I want to write torchx components of the each function above.</p>
<p>Is it enough to put <code>pipeline.py</code> under the project root directory and write all the torchx things in it?</p>
Building pytorch/vision on Windows

username: Titus
cooked: <p>Hello,<br>
I’m currently trying to build pytorch/visions on windows. I’ve given libtorch to cmake with the parameter<br>
<code>-DCMAKE_PREFIX_PATH="D:/libs/1.10/libtorch_cu102_release"</code>.<br>
Then using this command <code>cmake --build . --target install --config release</code><br>
I’m having the following warning and error.</p>
<pre><code class="lang-auto">D:/libs/vision/torchvision/csrc/ops/cuda/deform_conv2d_kernel.cu(73): fatal error C1083: Cannot open include file: 'ATen/cuda/Atomic.cuh': No such file or directory [D:\libs\vision\build\torchvision.vcxproj]
CUDACOMPILE : nvcc warning : The -std=c++14 flag is not supported with the configured host compiler. Flag will be ignored. [D:\libs\vision\build\torchvision.vcxproj]
</code></pre>
<p>What am I missing ? Indeed I can’t find the file <code>'ATen/cuda/Atomic.cuh'</code> in the libtorch archive that I’ve downloaded.</p>
<p>My generator is “Visual Studio 2019”<br>
I’m using libtorch-win-shared-with-deps-1.10.1%2Bcu102.zip</p>
<p>Thanks for your help</p>

username: CommanderLake
cooked: <p>Did you ever figure this out? I found the Atomic.cuh file in the ATen source in the pytorch github repository but when I put the file in place it just uncovered lots more errors when compiling vision.</p>
Loss always returns zero

username: nwe_lay
cooked: <p>when I implementing multiple instance learning, zeros were got in all epoch. Why?. Please Help me for the network</p>
<p>'&gt; class MILModule(nn.Module):</p>
<blockquote>
<pre><code>def __init__(self):
    super(MILModule,self).__init__()
    vgg=models.vgg16(pretrained=True)
    modules=list(vgg.features[i] for i in range(29))
    self.vgg=nn.Sequential(*modules)
    self.relu1=nn.ReLU()
    self.conv1=nn.Conv2d(in_channels=512,out_channels=4096,kernel_size=5)
    self.relu2=nn.ReLU()
    self.conv2=nn.Conv2d(in_channels=4096,out_channels=4096,kernel_size=3)
    self.relu0=nn.ReLU()
    self.conv3=nn.Conv2d(in_channels=4096,out_channels=1000,kernel_size=1)
    self.sigmoid=nn.Sigmoid()
    self.pool_mil=nn.MaxPool2d(8,stride=1)
def forward(self,images):
    features=self.vgg(images)
    N,C,H,W=features.size()
    relu0=self.relu0(features)
    conv1=self.conv1(relu0)
    relu1=self.relu1(conv1)
    conv2=self.conv2(relu1)
    relu2=self.relu2(conv2)
    conv3=self.conv3(relu2)
    pool=self.pool_mil(conv3)
    x=pool.squeeze(2).squeeze(2)
    x=self.sigmoid(x)
    return x
</code></pre>
</blockquote>
Find positive values in a given dimension without using torch.where()

username: Prakhar_Pradhan1
cooked: <p>Hi Everyone,<br>
I do not want to use torch.where() and still wants to find the positive values in a tensor in a given dimension,<br>
example, x = torch.randn(3,288), then I want to find the sum of positive values along the dimension 1. Note than x[x&gt;0] will not be helpful because it will create an 1-d tensor.</p>
<p>Thanks in advance</p>

username: KFrank
cooked: <p>Hi Prakhar!</p>
<aside class="quote no-group" data-username="Prakhar_Pradhan1" data-post="1" data-topic="164972" data-full="true">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/prakhar_pradhan1/48/53366_2.png" class="avatar"> Prakhar_Pradhan1:</div>
<blockquote>
<p>example, x = torch.randn(3,288), then I want to find the sum of positive values along the dimension 1.</p>
</blockquote>
</aside>
<p>In this particular instance, <code>max()</code> suffices.</p>
<aside class="quote no-group">
<blockquote>
<p>Note than x[x&gt;0] will not be helpful because it will create an 1-d tensor.</p>
</blockquote>
</aside>
<p>More generally, you can still use a condition such as <code>x &gt; 0</code>, but just use<br>
it as a numerical mask, rather than an index.</p>
<p>Consider:</p>
<pre><code class="lang-plaintext">&gt;&gt;&gt; import torch
&gt;&gt;&gt; torch.__version__
'1.12.0'
&gt;&gt;&gt; _ = torch.manual_seed (2022)
&gt;&gt;&gt;
&gt;&gt;&gt; x = torch.randn (3, 288)
&gt;&gt;&gt; torch.max (x, torch.tensor ([0.0])).sum (dim = 1)
tensor([118.9255, 116.4891, 128.0370])
&gt;&gt;&gt;
&gt;&gt;&gt; mask = x &gt; 0.0   # boolean mask, but can be used numerically
&gt;&gt;&gt; (mask * x).sum (dim = 1)
tensor([118.9255, 116.4891, 128.0370])
&gt;&gt;&gt;
&gt;&gt;&gt; (mask * x).sum (dim = 1) / mask.sum (dim = 1)   # mean of positive elements
tensor([0.8202, 0.8381, 0.8053])
</code></pre>
<p>Best.</p>
<p>K. Frank</p>

username: Prakhar_Pradhan1
cooked: <aside class="quote no-group" data-username="KFrank" data-post="2" data-topic="164972">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/k/ecb155/48.png" class="avatar"> KFrank:</div>
<blockquote>
<p><code>(mask * x).sum (dim = 1)</code></p>
</blockquote>
</aside>
<p>Thank you so much, it will be of great help</p>
Need to detect multiple sub categories in character strings

username: Richard_Jenkins
cooked: <p>I am asking in vision category because it’s object recognition I’m after.</p>
<p>I am using a character based CNN for categorizing data strings. Inside those strings are sub-segments that I want to categorize, or recognize. I see it like the 2d object recognition in RCNN or SDD. They put bounding boxes around multiple objects in an image. That’s what I want to do: underline or tag substrings and identify their categories.</p>
<p>I also think my problem is analogous to 1d data like ECG data with the pqrst parts of the heart beat. Many of the ECG algorithms talk about identifying the unusual heartbeat but I haven’t found examples of putting boxes around the sub segment parts of the heartbeat (pqrst parts).</p>
<p>Anyone have any tips or direction to suggest on how I can change my conv1d character based CNN into a conv1d R-CNN or SDD.</p>
Datasets, losses, and squeeze()

username: badger
cooked: <p>I’ve been making datasets for some time and I always seem to run into the same problem–whenever its time for a loss function I have to use the .squeeze() method on my targets.  It seems like I am doing something wrong in setting up my tensors.  Yes I can get it to work, but it seems I am doing something subtley wrong.</p>
<p>example code:</p>
<pre><code class="lang-auto">from torch.utils.data import Dataset
## just a toy example, this happens even for pictures/classification/seg
class DataFrameDataset(Dataset):
    def __init__(self, X_dataFrame, y_dataFrame):
        self.X = X_dataFrame
        self.y = y_dataFrame

    def __len__(self):
        return self.X.shape[0]

    def __getitem__(self, idx):
        inputs = torch.tensor(self.X.iloc[idx,:]).float()
        targets = torch.tensor(self.y.iloc[idx]).long()
        return inputs, targets
</code></pre>
<p>Now any model I run (I was doing an Iris dataset example for class) for a loss I need to do the following:</p>
<pre><code class="lang-auto">y_hat = model(x_batch)
loss = nn.functional.cross_entropy(y_hat, y_batch.squeeze())
</code></pre>
<p>I know the .squeeze() is just changing my (batch x 1) dimesnional targets into a (batch) dimension of targets, but it seems I missed something in the dataset/dataloaders to do this “natively” with just a loss = nn.functional.cross_entropy(y_hat, y_batch)</p>

username: ptrblck
cooked: <p>Your code looks generally alright and I guess your <code>y_dataFrame[idx]</code> might return a 2D tensor, which you then transform to a PyTorch tensor. If so, just keep the <code>.squeeze(1)</code> to remove the unneeded dimension.</p>
How to implement the most efficient convolution

username: anguoyang
cooked: <p>The result of stylegan(<a href="https://en.wikipedia.org/wiki/StyleGAN" class="inline-onebox" rel="noopener nofollow ugc">StyleGAN - Wikipedia</a>) is amazing, but the huge input/output channels(1024, 512, etc) make the convolution heavy and slow, how could we implement lightweight convolutions to slim the model? any advices are welcome, thank you.</p>
<p>Btw, there are some mobile/lightweight open sources, like MobileStyleGAN, anycost-gan, etc, but almost all these approaches are trying to decrease the channels, but unfortunately, this will also decrease the image quality, I just wonder if we could make a super lightweight convolution without decreasing the channels but still maintain similar results with StyleGAN.</p>
Two Head Yolov5

username: Pipu_Jain
cooked: <p>Hello,</p>
<p>I am pretty new to Yolo models and would really appreciate any kind of help.<br>
So I am trying to create a double head yolov5 model, one for detection and other for classification. I have developed a class for the two headed model. but I am facing a lot of issues, kindly let me know how I could improve it and make a trainable model.</p>
<pre><code class="lang-auto">class TwoHead(nn.Module):
    def __init__(self, model, ncc = 3):
        super(TwoHead, self).__init__()
        self.base_model = deepcopy(model)
        self.base_model.model = self.base_model.model[:8]
        self.detect_head = deepcopy(model)
        self.detect_head.model = self.detect_head.model[8:]
        self.classification_head = deepcopy(model)
        self.classification_head.model = self.classification_head.model[7]
        m = self.classification_head.model[-1]  # last layer
        ch = m.conv.in_channels if hasattr(m, 'conv') else sum([x.in_channels for x in m.m])  # ch into module
        c = Classify(ch, ncc)  # Classify()
        c.i, c.f, c.type = m.i, m.f, 'models.common.Classify'  # index, from, type
        self.classification_head.model[-1] = c  # replace
       
    def forward(self, x):
        x = self.base_model(x)
        out1 = self.detect_head(x)
        out2 = self.classification_head(x)
        return out1, out2


twomodel = TwoHead(model)   #Yolov5 model with pretrained weights
...
...
...
...
for imgs, targets, classification_targets in pbar:
                pred, pred2 = twomodel(imgs)  # forward
                loss, loss_items = compute_loss(pred, targets.to(device))  # loss scaled by batch_size
                loss2 = criterion(pred2, classification_target)
</code></pre>
<p>Error that I face is</p>
<pre><code class="lang-auto">Traceback (most recent call last):
  File "/home/pipu/yolov5/twohead.py", line 664, in &lt;module&gt;
    main(opt)
  File "/home/pipu/yolov5/twohead.py", line 558, in main
    train(opt.hyp, opt, device, callbacks)
  File "/home/pipu/yolov5/twohead.py", line 337, in train
    pred, pred2 = twomodel(imgs)  # forward
  File "/home/piyush/miniconda3/lib/python3.9/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/home/pipu/yolov5/twohead.py", line 86, in forward
    out1 = self.detect_head(x)
  File "/home/piyush/miniconda3/lib/python3.9/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/home/pipu/yolov5/models/yolo.py", line 211, in forward
    return self._forward_once(x, profile, visualize)  # single-scale inference, train
  File "/home/pipu/yolov5/models/yolo.py", line 120, in _forward_once
    x = y[m.f] if isinstance(m.f, int) else [x if j == -1 else y[j] for j in m.f]  # from earlier layers
  File "/home/pipu/yolov5/models/yolo.py", line 120, in &lt;listcomp&gt;
    x = y[m.f] if isinstance(m.f, int) else [x if j == -1 else y[j] for j in m.f]  # from earlier layers
IndexError: list index out of range
</code></pre>
Unsupervised minimization with SGD

username: Eli1
cooked: <p>Hello everyone, I am trying to implement a minimization problem using SGD.<br>
In particular, I have an objective function (or loss) that looks like this:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/c/f/cf6c09d99f12e7cc1502eee9c4350ecb61fb383d.png" data-download-href="https://discuss.pytorch.org/uploads/default/cf6c09d99f12e7cc1502eee9c4350ecb61fb383d" title="image"><img src="https://discuss.pytorch.org/uploads/default/original/3X/c/f/cf6c09d99f12e7cc1502eee9c4350ecb61fb383d.png" alt="image" data-base62-sha1="tAWj4ZXe3u7OySxVky5kW0IOCAZ" width="690" height="112" data-dominant-color="F6F6F6"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">695×113 4.42 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div><br>
where q_theta is parametrized by a fully connected NN and has the form:</p>
<pre><code class="lang-auto">def objective(p, output):
  x,y = p
  a = minA
  b = minB
  r = 0.1

  XA = 1/2 -1/2 * torch.tanh(100*((x - a[0])**2 + (y - a[1])**2 - (r + 0.02)**2))
  XB = 1/2 -1/2 * torch.tanh(100*((x - b[0])**2 + (y - b[1])**2 - (r + 0.02)**2))
  q = (1-XA)*((1-XB)* output - (XB))
  return q
</code></pre>
<p>“output” is the output of the NN, namely the only part of this function that is parametrized.</p>
<p>Now, my training function looks like this:</p>
<pre><code class="lang-auto">optimizer = optim.SGD(model.parameters(), lr=learning_rate)

for e in range(epochs) :
  for configuration in total:
    # for each point in the array of independently sampled points 
    optimizer.zero_grad()

    #output is q~
    output = model(configuration)

    #loss is the objective function we defined
    #in the paper, objective function is 18

    loss = objective(configuration, output).backward()
    optimizer.step()
</code></pre>
<p>Where my model is a simple two-layer fully connected NN, with an input layer equal to 2 (x,y) and one output node corresponding to the parametrized part of the function.<br>
Note that each “configuration” is a point in a 2D space, which is sampled independently from a distribution to perform the sample average, which approximates the expectation in (18).</p>
<p>However, the resulting minimized function does not make any sense. In particular, I am not sure I am handling the objective function correctly. Is .backward() substituting the gradient in (18) or should I compute the gradient with autograd?</p>
Torch.cat Sizes of tensors must match except in dimension 2. Got 400 and 100 (The offending index is 0)

username: Topsoil
cooked: <p>I have two tensors, one is shaped (1,1,100) and another (1,1,400)</p>
<p>inside <code>forward()</code> method of my model they get <code>.cat()</code> together, but for some reason it throws this error:</p>
<p>Sizes of tensors must match except in dimension 2. Got 400 and 100 (The offending index is 0)</p>
<p>What is the reason???</p>
<p>Code:</p>
<pre><code class="lang-auto">def forward(self, cond, hidden,state):
    '''
    Cond shape: (batch,1,100)

    hidden and state shape: (batch,1,400)
    '''
    cond = torch.cat((cond,hidden),1) #Error is here
    . . .
</code></pre>

username: Topsoil
cooked: <p>Fixed itself, change 1 to 2 in <code>torch.cat()</code></p>
Weird matmul() behavior

username: vince62s
cooked: <p>Can someone explain why this in the code below ?<br>
as is with slen=24, dim=8, I have out=out2</p>
<p>if I change slen to 25 or more, or dim to 9 or more, then it does not work, out and out2 are not equal.<br>
can’t get why.</p>
<p>import torch<br>
import time</p>
<p>def tile(x, count):<br>
“”"<br>
Tiles x on dimension 0 count times.<br>
“”"<br>
out_size = list(x.size())<br>
out_size[0] *= count<br>
batch = x.size(0)<br>
x = x.view(batch, -1) <br>
.transpose(0, 1) <br>
.repeat(count, 1) <br>
.transpose(0, 1) <br>
.contiguous() <br>
.view(*out_size)<br>
return x</p>
<p>batch_size = 16<br>
beam_size = 2</p>
<p>slen = 24<br>
dim = 8</p>
<p>enc_out = torch.randn(batch_size, slen, dim)<br>
dec_in = torch.randn(batch_size * beam_size, 1, dim)</p>
<p>tiled_enc = tile(enc_out, beam_size)</p>
<h1>
<a name="regular-matmul-1" class="anchor" href="#regular-matmul-1"></a>regular matmul</h1>
<p>out = torch.matmul(dec_in, tiled_enc.transpose(2, 1))</p>
<h1>
<a name="beamed-matmul-2" class="anchor" href="#beamed-matmul-2"></a>beamed matmul</h1>
<p>inp1 = dec_in[:, 0, :].unfold(0, beam_size, beam_size).transpose(2, 1)<br>
inp2 = tiled_enc.unfold(0, beam_size, beam_size)[:, :, :, 0]<br>
out2 = torch.matmul(inp1, inp2.transpose(2,1))<br>
out2 = out2.view(batch_size*beam_size, 1, -1)</p>
<p>print(torch.equal(out, out2))</p>

username: ptrblck
cooked: <p>Using <code>torch.equal</code> with floating point numbers is not a good idea due to the limited floating point precision and the expected small errors caused by a different order or operations.<br>
If I change <code>slen</code> to 25 and <code>dim</code> to 9 I see an <code>.abs().max()</code> error of <code>tensor(9.5367e-07)</code> which is expected for <code>float32</code>.</p>

username: vince62s
cooked: <p>real life settings batch 16, beam 5, slen61, dim 512 gives me 1.5e-5 which is still ok.</p>
<p>many thanks.</p>
Pruning increases inference time for detectron2 model

username: ajktym94
cooked: <p>I have pruned a detectron2 model for 20%, 40%, 60% and 80% of the weights.<br>
However, while checking the measuring the inference time for such a model, it’s performing inconsistently and surprisingly, the model with 80% weights pruned is taking more time than an unpruned model.</p>
<p>This is surprising because I had pruned a Resnet101 model previously and the inference time decreased consistently.</p>
<p>Note: The pruning parameters have been removed using prune.remove()</p>
Creating A Dataset from keras train_test_split

username: d3tk
cooked: <p>I have a dataset of images and then a continuous value. I’m using a CNN model to predict that value. There are 14,000 images and 14,000 values. I know in Keras I can use <code>train_test_split</code> to get X_train, y_train, X_test, and y_test then would use <code>model.fit()</code></p>
<p>but to train my model in pytorch, do I combine X_train and y_train into a dataset and use a DataLoader or is there another way? ie not using keras <code>train_test_split</code></p>
<p>My code so far:<br>
The images are 360x360 and grayscaled so the input shape is (1,360,360)</p>
<pre><code class="lang-auto">X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.33, random_state=42)

X_train.shape is  torch.Size([9814, 360, 360, 1])
y_train.shape is torch.Size([9814, 1])
X_test.shape is torch.Size([4834, 360, 360, 1])
y_test.shape is torch.Size([4834, 1])

training_set = torch.hstack((X_train,y_train))
validation_set = torch.hstack((X_test, y_test))

training_loader = torch.utils.data.DataLoader(training_set, batch_size=64, shuffle=True, num_workers=2)

validation_loader = torch.utils.data.DataLoader(validation_set, batch_size=64, shuffle=False, num_workers=2)
</code></pre>
<p>Thank you in advance!</p>

username: nivek
cooked: <p>Typically, users create a <a href="https://pytorch.org/tutorials/beginner/basics/data_tutorial.html" rel="noopener nofollow ugc"><code>Dataset</code></a> object then use <a href="https://pytorch.org/docs/stable/data.html#torch.utils.data.random_split" rel="noopener nofollow ugc"><code>random_split</code></a> to split into train/test sets.</p>
<p>Here’s an additional <a href="https://pytorch.org/tutorials/beginner/data_loading_tutorial.html" rel="noopener nofollow ugc">tutorial</a> that you may find helpful.</p>
Use model.cuda() in multprocessing.Process on windows platform

username: li-haoran
cooked: <pre><code class="lang-auto">import torchvision.models as Model
import torchvision.transforms as TT
import torch.multiprocessing as mp

class baseProcess:
    max_size=128
    def __init__(self,data_root) -&gt; None:
        self.Q=mp.Queue(maxsize=self.max_size)
        self.model=Model.resnet18(True)
        self.model.eval()
        self.image_loader=image_loader
        self.transform = TT.Compose([                           
                                TT.Resize(224),
                                TT.CenterCrop(224),
                                TT.ToTensor(),
                                TT.Normalize(
                                    mean=[0.485, 0.456, 0.406],
                                    std=[0.229, 0.224, 0.225])])

    def update(self):

        for i in range(self.image_loader.length()):
            img,file_name=self.image_loader.getitem()
            data=self.transform(img)
            data=torch.unsqueeze(data,0)
            with torch.no_grad():
                output=self.model(data)
                output=torch.softmax(output,dim=-1)              
                v,id=output[0].topk(1)
                name=id2name[id.item()]
                # print(name,v)

            while self.Q.full():
                time.sleep(2)
            self.Q.put((img, name))
    def start(self):
        p = mp.Process(target=self.update, args=())
        p.daemon = True
        p.start()
        return self

</code></pre>
<p>when I just use the model on CPU, the output is fine.<br>
when I use self.model.cuda(), the output is always zeros on windows platform, but it is fine on linux platform.</p>
NN Model summary

username: yviiendaleee
cooked: <p>I created a NN model in PyTorch.<br>
This is my model summary:</p>
<h2>
<a name="training-time-293956-1" class="anchor" href="#training-time-293956-1"></a>Training time: 2939.56</h2>
<pre><code>    Layer (type)               Output Shape         Param #
</code></pre>
<h1>
<a name="linear-1-1-1-10-10-30-tanh-2-1-1-10-10-0-linear-3-1-1-10-10-110-tanh-4-1-1-10-10-0-linear-5-1-1-10-10-110-tanh-6-1-1-10-10-0-linear-7-1-1-10-10-110-tanh-8-1-1-10-10-0-linear-9-1-1-10-1-11-2" class="anchor" href="#linear-1-1-1-10-10-30-tanh-2-1-1-10-10-0-linear-3-1-1-10-10-110-tanh-4-1-1-10-10-0-linear-5-1-1-10-10-110-tanh-6-1-1-10-10-0-linear-7-1-1-10-10-110-tanh-8-1-1-10-10-0-linear-9-1-1-10-1-11-2"></a>================================================================<br>
Linear-1            [-1, 1, 10, 10]              30<br>
Tanh-2            [-1, 1, 10, 10]               0<br>
Linear-3            [-1, 1, 10, 10]             110<br>
Tanh-4            [-1, 1, 10, 10]               0<br>
Linear-5            [-1, 1, 10, 10]             110<br>
Tanh-6            [-1, 1, 10, 10]               0<br>
Linear-7            [-1, 1, 10, 10]             110<br>
Tanh-8            [-1, 1, 10, 10]               0<br>
Linear-9             [-1, 1, 10, 1]              11</h1>
<h2>
<a name="total-params-371-trainable-params-371-non-trainable-params-0-3" class="anchor" href="#total-params-371-trainable-params-371-non-trainable-params-0-3"></a>Total params: 371<br>
Trainable params: 371<br>
Non-trainable params: 0</h2>
<h2>
<a name="input-size-mb-000-forwardbackward-pass-size-mb-001-params-size-mb-000-estimated-total-size-mb-001-4" class="anchor" href="#input-size-mb-000-forwardbackward-pass-size-mb-001-params-size-mb-000-estimated-total-size-mb-001-4"></a>Input size (MB): 0.00<br>
Forward/backward pass size (MB): 0.01<br>
Params size (MB): 0.00<br>
Estimated Total Size (MB): 0.01</h2>
<p>But what does this mean? What does it tell me? How can I interpret it?<br>
Thanks guys <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=12" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p>
Fill diagonal of matrix with zero

username: AreTor
cooked: <p>I have a very large n x n <code>tensor</code> and I want to fill its diagonal values to zero, granting backwardness. How can it be done? Currently the solution I have in mind is this</p>
<pre><code class="lang-auto">t1 = torch.rand(n, n)
t1 = t1 * (torch.ones(n, n) - torch.eye(n, n))
</code></pre>
<p>However if n is large this can potentially require a lot of memory. Is there a simpler differentiable solution, perhaps similar to NumPy <code>np.fill_diagonal</code> function?</p>

username: vmirly1
cooked: <pre><code class="lang-python">&gt;&gt;&gt; t = torch.randn(5, 5)
&gt;&gt;&gt; ind = np.diag_indices(t.shape[0])
&gt;&gt;&gt; t[ind[0], ind[1]] = torch.zeros(t.shape[0])
&gt;&gt;&gt; t
tensor([[ 0.0000, -1.2111,  2.0369, -0.7607,  0.1844],
        [ 1.2293,  0.0000, -1.0472, -0.5150,  0.1518],
        [ 0.1972, -0.3708,  0.0000, -1.2243,  0.1612],
        [-0.1637, -1.2848, -0.1972,  0.0000,  1.3353],
        [ 1.1711,  0.9332,  0.0911, -0.3391,  0.0000]])
</code></pre>

username: Sunshine352
cooked: <p>replace op is non-differential</p>

username: Sunshine352
cooked: <p>t1 = torch.rand(n, n)<br>
t1 = t1 * (1 - torch.eye(n, n))<br>
so what ?</p>

username: vmirly1
cooked: <p>yeah, but replacing them with a constant (zero), the gradients will stay zero, I suppose, isn’t that true?</p>

username: Sunshine352
cooked: <p>another solution:<br>
t = torch.randn(n, n)<br>
mask = torch.eye(n, n).byte()<br>
t.masked_fill_(mask, 0)</p>

username: Sunshine352
cooked: <p>You may code a simple net, and backward to observe gradients</p>

username: redtailedhawk
cooked: <p>There’s an easier solution: <a href="https://pytorch.org/docs/stable/tensors.html#torch.Tensor.fill_diagonal_" rel="nofollow noopener">fill_diagonal_</a></p>
<p><code>fill_diagonal_</code> ( <em>fill_value</em> ,  <em>wrap=False</em> ) → Tensor</p>

username: Usman_Mahmood
cooked: <p>How to do it for a batch of tensors? For tensor with shape N * M * M. Have to set diagonal equal to zero for every M*M matrix. fill_diagonal doesn’t work if N isn’t equal to M.</p>

username: redtailedhawk
cooked: <p>Break it into smaller problems. Each M x M tensor can be cycled through from [0 to N-1]. Run the function on each layer.</p>

username: Usman_Mahmood
cooked: <p>I did that but I wanted a solution which didn’t involve loop/cycle.</p>

username: Sandro_Hauri
cooked: <p>A bit late, but if anyone is interested in the batched version without loop:</p>
<pre><code class="lang-auto">t1 = torch.rand(m, n, n)
t2 = t1 * (1 - torch.eye(n, n).repeat(m, 1, 1))
</code></pre>
Kornia: how to apply morphological closing on 3D tensor?

username: renken
cooked: <p>Hi,</p>
<p>I want to apply morphological closing on a 3D grayscale/binary batched tensor. So far, i tried:</p>
<pre><code class="lang-auto"># importing modules
import torch
import torch.nn as nn
import torch.nn.functional as F
from kornia import morphology as morph

# creating random input 
input_tensor = torch.rand(1,1,8,8,8)
print(input_tensor[:,:,:,:,0])

# applying morphological closing
morph_kernel = torch.ones(3,3,3)
result = morph.closing(input_tensor, morph_kernel)
print(result[:,:,:,:,0])
</code></pre>
<p>But it leads to this error:</p>
<pre><code class="lang-auto">ValueError: Input size must have 4 dimensions. Got 5
</code></pre>
<p>Do you know a way to perform closing on 3D tensors (B,C,X,Y,Z) with kornia ? (or any other way working on tensors and allowing backpropagation)</p>
<p>Thanks</p>
How to select random index with condition?

username: Hyeonuk_Woo
cooked: <pre><code class="lang-auto">input_boolean_mask= (torch.FloatTensor(10).uniform_()&gt;0.8) # shape 10  boolean tensor
#tensor([False,  True, False, False, False, False, False, False,  True, False])
</code></pre>
<p>I want to random select “n” indexes only among the values corresponding to the conditions I want( for above example, True value).</p>
<p>How can I do this? Thanks.</p>

username: ptrblck
cooked: <p>Something like this should work:</p>
<pre><code class="lang-python">input_boolean_mask = (torch.empty(10).uniform_()&gt;0.8)
print(input_boolean_mask)
# tensor([ True, False, False, False, False,  True,  True, False, False,  True])

# get indices of True values
idx = input_boolean_mask.nonzero()
print(idx)
# tensor([[0],
#         [5],
#         [6],
#         [9]])

# select n indices
n = 2
ret = idx[:n]
print(ret)
# tensor([[0],
#         [5]])
</code></pre>

username: Hyeonuk_Woo
cooked: <p>I wanted to select random n indices  among True values. For example, select random n selection among indices (0,5,6,9).<br>
I solved problem with <code>torch.Tensor.multinomial</code> (<a href="https://pytorch.org/docs/stable/generated/torch.Tensor.multinomial.html" class="inline-onebox" rel="noopener nofollow ugc">torch.Tensor.multinomial — PyTorch 1.13 documentation</a>)</p>
<pre><code class="lang-auto">input_boolean_mask = (torch.empty(10).uniform_()&gt;0.8).long()
input_boolean_mask=input_boolean_mask.float()
print(input_boolean_mask)
#tensor([0, 1, 0, 0, 0, 0, 1, 0, 1, 0])
indices=input_boolean_mask.multinomial(2,replacement=False)
print (indices)
#tensor([1,8])
</code></pre>
<p>If this way is inefficient and you have suggestion, please let me know.</p>
<p>Thanks.</p>
Missing keys in load_state_dict

username: DoHuuDat
cooked: <p>Hi all,</p>
<p>I finished training the model and I’m trying to load it for evaluation at the moment. However, load_state_dict raise error:</p>
<pre><code class="lang-auto">Missing key(s) in state_dict: "iter", "losses.class_map.cls_linear.weight", ...
</code></pre>
<p>But when I tried to print the state_dict.keys(), the keys are the same as the missing keys:</p>
<pre><code class="lang-auto">odict_keys(['iter', 'losses.class_map.cls_linear.weight', ...
</code></pre>
<p>The code for the model is quite big so I can’t paste it here.</p>
<p>Did anyone encounter this bug? Any idea of what might be causing this?</p>
<p>Any help is appreciated. Thanks.</p>
How to debug "trying to resize storage that is not resizable" error?

username: Vedant_Roy
cooked: <p>I’m getting the following error:</p>
<pre><code class="lang-auto">(RayTrainWorker pid=916350)   File "/home/ray/anaconda3/lib/python3.8/site-packages/torch/utils/data/_utils/collate.py", line 162, in collate_tensor_fn
(RayTrainWorker pid=916350)     out = elem.new(storage).resize_(len(batch), *list(elem.size()))
(RayTrainWorker pid=916350) RuntimeError: Trying to resize storage that is not resizable
</code></pre>
<p>Roughly, I have the following function in a torchdata pipeline:</p>
<pre><code class="lang-auto">    def make_augmentations(x):
        aug1, aug2 = augment(x.data), augment(x.data)
        return dict(aug1=aug1, aug2=aug2, og=x.data, url=x.url, index=x.Index)
</code></pre>
<p>the dict later gets passed into pytorch’s <code>collate</code> function. I get the above error if I include the <code>og=x.data</code> line in the <code>return</code> statement.</p>
<p>I’m not sure what to do here. I tried deep copying the tensor, but that did not help. I also tried to convert to/from a numpy array, and that did not help either.</p>
<p>What might be going on here?</p>
Sampling patches of a set of images

username: sergiobd
cooked: <p>I need to get patches around certain points in a set of images. For the sake of this question, let’s say I have 2 images, and 8 points per image. I’d like to get 5-pixel-wide patches around each point on each image. My current approach is to make the indices first, and then try to sample the images with my indices. I’m stuck in the last part.</p>
<p>Let:</p>
<p><code>src_uvs</code> → coordinates of the interest points (shape <code>[2, 2, 8]</code>: xy coords for 8 points on 2 images)</p>
<p><code>patch_size</code> → patch half-width ( =5. The patch is symmetric around each point, so the size of the patch is 11x11)</p>
<p><code>N</code> → Number of interest points ( =8)</p>
<p><code>src_img_gray</code> → The images to be sampled, with shape [2, 540, 960] (2 images for this example)</p>
<pre><code class="lang-auto"># Make one patch
meshgrid_patch = torch.meshgrid( 
    torch.arange(-patch_size , patch_size + 1), 
    torch.arange(-patch_size , patch_size + 1))

# Take each coordinate of the meshgrid, and expand it to size [11, 11, 2, 8]
mm_x = meshgrid_patch[0][..., None, None]
mm_x = mm_x.expand(2 * patch_size + 1 , 2 * patch_size + 1, nsrc, N)

# We add this to the point's coordinates
x_coords = src_uvs[:, 0, :] + mm_x
y_coords = src_uvs[:, 1, :] + mm_x.transpose(0, 1) # transposing 1st 2 components.
</code></pre>
<p>At this point, <code>x_coords</code> and <code>y_coords</code> are tensors with shape <code>[11, 11, 2, 8]</code> , which hold the coordinates of the pixels that I want to sample on the image set ( which has shape <code>[2, 540, 960]</code> ). I’m unsure how to proceed to sample the images.</p>
How to create custom dataset with variable length input

username: Hyakuri
cooked: <p>Hi, I am a beginner for Pytorch but have experience using Tensorflow.</p>
<p>Currently, I want custom a Dataset to load some .npy data from HHD streamingly. At same time, I also want drop out some elements that not  meet conditions from <code>pathlist</code>.<br>
I try to use <code>__getitem__()</code> in <code>torch.utils.data.Dataset</code> , but index count  will raise error due to the variable length of <code>pathlist</code> (I pop() some bad data). Maybe it is because <code>__len__</code> only be recalled once at batch size counting?</p>
<p>My question is what should I do to re-count length and index before iterating. Thank you!</p>
<p>Here is my code:</p>
<pre><code class="lang-python">class NPY_Dataset(torch.utils.data.Dataset):
    def __init__(self, abspath_filelist: list[str]) -&gt; None:
        super().__init__()
        self.abspath_list = abspath_filelist

    def __len__(self):
        return len(self.abspath_list)

    def __getitem__(self, idx) -&gt; np.ndarray:
        data_path = self.abspath_list[idx]
        sample = np.load(data_path, allow_pickle=True)
        sample = sample.astype(np.float32)

        # data check
        if len(sample) &lt; custom_size:
            self.abspath_list.pop(idx)
            return self.__getitem__(idx)

        return sample
</code></pre>

username: nivek
cooked: <p>One option is to use an <a href="https://pytorch.org/docs/stable/data.html#iterable-style-datasets" rel="noopener nofollow ugc">Iterable-style Dataset</a> (or <code>IterDataPipe</code> in <a href="https://pytorch.org/data/main/torchdata.datapipes.iter.html" rel="noopener nofollow ugc">TorchData</a>), where your custom Dataset’s <code>__iter__</code> method can skip over samples that do meet your criteria (or call <code>.filter()</code> if you are using <code>IterDataPipe</code>).</p>

username: Hyakuri
cooked: <p>Thank you for your response! I will have a try with Iterable-style.</p>
Another way to implement MAML(Model-Agnostic Meta-Learning)?

username: zhyliu00
cooked: <p>Typically many maml implementation use nn.functional interface such as F.linear(x,w,b). However, it is unfriendly for the pre-defined nn.Module model.<br>
So, if I initialize a model (Resnet as an example), copy its parameters</p>
<pre><code class="lang-auto">model = Resnet()
param_copy = copy.deepcopy(model.parameters())
</code></pre>
<p>Then, I do the meta training, each update step as follow</p>
<pre><code class="lang-auto"># load parameters
for meta_param, model_param in zip(param_copy, model.parameters()):
    # shallow copy here
    model_param = meta_param

out = model(x)
loss = F.cross_entropy(out, y)
grad = torch.autograd.grad(loss, param_copy)
# use grad to update param_copy
param_copy = list(map(lambda p: p[1] - update_lr * p[0], zip(grad, param_copy)))
</code></pre>
<p>Thus, in this fashion, nn.functional interface is replaced by shallow copy of the parameter variable.</p>

username: soulitzer
cooked: <p>Hey, just to confirm my understanding of the issue:</p>
<ul>
<li>you are creating a new set of the parameters after updating them with grad out of place</li>
<li>nn.functional is easy to use because you can just pass the new parameter</li>
<li>however, it is harder to replace the parameter for pre-defined nn.Modules</li>
</ul>
<p>Please correct me if I’m misunderstanding!</p>

username: zhyliu00
cooked: <ol>
<li>Yes</li>
<li>Yes.</li>
<li>Yes.</li>
</ol>

username: soulitzer
cooked: <p>These might help, depending if you want to use functorch or not:</p>
<ul>
<li><a href="https://pytorch.org/docs/stable/generated/torch.nn.utils.stateless.functional_call.html" class="inline-onebox" rel="noopener nofollow ugc">torch.nn.utils.stateless.functional_call — PyTorch 1.13 documentation</a></li>
<li><a href="https://pytorch.org/functorch/1.13/generated/functorch.make_functional.html?highlight=make_functional#functorch.make_functional" class="inline-onebox" rel="noopener nofollow ugc">functorch.make_functional — functorch 1.13 documentation</a></li>
</ul>
<p>FYI: These APIs do very similar things, we’re in the process of moving functorch in to pytorch and merging these two APIs.</p>

username: zhyliu00
cooked: <p>Thanks! This is what I need.</p>
Does pytorch support Intel ® SSE2, Intel ® SSE3, Intel ® SSSE3 Instruction Set?

username: RichardWang
cooked: <p>nao [err 1] ~ $ pip install torch-1.4.0+cpu-cp27-cp27mu-linux_x86_64.whl<br>
Defaulting to user installation because normal site-packages is not writeable<br>
ERROR: torch-1.4.0+cpu-cp27-cp27mu-linux_x86_64.whl is not a supported wheel on this platform.<br>
/usr/lib/python2.7/site-packages/pip-20.3.1-py2.7.egg/pip/<em>vendor/urllib3/util/ssl</em>.py:424: SNIMissingWarning: An HTTPS request has been made, but the SNI (Server Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information,</p>
Does `torch.distributed.pipeline.sync.Pipe` only supports model with single input?

username: JiayiFeng
cooked: <p>The <code>torch.distributed.pipeline.sync.Pipe</code> use a <code>torch.nn.Sequential</code> object as its underlying model. However, it seems that <code>torch.nn.Sequential</code> can only have one input. For the <code>Pipe</code> doesn’t modify the input signature of the underlying module, does it means that the <code>Pipe</code> can only handle models with single input?</p>
<p>If so, is there any method to walk around this limitation and pipeline parallelize models with multiple inputs?</p>
<p>Many thanks!!</p>

username: mrshenli
cooked: <p>Hey <a class="mention" href="/u/jiayifeng">@JiayiFeng</a></p>
<blockquote>
<p>For the <code>Pipe</code> doesn’t modify the input signature of the underlying module, does it means that the <code>Pipe</code> can only handle models with single input?</p>
</blockquote>
<p>I believe this is true, as of v1.13. However, for multi-input model, I assume you can create a wrapper that packs multiple input/output into one customized object and unpack before calling into the original model?</p>

username: JiayiFeng
cooked: <p>Hi <a class="mention" href="/u/mrshenli">@mrshenli</a>, thanks for your replay! But I’m afraid it won’t work. Because <code>Pipe</code> requires that the inputs contain at least one tensor. If I wrap all inputs into one object, it means that there is only one input for <code>Pipe</code> and it is not a tensor, <code>Pipe</code> will reject it.</p>
<p>see: <a href="https://pytorch.org/docs/stable/pipeline.html#torch.distributed.pipeline.sync.Pipe.forward" class="inline-onebox" rel="noopener nofollow ugc">Pipeline Parallelism — PyTorch 1.13 documentation</a></p>
Alternative to `torch.Generator` for using `mps`

username: Michael_Vinyard
cooked: <p>Is there an alternative to using <code>torch.Generator</code>? When used as follows, even with PyTorch version: 1.13.0, the subsequent error is given.</p>
<pre><code class="lang-python">device = 'mps'
generator = torch.Generator(device).manual_seed(int(seed))    
</code></pre>
<pre data-code-wrap="BASH"><code class="lang-nohighlight">RuntimeError: Device type MPS is not supported for torch.Generator() api.
</code></pre>