akankshakshurai/cuda-error-resolution-analysis huggingface dataset:
Using validation data separated from train data in Skorch EarlyStopping

Oxward: <p>Dear reader,</p>
<p>In a project implying a Sklearn pipeline, I’m trying to add my Pytorch model, therefore I have been using the usefull wrapper Skorch to make the link.</p>
<p>It’s working well, the problem is that I want to use a callback to perform EarlyStopping:</p>
<p>"   callbacks = [EarlyStopping(monitor=‘valid_loss’, patience=self.classifier.patience, threshold=0.0001, threshold_mode=‘rel’, lower_is_better=True, load_best=True)],"</p>
<p>and doing this, I found in skorch documentation, that it was using a split of the train data, where as I already have a split train/valid made before the train loop and I would like to use this specific valid data as the validation data used in the EarlyStopping Callback, as well as the one displayed in :<br>
" valid_loss=net.history[:, ‘valid_loss’] "</p>
<p>Could anyone who has any idea how to proceed with my already splitted data in this specific case, help me ?</p>
<p>Thanks in advance !!</p>
What would be the "correct" way to classify live audio?

hananelroe: <p>I have a trained audio classifier network that I want to do live inference with. for that I to have a mel spectrogram “live stream” from the microphone. the only way that I can think of is recording the audio, saving it to a .wav file and then loading it back with torchaudio. is there a cleaner way to do it?</p>

hananelroe: <p>here’s what chatGPT came up with + some tweaks:</p>
<pre><code class="lang-auto">import torch
from torch import nn
from torch.nn import functional as F
import sounddevice as sd
import torchaudio
import numpy as np


def record_specgram():
    # Parameters
    sample_rate = 1200  # Sample rate
    duration = 5  # Duration to record in seconds

    print("Recording...")

    # Record audio from microphone
    audio = sd.rec(int(sample_rate * duration), samplerate=sample_rate, channels=1, dtype='float32')
    sd.wait()  # Wait until the recording is finished

    print("Recording finished")

    # Convert the NumPy array to a PyTorch tensor
    waveform = torch.from_numpy(audio).squeeze()

    # If necessary, transpose the waveform to fit torchaudio's expectations (shape: [channels, time])
    # waveform = waveform.transpose(0, 1)

    # Define the transformation
    mel_spectrogram_transform = torchaudio.transforms.MelSpectrogram()

    # Generate the mel spectrogram
    mel_spectrogram = mel_spectrogram_transform(waveform)

    # half the sample rate
    half_specgram = mel_spectrogram[:, ::2]

    # pad
    half_specgram = np.pad(half_specgram, [(0, 0), (174, 0)])

    # replace zero values
    half_specgram[half_specgram == 0] = 0.00001
    half_specgram = np.log(half_specgram)


    print("Mel spectrogram shape:", mel_spectrogram.shape)
    print("half Mel spectrogram shape:", half_specgram.shape)

    return torch.from_numpy(half_specgram)

</code></pre>
Dataloader, parallelism, SSD, and hanging long

kzaitse: <p>Hi, my profiler returns the following result for the training loop:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/4/f/4f68b8d2946246c3392bbc4b58acbcc7fb94e93f.png" data-download-href="https://discuss.pytorch.org/uploads/default/4f68b8d2946246c3392bbc4b58acbcc7fb94e93f" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/4/f/4f68b8d2946246c3392bbc4b58acbcc7fb94e93f_2_690x321.png" alt="image" data-base62-sha1="bku5kl9IaiI3b4bPMtJblFI0FlB" width="690" height="321" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/4/f/4f68b8d2946246c3392bbc4b58acbcc7fb94e93f_2_690x321.png, https://discuss.pytorch.org/uploads/default/optimized/3X/4/f/4f68b8d2946246c3392bbc4b58acbcc7fb94e93f_2_1035x481.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/4/f/4f68b8d2946246c3392bbc4b58acbcc7fb94e93f_2_1380x642.png 2x" data-dominant-color="8A8A8C"><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">2190×1021 103 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></p>
<p>There are two problematic things:</p>
<ol>
<li>a method in popen_spawn_posix.py that bottlenecks training</li>
<li>a <code>__del__</code> method in dataloader.py that takes suspiciously long</li>
</ol>
<p>The problem applies only when I use <code>num_workers &gt; 0</code>. My data resides on an SSD drive.</p>
<p>Remarks about the code:</p>
<ul>
<li>The dataset’s <code>__getitem__</code>  loads a single .npy file ~3MB in size.</li>
<li>The dataset’s <code>__init__</code> loads a single .json file ~40MB in size</li>
<li>dataloader:</li>
</ul>
<pre><code class="lang-auto">torch.utils.data.DataLoader(
                dataset,
                batch_size=4,
                shuffle=False,
                sampler=None,
                num_workers=4,
                collate_fn=custom_collate_fn,
                drop_last=True,
                persistent_workers=True,
            )
</code></pre>
<p>Also, having <code>persistent_workers=True</code> makes we wonder why the next bottleneck is <code>__del__</code> from <code>dataloader.py</code>.<br>
Thanks for your help.</p>

kzaitse: <p>Without loading the 40MB file in <code>__init__</code> it gets faster, but still substantially slower than <code>num_workers=0</code></p>
[Torchvision] [Android] Torchvision.ops when will they be available on Mobile

zetyquickly: <p>Hello,</p>
<p>Let me introduce a problem. Last month two significant features for mobile deployment was added to pytorch=1.4. I am talking about torchvision operations torchvision::nms and torchvision::roi_align that are now convertible from eager python code via torchscript to <code>.pt</code> model.</p>
<p>The most recent builds of pytorch for mobile don’t contain this features. Is there any estimation when wiil tey be available to use on phones?</p>

David_Reiss: <p>We’re looking into this.  Probably late this year or early next year.</p>

noranart.v: <p>Thank you so much for the update. Would nms be planned to support on Android anytime soon?</p>

AmrAhmed: <p>Hello, When nms will be supported in Android?</p>
<p>Thanks</p>

Redney_Quartz: <p>Any further progress?</p>

valerianG: <p>Any update on the NMS for Pytorch Mobile (Android) ?</p>

trina: <p>hi there any updates</p>
How to use autograd to differentiate twice when non scalar?

santom: <p>def physics_loss(pinn_output, mass, forces):<br>
# Create a tensor of time values<br>
time = torch.linspace(0, (len(pinn_output)-1)*0.01, len(pinn_output)).requires_grad_(True)</p>
<pre><code># Repeat the time tensor to match the dimensions of pinn_output
time = time.unsqueeze(1).repeat(1, pinn_output.shape[1])

# Compute velocity by differentiating position with respect to time
v_pred = torch.autograd.grad(pinn_output, time, grad_outputs=torch.ones_like(pinn_output), create_graph=True, allow_unused=True)[0]

# Compute acceleration by differentiating velocity with respect to time
a_pred = torch.autograd.grad(v_pred, time, grad_outputs=torch.ones_like(v_pred), create_graph=True, allow_unused=True)[0]

# Adjust for gravity in the y-direction
a_pred[:, 1] -= 9.81  # Subtract gravity from y-acceleration

# Compute the physics loss
return torch.mean((forces - mass * a_pred) ** 2)
</code></pre>
<p>I have this physics loss equation and I am trying to get v_pred and a_pred but I constantly get errors like “TypeError: ones_like(): argument ‘input’ (position 1) must be Tensor, not NoneType”</p>

AlphaBetaGamma96: <p>Hi <a class="mention" href="/u/santom">@santom</a>,</p>
<p>Can you check the type of <code>pinn_output</code> and <code>v_pred</code>, they seem to be type <code>None</code> instead of a <code>Tensor</code>.</p>

santom: <p>hey!</p>
<p>for the pinn_ouput, this is the type : &lt;class ‘torch.Tensor’&gt;</p>
<p>for v_pred, this is the type: &lt;class ‘NoneType’&gt;</p>
<p>But I don’t understand why the v_pred is nontype. Do you know?</p>

AlphaBetaGamma96: <aside class="quote no-group" data-username="santom" data-post="1" data-topic="204380">
<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/s/6f9a4e/48.png" class="avatar"> santom:</div>
<blockquote>
<p><code>allow_unused=True</code></p>
</blockquote>
</aside>
<p>If you set <code>allow_unused=False</code>, does autograd state there are Tensors not used in calculation of the gradient?</p>
<p>Is the <code>time</code> Tensor used in the calculation of <code>pinn_output</code>?</p>
Security Issue in RPC - still relevant if RPC is not being used?

jjordan: <p>A potentially severe security issue was reported, see e.g. <a href="https://www.securityweek.com/critical-pytorch-vulnerability-can-lead-to-sensitive-ai-data-theft/" rel="noopener nofollow ugc">https://www.securityweek.com/critical-pytorch-vulnerability-can-lead-to-sensitive-ai-data-theft/</a> or <a href="https://nvd.nist.gov/vuln/detail/CVE-2024-5480" class="inline-onebox" rel="noopener nofollow ugc">NVD - CVE-2024-5480</a></p>
<p>Is this issue relevant if torch RPC is not explicitly being used? Is it recommended to update PyTorch, even if training and inference is only performed on a single GPU in a single system?</p>
Reshaping tensor image

Ghostv: <p>Hi,</p>
<p>This is probably very basic, but i have the following issue… i have an rgb image read as a tensor (torchvision.io.read_image) with the shape (c,rows,columns). Now, i’m trying to reshape it into a (rows x columns,3) array which contains in each row the 3 channel values (the rgb color), but i haven’t been able to figure out a way to tell reshape() to read the values iterating over the channel dimension first. When i use img.reshape((4140*2647,3)), the order for reading the values is row-wise.</p>
<p>Any idea how to achieve it?</p>
<p>Thanks in advance!</p>

vdw: <p>Since you want to swap the dimensions, <code>reshape()</code> and <code>view()</code> are probably the wrong approaches anyway. Assuming your tensor is called <code>X</code>, you can do</p>
<pre><code class="lang-auto">X = X.permute(1, 2, 0)
</code></pre>

Ghostv: <p>I never ever said i wanted to ‘swap the dimensions’, i literally said i wanted to reshape.</p>
<p>I managed to do it with</p>
<p><code>y = x.flatten(start_dim=1,end_dim=2).t().reshape(x.shape[1]*x.shape[2],3)</code></p>
<p>Thanks anyway!</p>

vdw: <p>I still think you might(!) need to swap the dimensions first since you <code>c</code> dimensions is the first in the input and the last in the output. Sure, you can reshape it immediately, but you might mess up your data semantically (see <a href="https://discuss.pytorch.org/t/for-beginners-do-not-use-view-or-reshape-to-swap-dimensions-of-tensors/75524">here</a>)</p>
<p>I would have no doubt that your solution is perfectly fine, I honestly can’t tell from just look at the line. I’m just wondering if something like this</p>
<pre><code class="lang-auto">X = X.permute(1, 2, 0)
X = X.reshape(-1, 3)  # not 100% sure if correct
</code></pre>
<p>might not be much easier to read/maintain.</p>

Ghostv: <p>Just tested it, both solutions are indeed equivalent :).</p>
<p>Thanks again!</p>
Inplace resizing with interpolation options

Faruk_Nane: <p>Hi, I am working on a deployment server where I want to resize a bunch of images to a fixed size. The problem is that I don’t want to create a new tensor when doing interpolation/resizing since it requires a memory allocation and it will have to reassign the values to the ‘images’ tensor.</p>
<p>My current code:</p>
<pre><code class="lang-auto">images = torch.empty((len(original_images), 3, input_size[0], input_size[1]), device=device, dtype=dtype)

        for i, image in enumerate(original_images):
            images[i] = F.interpolate(image, size=input_size, mode='bilinear', align_corners=False)
</code></pre>
<p>Is there something like:</p>
<pre><code class="lang-auto">F.interpolate(input_tensor=image, output_tensor=images[i], size=input_size, mode='bilinear', align_corners=False)
</code></pre>
<p>I found a few functions which don’t support any interpolation mode:</p>
<pre><code class="lang-auto">torch._copy_from_and_resize
torch.resize_as_
</code></pre>
<p>I think writing optimal code for better performance is important for servers. However, the options seem to be limited.</p>
<p>Do you have a possible solution or workaround?</p>
<p>Thank you!</p>

ptrblck: <p>Why don’t you pass all images to <code>F.interpolate</code> as it also accepts batched inputs:</p>
<pre data-code-wrap="python"><code class="lang-python">image = torch.randn(1, 3, 500, 500)
input_size = (224, 224)
out = F.interpolate(image, size=input_size, mode='bilinear', align_corners=False)
print(out.shape)
# torch.Size([1, 3, 224, 224])

image = torch.randn(16, 3, 500, 500)
input_size = (224, 224)
out = F.interpolate(image, size=input_size, mode='bilinear', align_corners=False)
print(out.shape)
# torch.Size([16, 3, 224, 224])
</code></pre>

Faruk_Nane: <p><a class="mention" href="/u/ptrblck">@ptrblck</a> Sorry for the lack of explanation in the question. The original_images is a list of images which are in different sizes.</p>

SchulzKilian: <p>Idea for a “workaround”: If your images arent of completely different sizes, you can pad them all to the size of the biggest images, and then interpolate using bilinear. With bilinear not too many artifacts should remain (maybe slightly blurry edges) , the rest of the code would then be as <a class="mention" href="/u/ptrblck">@ptrblck</a> suggested</p>

Faruk_Nane: <p><a class="mention" href="/u/schulzkilian">@SchulzKilian</a> hi, thank you for your message. However, I should remind that my question is not how to resize images with batching. I’m looking for a solution that doesn’t allocate any new memory/tensors. The solution you suggest allocates new tensors (paddings) or expands the existing tensors and then resizes with batching.</p>
How to combine two models sequentially?

jybb: <p>I have two fine-tuned PyTorch models: one for segmentation and one for classification. My goal is to crop an image using a binary mask from the segmentation model and then use the cropped image for classification.</p>
<p>This process is straightforward on my workstation, but I haven’t found useful resources on how to achieve it. Do you have any recommendations or a simple workflow for this task?</p>
Nsight-compute profiling for torch?

dsa-shua: <p>Hi, I am a newbie here. Sorry if the post is unrelated to PyTorch or something… I just want to profile hugging face transformers mainly written in torch using nsight-compute (ncu). Is there any one who tried to do so? I know there is torch.cuda.profiler but I want to measure occupancy of the GPU instead of the percentage of the execution time of each kernel.</p>
<p>Thanks~</p>
Fx on split and cat combination

Sydney_Hauke: <p>Hi,</p>
<p>I am tracing some model containing a consecutive call to split whose output is then passed to cat :</p>
<pre><code class="lang-python">import torch
from torch.fx import symbolic_trace

class M(torch.nn.Module):
    def forward(self, x):
        y = torch.split(x, 4, 2)
        return torch.cat(y, 0)

m = M()
traced = symbolic_trace(m)
print(traced.graph)
</code></pre>
<p>which, when executed triggers an error :</p>
<pre data-code-wrap="shell"><code class="lang-nohighlight">TypeError: cat() received an invalid combination of arguments - got (Proxy, int), but expected one of:
 * (tuple of Tensors tensors, int dim, *, Tensor out)
 * (tuple of Tensors tensors, name dim, *, Tensor out)
</code></pre>
<p>On other torch functions I have never seen such a problem. The difference I see here is that the intermediate value between split and cat is a sequence of tensors instead of a single tensor. And apparently this doesn’t play well under FX for some reason.</p>
<p>I am wondering if this is the desired behaviour and if I am missing something. Is there a workaround ?</p>
<p>Could the following issue : <a href="https://github.com/pytorch/pytorch/issues/34294" class="inline-onebox" rel="noopener nofollow ugc">torch.cat does not call __torch_function__ properly · Issue #34294 · pytorch/pytorch · GitHub</a><br>
be related to the behaviour I am observing ?</p>

Michelvl92: <p>have you fixed this already? I have the same issue.</p>
NVIDIA cuda version for docker

Maha: <p>Hey folks, need some help here! We’re trying to run an AWS batch job that uses an Nvidia GPU in darts model definition. It works fine on our local machine, but when we containerize it with Docker, it fails to detect the GPU available on the instance.<br>
Host-machine has cuda 11.4 nvidia drivers pre- installed and nvidia toolkit of the same version. How can I build a docker image to use these nvidia drivers so that it detects the GPU in the instance?</p>
AttributeError: Can't pickle local object 'setup_data_loader.<locals>.seed_worker'

namespace: <p>Hi all,<br>
I hope everybody reading this is having a great day.</p>
<p>So I have a problem when reproducing the experiments of <a href="https://paperswithcode.com/paper/large-language-models-are-zero-shot-reasoners" rel="noopener nofollow ugc">Large Language Models are Zero-Shot Reasoners</a>.<br>
I have installed all required package and equiped the environment.<br>
But when I run <code>main.py</code>,  it outputs the following error:</p>
<blockquote>
<p>Traceback (most recent call last):<br>
File “”, line 1, in <br>
File “C:\ProgramData\anaconda3\Lib\multiprocessing\spawn.py”, line 120, in spawn_main<br>
Traceback (most recent call last):<br>
File “D:\GitHub project\zero_shot_cot\main.py”, line 217, in <br>
exitcode = _main(fd, parent_sentinel)<br>
^^^^^^^^^^^^^^^^^^^^^^^^^^<br>
File “C:\ProgramData\anaconda3\Lib\multiprocessing\spawn.py”, line 130, in _main<br>
self = reduction.pickle.load(from_parent)<br>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^<br>
EOFError: Ran out of input<br>
main()<br>
File “D:\GitHub project\zero_shot_cot\main.py”, line 36, in main<br>
for i, data in enumerate(dataloader):<br>
^^^^^^^^^^^^^^^^^^^^^<br>
File “C:\ProgramData\anaconda3\Lib\site-packages\torch\utils\data\dataloader.py”, line 441, in <strong>iter</strong><br>
return self._get_iterator()<br>
^^^^^^^^^^^^^^^^^^^^<br>
File “C:\ProgramData\anaconda3\Lib\site-packages\torch\utils\data\dataloader.py”, line 388, in _get_iterator<br>
return _MultiProcessingDataLoaderIter(self)<br>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^<br>
File “C:\ProgramData\anaconda3\Lib\site-packages\torch\utils\data\dataloader.py”, line 1042, in <strong>init</strong><br>
w.start()<br>
File “C:\ProgramData\anaconda3\Lib\multiprocessing\process.py”, line 121, in start<br>
self._popen = self._Popen(self)<br>
^^^^^^^^^^^^^^^^^<br>
File “C:\ProgramData\anaconda3\Lib\multiprocessing\context.py”, line 224, in _Popen<br>
return _default_context.get_context().Process._Popen(process_obj)<br>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^<br>
File “C:\ProgramData\anaconda3\Lib\multiprocessing\context.py”, line 336, in _Popen<br>
return Popen(process_obj)<br>
^^^^^^^^^^^^^^^^^^<br>
File “C:\ProgramData\anaconda3\Lib\multiprocessing\popen_spawn_win32.py”, line 94, in <strong>init</strong><br>
reduction.dump(process_obj, to_child)<br>
File “C:\ProgramData\anaconda3\Lib\multiprocessing\reduction.py”, line 60, in dump<br>
ForkingPickler(file, protocol).dump(obj)<br>
AttributeError: Can’t pickle local object ‘setup_data_loader..seed_worker’</p>
</blockquote>
<p>Would anybody be kind enough to tell me how to solve this problem</p>

zzy20020802: <p>Hi, have you solved the problem? I met the same issue.</p>

getharrymiles: <p>Hi,<br>
I am also having same issue. Were you able to resolve the issue?<br>
<a class="mention" href="/u/namespace">@namespace</a> <a class="mention" href="/u/zzy20020802">@zzy20020802</a></p>
How to implement the functionality of SCATTER_MEAN function from torch_scatter

Srujan_Topalle: <p>I want to replicate teh effect of Scatter_mean function in the torch-scatter library in basic pytorch code, how can I go about this?</p>

ptrblck: <p>You can use <code>tensor.scatter_reduce_</code> with <code>reduce="mean"</code>.</p>
How could I create one hot tensor while ignoring some label index

coincheung: <p>Hi,</p>
<p>I am  creating one hot label with this function:</p>
<pre><code class="lang-auto">def one_hot_emb(logits, label):
    lb_one_hot = logits.data.clone().zero_().scatter_(1, label.unsqueeze(1), 1)
    return lb_one_hot
</code></pre>
<p>It works when there is no ignore labels. When there is ignore labels such as <code>lb_ignore=255</code>, I hope the one hot vector at this position to be all zeros. How could I do this please?</p>
<p>For example, there is a <code>label=[0,1,2]</code> whose one hot embedding is: <code>[[1,0,0], [0,1,0], [0,0,1]]</code>.  If the label is  <code>label=[0,1,255]</code>, where 255 is the ignored label, the output should be: <code>[[1,0,0], [0,1,0], [0,0,0]]</code>.</p>
<p>Do I have a way to do it?<br>
The label tensor might not be 1d tensor, I can be tensor of shape <code>N,C,H,W</code>.</p>

MariosOreo: <p>Waiting for the solutions… …</p>

ptrblck: <p>One possible approach would be to set the <code>lb_ignore</code> to <code>nb_classes+1</code>, create an approprialty shaped zero tensor, and remove this additional dimension using slicing.<br>
Probably not the best approach, but it should work.</p>

Jo-w: <aside class="quote no-group quote-modified" data-username="coincheung" data-post="1" data-topic="40987">
<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/c/ad7895/48.png" class="avatar"> coincheung:</div>
<blockquote></blockquote>
</aside>
<p>Have you solve that? I can only think of it as ptrblck said below.</p>

Jack_Zhening_Huang: <pre><code class="lang-auto">def onehot_with_ignore_label(labels, num_class, ignore_label):
    dummy_label = num_class + 1
    mask = labels == ignore_label
    modified_labels = labels.clone()
    modified_labels[mask] = num_class
    # One-hot encode the modified labels
    one_hot_labels = torch.nn.functional.one_hot(modified_labels, num_classes=dummy_label)
    # Remove the last row in the one-hot encoding
    one_hot_labels = one_hot_labels[:, :-1]
    return one_hot_labels
</code></pre>

mkoerner: <p>Thanks for the <code>labels.clone()</code> hint! A version ignoring all labels larger than <code>num_classes</code> by mapping them to <code>0</code> and reusing the mask to remove their encoding:</p>
<pre><code class="lang-auto">def one_hot(target, num_classes):
    unused_mask = target &gt;= num_classes
    target = target.clone()
    target[unused_mask] = 0
    encoded = F.one_hot(target, num_classes)
    encoded[unused_mask, :] = False
    return encoded
</code></pre>
Amount of custom filters in CNNs when comparing to default filters?

undefined: <p>When I want to compare the performance of CNNs between using the default and using custom filters, should I use the same amount of filters in both cases?<br>
Let’s say I want to use custom filters (and by that I mean I choose my own initial weights for the filters) for the first conv layer. Should I create the same amount of custom filters as my “normal” CNN has in its first layer?</p>

sally2: <p><em>Hey there <a class="mention" href="/u/undefined">@undefined</a></em><br>
<strong>When comparing CNNs with default and custom filters, it’s important to use the same number of filters in both cases. This ensures a fair comparison. Keeping the number of filters consistent allows us to see how customizing filters affects performance without other variables getting in the way. It also ensures fair use of computational resources and training conditions. If you’re curious about how different filter numbers impact performance, it’s best to conduct separate experiments while keeping other factors constant.</strong></p>
Unable to install Pytorch on Python 3.9

Yodaking8549: <p>I had an issue trying to install Pytorch for Cuda 12.1. I used the following command from your install website:<br>
“pip install torch torchvision torchaudio --index-url <a href="https://download.pytorch.org/whl/cu121" rel="noopener nofollow ugc">https://download.pytorch.org/whl/cu121</a>”.</p>
<p>I got the following error:</p>
<p>Looking in indexes<br>
ERROR: Could not find a version that satisfies the requirement torch (from versions: none)<br>
ERROR: No matching distribution found for torch</p>
<p>Im on Windows 10 and a venv of Python 3.9.0. I tried to install the packages one after another so I ran<br>
“pip install torch --index-url <a href="https://download.pytorch.org/whl/cu121" rel="noopener nofollow ugc">https://download.pytorch.org/whl/cu121</a>”<br>
and the same for torchvision and torchaudio. Torchvision got installed just fine but for the other two I got the same error as before.</p>
<p>Im really confused on what to do so any Idea would greatly help out.<br>
Thanks in advance! <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>
INTERNAL ASSERT FAILED at "../c10/cuda/CUDACachingAllocator.cpp":829 while calculating dot product

Shibu: <p>attn = (q @ k.transpose(-2, -1)) * self.scale<br>

^
~~~~~~~~~~~~~~~~~~<br>
RuntimeError: NVML_SUCCESS == DriverAPI::get()-&gt;nvmlDeviceGetHandleByPciBusId_v2_( pci_id, &amp;nvml_device) INTERNAL ASSERT FAILED at “…/c10/cuda/CUDACachingAllocator.cpp”:829, please report a bug to PyTorch.</p>
<p>can anyone please help me to solve the above bug?</p>
Issue with Gradient Clipping When Using Stochastic Weight Averaging in PyTorch Lightning

gonzrubio: <p>Hi everyone,</p>
<p>I’m encountering an issue with gradient clipping at the final epoch when using Stochastic Weight Averaging (SWA) in PyTorch Lightning. The error occurs consistently at the last epoch of training. Below is my script:</p>
<pre><code class="lang-auto">import time
import hydra
import lightning as pl
import torch
from lightning.pytorch.loggers import WandbLogger
from lightning.pytorch.callbacks import LearningRateMonitor, ModelCheckpoint, StochasticWeightAveraging
from model import EarthQuakeModel
from omegaconf import DictConfig
from torchgeo.datamodules import QuakeSetDataModule

@hydra.main(config_path="configs", config_name="mobilenet", version_base=None)
def main(args: DictConfig):
    pl.seed_everything(100195, workers=True)
    torch.set_float32_matmul_precision("medium")

    model = EarthQuakeModel(**args.model)
    data_module = QuakeSetDataModule(**args.dataset)
    data_module.train_aug = None

    run_id = time.strftime('%Y%m%d-%H%M%S')
    wandb_logger = WandbLogger(
        project="smac",
        name=run_id,
        log_model="all"
    )
    wandb_logger.watch(model, log="gradients")

    checkpoint_callback = ModelCheckpoint(
        monitor="val_mae",
        dirpath=f"checkpoints/{run_id}",
        filename="earthquake-detection-{epoch:02d}-{val_mae:.4f}",
        save_top_k=3,
        mode="min",
    )
    lr_monitor = LearningRateMonitor(logging_interval="step")

    trainer = pl.Trainer(
        **args.trainer,
        deterministic=True,
        callbacks=[
            StochasticWeightAveraging(swa_lrs=1e-2),
            checkpoint_callback,
            lr_monitor
        ],
        logger=wandb_logger,
        log_every_n_steps=50,
        precision="32-true",
        gradient_clip_val=0.5,
        gradient_clip_algorithm="value"
    )

    trainer.fit(model, datamodule=data_module)

if __name__ == "__main__":
    main()

</code></pre>
<p><strong>Error Message:</strong></p>
<blockquote>
<p>Error executing job with overrides: [‘trainer.max_epochs=20’]<br>
…<br>
RuntimeError: Expected !nested_tensorlist[0].empty() to be true, but got false.<br>
…</p>
</blockquote>
<p>I am using PyTorch Lightning 2.2.3 and PyTorch 2.3.0.</p>
<p>I have tried using different <code>swa_epoch_start</code> values and changing the precision setting, but the issue persists. The gradient clipping method and SWA seem to work fine independently but cause this error when used together.</p>
<p>Has anyone encountered a similar issue or have insights on why this might be happening? Any suggestions on how to debug or fix this would be greatly appreciated!</p>
<p>Thanks in advance!</p>
Metrics for a GAN model

Najeh_Nafti: <p>How can I calculate the metrics for a GAN model: Accuracy, precision, F1, ROC and confusion matrix?</p>

toufiq: <p>Hi Najeh…</p>
<p>Its rather unfortunate no one has replied after all this while. This is for anyone else in the future, just in case.</p>
<p>GANs don’t converge (meaning there’s no clear endpoint to training where one will say it can no longer improve). And the outputs are not of the type that can be directly quantitatively assessed using F1, etc.</p>
<p>GANs can be assessed by other means such as the <a href="https://en.wikipedia.org/wiki/Fr%C3%A9chet_inception_distance" rel="noopener nofollow ugc">Frechet Inception Index (FID)</a>, Inception Score, etc for measuring generated image quality.</p>
<p>You can refer to the following github for help in evaluating your GAN: <a href="https://github.com/w86763777/pytorch-image-generation-metrics/tree/master" rel="noopener nofollow ugc">w86763777/pytorch-image-generation-metrics: Pytorch implementation of common image generation metrics. (github.com)</a></p>
Pytorch training slow

agunghabuu: <p>I have this project file using RoBERTa to create a model about multiclass text classification. Before I tested on my own laptop, I’m using google colab. It only took about 20-30 minutes for training. Then you know, it’s free version so I’ve reach my usage limit.<br>
After that I’m installing jupyterlab &amp; pytorch cuda version 12.1 on my laptop. I didn’t install cuda toolkit from nvidia website. Then I run it, it works. But when training my model, it says approximately 6-7 hours. Is that normal? Or I have some settings/configs wrong. Tbh my gpu laptop isn’t that good too. You know google colab has Nvidia Tesla T4 and my laptop was RTX 2050. But the difference is so big, I tried to use my cpu instead gpu then it says approximately 12 hours.</p>
<p>Please let me know if this normal or there’s something isn’t right. I have knowledge in machine learning before, but for NLP this is my first time<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/a/f/af504702f425c0ff0584d11815bd44cf196694de.jpeg" data-download-href="https://discuss.pytorch.org/uploads/default/af504702f425c0ff0584d11815bd44cf196694de" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/a/f/af504702f425c0ff0584d11815bd44cf196694de_2_690x346.jpeg" alt="image" data-base62-sha1="p0Ty9qOizHdQTT0feOjSL5DKQ7Y" width="690" height="346" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/a/f/af504702f425c0ff0584d11815bd44cf196694de_2_690x346.jpeg, https://discuss.pytorch.org/uploads/default/optimized/3X/a/f/af504702f425c0ff0584d11815bd44cf196694de_2_1035x519.jpeg 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/a/f/af504702f425c0ff0584d11815bd44cf196694de.jpeg 2x" data-dominant-color="2A2B2C"><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">1110×557 114 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></p>

ptrblck: <p>You could profile your code with a visual profiler, e.g. Nsight Systems, to see where the bottleneck in your code is. E.g. it could be the data loading, the CPU workload (i.e. scheduling the actual kernels), or the GPU itself.</p>