akankshakshurai/cuda-error-resolution-analysis huggingface dataset:
Performance regression between 2.1.0.dev20230621 (with cuda 1.17.1) and 2.1.0.dev20230628 (with cuda 12.1)

Benjamin_Sergeant: <p>I know it isn’t a great topic, but just want to bring this up as it did surprise me.</p>

ptrblck: <p>Could you describe what kind of performance regression you were seeing?</p>

Benjamin_Sergeant: <p>Runtime of an inference run got like 3x/4x slower.</p>

ptrblck: <p>Your information is unfortunately too vague and we didn’t observe any regression in our nightly testing.</p>

Benjamin_Sergeant: <p>I understand it’s very vague … I will try to narrow down the problem, at least in term of builds ; we were using the 1.17 cuda build until now (through the docker package), I will try to switch to the 1.18 one when I get a chance, or back to the first cuda 1.12.1 available to see if it has anything to do with this.</p>
Roc_auc_score error

nima_pw: <p>Hi,<br>
I have a CNN model for the classification task with 11 classes.<br>
I want to use <code>sklearn.metrics</code> to print metrics like F1, precision, roc_auc, etc.<br>
I’ve calculated y_real and y_pred as follow:</p>
<pre><code class="lang-auto">  with torch.no_grad():
        for inputs, targets in test_dl:
            targets = targets[0]

            inputs = inputs.to(device)
            outputs = model(inputs)
            _, preds = torch.max(outputs, 1)

            predict += [preds.cpu().numpy()]
            label += [targets.cpu().numpy()]

    y_pred = np.concatenate(predict)
    y_real = np.concatenate(label)
    return y_real, y_pred
</code></pre>
<p><code>y_real</code> and <code>y_pred</code> work ok and without any error for precision_score, recall_score, f1_score, for example:<br>
<code>print(recall_score(y_real, y_pred))</code></p>
<p>but for <code>roc_auc</code>, it doesn’t accept <code>y_real</code> and <code>y_pred</code>:</p>
<pre><code class="lang-auto">print('ROC: {:.4f}\n'.format(roc_auc_score(y_real, y_pred)))
ValueError: multi_class must be in ('ovo', 'ovr')
</code></pre>
<p>I also tested with <code>multi_class='ovo'</code> and <code>multi_class='ovr'</code>, I got this error:<br>
<code>AxisError: axis 1 is out of bounds for array of dimension 1</code></p>
<p>The type of <code>y_real</code> and <code>y_pred</code> and their shape for both of them are:</p>
<pre><code class="lang-auto">&lt;class 'numpy.ndarray'&gt;
(550,)
</code></pre>
How to build libtorch from source with C++20 on M1 Mac?

torchwang: <p>I am currently limited to using the Clang compiler and can only build libtorch with C++17. Building with GCC 13.1 fails. Can anyone tell me if libtorch currently supports building with C++20? I have a lot of C++20 code in my project and I would like to incorporate the libtorch library.</p>
Is pytorch adam eps same with keras adam eps?

bfss: <p>Hi, I moved my keras model to pytorch, but the model’s accuracy seems not right. Keras model’s result always 1%-2% higher than pytorch.</p>
<p>I used same initializer (xaiver uniform for kernel and zeros for bias), same random seed, same hyper parameters, and same datasets with same order (no shuffle) , the only thing I thought would be the adam optimizer,  I found keras’ document said:</p>
<p>This epsilon is “epsilon hat” in the Kingma and Ba paper (in the formula just before Section 2.1), not the epsilon in Algorithm 1 of the paper.</p>
<p>I searched it from forum but not find a solution about this.</p>
<p>Maybe there are differences between pytorch’ adam and keras’ s adam?</p>
<p>What should I do to let pytorch defeat keras? <img src="https://discuss.pytorch.org/images/emoji/apple/sob.png?v=12" title=":sob:" class="emoji" alt=":sob:" loading="lazy" width="20" height="20"></p>

AlphaBetaGamma96: <p>Hi <a class="mention" href="/u/bfss">@bfss</a>,</p>
<p>If I recall correctly, the eps factor in Adam varies between PyTorch and Keras. In Keras the eps is included within the sqrt of exp. moving average in the denominator, but in PyTorch it isn’t. So, that may have some effect on the asymptotic of your convergence.</p>
<p>Also, just because you use the same initializer doesn’t mean you have the same weights. Remember <code>nn.Linear</code> (the <code>Dense</code> layer in Keras) are defined differently from one other, albeit via a transpose operator, so you’ll get different weights and hence different performance.</p>
<p>You must make sure <strong>all</strong> aspects of the code is the same, because if they were you’d get the same results</p>

bfss: <p><a class="mention" href="/u/alphabetagamma96">@AlphaBetaGamma96</a></p>
<p>Very thanks for your reply~</p>
<p>I tried several (about 20 times）different random seed and export keras’ weights to pytorch, and keras always better than pytorch on my dataset.</p>
<p>Although the weights are same, keras’ accuracy is 97.75% while pytorch’s accuracy is  96.52%, I think the adam makes the difference between them.</p>
<p>Maybe I should try other optimizers.</p>
<p>Can you give me some advice about which optimizer is suitable for text classification?</p>
Libtorch with c++23 giving CUDA23 error

Te93: <p>Libtorch: libtorch CUDA12.1 nightly build<br>
OS: Windows<br>
CUDA: 12.1</p>
<p>With C++ set to version 23, I’m getting an error stating that <code>Target "cmTC_f8cbf" requires the language dialect "CUDA23" .  But the   current compiler "NVIDIA" does not support this, or CMake does not know the   flags to enable it.</code></p>
<p>Works fine with C++20 <code>set(CMAKE_CXX_STANDARD 20)</code> but not 23.</p>
<p>CMake error:</p>
<pre><code class="lang-auto">  Target "cmTC_f8cbf" requires the language dialect "CUDA23" .  But the
  current compiler "NVIDIA" does not support this, or CMake does not know the
  flags to enable it.


CMake Error at C:/DevDependencies/libtorch-win-shared-with-deps-latest/libtorch/share/cmake/Caffe2/Modules_CUDA_fix/upstream/FindCUDA/select_compute_arch.cmake:106 (try_run):
  Failed to generate test project build system.
Call Stack (most recent call first):
  C:/DevDependencies/libtorch-win-shared-with-deps-latest/libtorch/share/cmake/Caffe2/Modules_CUDA_fix/upstream/FindCUDA/select_compute_arch.cmake:166 (CUDA_DETECT_INSTALLED_GPUS)
  C:/DevDependencies/libtorch-win-shared-with-deps-latest/libtorch/share/cmake/Caffe2/public/utils.cmake:401 (cuda_select_nvcc_arch_flags)
  C:/DevDependencies/libtorch-win-shared-with-deps-latest/libtorch/share/cmake/Caffe2/public/cuda.cmake:325 (torch_cuda_get_nvcc_gencode_flag)
  C:/DevDependencies/libtorch-win-shared-with-deps-latest/libtorch/share/cmake/Caffe2/Caffe2Config.cmake:87 (include)
  C:/DevDependencies/libtorch-win-shared-with-deps-latest/libtorch/share/cmake/Torch/TorchConfig.cmake:68 (find_package)
  CMakeLists.txt:27 (find_package)


-- Configuring incomplete, errors occurred!
</code></pre>
<p>Does anyone manage to get libtorch working with C++23?</p>

ptrblck: <p>CUDA12 supports up to C++20 as described <a href="https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#c-cplusplus-language-support">here</a> so the limitation is expected.</p>

torchwang: <aside class="quote no-group" data-username="Te93" data-post="1" data-topic="182143">
<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/te93/48/61307_2.png" class="avatar"> Te93:</div>
<blockquote>
<p>Works fine with C++20 <code>set(CMAKE_CXX_STANDARD 20)</code> but not 23.</p>
</blockquote>
</aside>
<p>Can I compile PyTorch 2.0.1 or the nightly build with C++20 on the M1 Mac platform?</p>
Batchwise argmax

MUnique: <p>Hi,<br>
What is the best way to do a batchwise argmax on a tesnor? Let’s say I have a B * H * W tensor and I want to do an argmax on each H * W sample. I have to end up with a B * 2 tensor that has the argmax components of each sample stacked. Is a for loop torch.stack the only possible way?</p>

KFrank: <p>Hi M!</p>
<aside class="quote no-group" data-username="MUnique" data-post="1" data-topic="183174" data-full="true">
<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/m/d78d45/48.png" class="avatar"> MUnique:</div>
<blockquote>
<p>I have a B * H * W tensor and I want to do an argmax on each H * W sample.</p>
</blockquote>
</aside>
<p>Reshape your tensor of shape <code>[B, H, W]</code> into shape <code>[B, H * W]</code><br>
and call <code>.argmax (dim = 1)</code>.  Use the indices returned by <code>argmax()</code><br>
to set the per-sample max values to a <code>sentinel</code> value.  Reshape your<br>
tensor back to <code>[B, H, W]</code> and use <code>torch.where (t == sentinel)</code><br>
to get a tuple of length <code>B</code> of the per-sample “argmax components.”</p>
<p>You can stack this tuple into a tensor of shape <code>[B, 2]</code> if you want a<br>
tensor for the final result.</p>
<p>Best.</p>
<p>K. Frank</p>
Pytorch==1.6.0 installation error

Tony_stark: <p>I upgrade my cuda version to <code>8.0</code> and I try to using <code>pip</code> to install <code>torch==1.6.0</code> . According to official command<br>
I would get error:<br>
ERROR: Could not find a version that satisfies the requirement torch==1.6.0 (from versions: none)<br>
ERROR: No matching distribution found for torch==1.6.0<br>
WARNING: You are using pip version 21.1.2; however, version 21.3.1 is available.<br>
You should consider upgrading via the ‘D:\torch_pypi\venv\Scripts\python.exe -m pip install --upgrade pip’ command.</p>
Class which holds some tensors and can .to() itself

cwindolf: <p>I’m using torch to write some non neural net code, and I have something like:</p>
<pre><code class="lang-auto">class Worker:
    def __init__(self, fixed_matrix, fixed_neural_net):
        self.fixed_matrix = fixed_matrix
        self.fixed_neural_net = fixed_neural_net

    def do_work(self, data):
        # something with self.fixed_matrix,fixed_neural_net
</code></pre>
<p>I’d like to be able to use <code>worker.cuda()</code>, <code>worker.to("cuda:1")</code>, and things like this, and one approach would be to subclass <code>nn.Module</code> and use <code>self.register_buffer(...)</code> to store <code>fixed_matrix</code>, and <code>fixed_neural_net</code> is already a <code>Module</code> instance here (a neural net which is not training, and has requires_grad=False).</p>
<p>However, I don’t want all of the extra bells and whistles that <code>Module</code> brings with it related to NN training: things like <code>self.training</code>, <code>forward()</code>, the parameters, the forward and backward hooks, etc. To be clear: gradients will not be used at all in this setting.</p>
<p>I thought this kind of case might be common, so I was wondering if there is a simple way to just take the parts of <code>Module</code> which I want (really, all of the logic related to <code>_buffers</code> and <code>_modules</code>) and forget the rest. Or, maybe the rest is no big deal to have around? The main thing I don’t want to do is have to call <code>requires_grad_(False)</code> every time I initialize this Worker, I guess.</p>
How to calculate CIoU or DIoU loss only for certain unmasked boxes in a tensor and ignore the masked values?

Amish: <pre><code class="lang-auto"># bbox loss
bbox_labels = batch['bbox'][:, 1:]
bbox_masks = batch['bbox_mask'][:, 1:]

masked_bbox_preds = bbox_preds*bbox_masks
masked_bbox_labels = bbox_labels*bbox_masks

if self.config.bbox_loss == "smoothl1":
    box_loss = self.bbox_loss(masked_bbox_preds, masked_bbox_labels)
elif self.config.bbox_loss == "diou":
    masked_bbox_preds_xyxy = ops.box_convert(masked_bbox_preds, 'cxcywh', 'xyxy')
    masked_bbox_labels_xyxy = ops.box_convert(masked_bbox_labels, 'cxcywh', 'xyxy')
    box_loss = ops.distance_box_iou_loss(masked_bbox_preds_xyxy, masked_bbox_labels_xyxy, reduction='sum')
    bbox_masks_inv = (bbox_masks + 1) % 2
    box_loss -= bbox_masks_inv.sum()

box_loss = box_loss / (bbox_masks.sum() + self.eps)
</code></pre>
<p>This is a Transformer Decoder model in which one branch of the Decoder predicts the HTML structure sequence for a table image and the other predicts the bbox for corresponding cell tokens (‘&lt; td &gt;’, ‘&lt; td &gt;&lt; /td &gt;’, ‘&lt;td’). So, for all the other tokens, I have to mask those predictions and calculate loss only for the td tokens.</p>
<p>In this, DIoU gives a value of 1.0 for boxes which are [0.0,0.0,0.0,0.0]. So, I subtract the number of masked boxes from the total loss to keep it consistent however, the model is predicting random boxes in places where it should predict properly. I’m not sure if this approach is correct in terms of weights/gradient updates. Is there any other way to use DIoU/CIoU with masks?</p>
<p>CIoU straight away gives nan for [0.0,0.0,0.0,0.0] because it considers the aspect ratio also, so I couldn’t figure out how to fix that.</p>
<p>Edit:<br>
So for input [0.0,0.0,1.0,1.0] (in xyxy format) in box1 and box2, CIoU and DIoU both give 1.9e-7 which I’m assuming is coming from an epsilon somewhere. So, I converted the masked predictions to this, but still, after one step, the loss becomes nan.</p>

Amish: <p>Any input would be really helpful. I have to experiment and complete the project soon. I need to use a good bounding box loss function (for table cell bounding box) along with cross entropy (for the html token prediction). I experimented with smoothl1 loss but the the model isn’t able to learn the boxes properly whereas the token predictions are good.<br>
With the above technique I mentioned about diou, it did improve the bbox preds but still there is issue as I have mentioned.<br>
Another approach I tried was to keep reduction=‘none’ and then replace the ‘nan’ values with zero using torch.nan_to_num and then calculate the mean. But the loss isn’t converging like it should by using this method. Not sure what is the issue here</p>
Custom Handler Not starting due to Pydantic

dhx: <p>I am seeing the following error, when my TorchServe container is starting up.</p>
<p>I was able to spin up the TorchServer locally and submit requests successfully.</p>
<p>However - i see the error below when trying to do it through docker.</p>
<p>Any ideas?</p>
<pre><code class="lang-auto">-----Starting handler -----

Backend worker process died.
Traceback (most recent call last):
  File "/home/venv/lib/python3.9/site-packages/ts/model_service_worker.py", line 253, in &lt;module&gt;
    worker.run_server()
  File "/home/venv/lib/python3.9/site-packages/ts/model_service_worker.py", line 221, in run_server
    self.handle_connection(cl_socket)
  File "/home/venv/lib/python3.9/site-packages/ts/model_service_worker.py", line 184, in handle_connection
    service, result, code = self.load_model(msg)
  File "/home/venv/lib/python3.9/site-packages/ts/model_service_worker.py", line 131, in load_model
    service = model_loader.load(
  File "/home/venv/lib/python3.9/site-packages/ts/model_loader.py", line 135, in load
    initialize_fn(service.context)
  File "/home/model-server/tmp/models/72c9eb6e81f24828911500b7883601b0/custom_handler.py", line 55, in initialize
    self.ckpt_cfg = toMyConfig(self.ckpt_cfg)
  File "/home/model-server/tmp/models/72c9eb6e81f24828911500b7883601b0/custom_handler.py", line 30, in toMyConfig
    cfg = MyConfig.parse_obj(cfg)  # to MyConfig
  File "pydantic/main.py", line 526, in pydantic.main.BaseModel.parse_obj
  File "pydantic/main.py", line 341, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 1 validation error for MyConfig
exp_manager
  field required (type=value_error.missing)
</code></pre>
Pytorch geometric create custom dataset error:TypeError: expected str, bytes or os.PathLike object, not NoneType[posixpath.py]

CHAOWU: <p>Hi there,</p>
<p>I am new to PyG and facing with a error as below:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/b/d/bde64ba31c5aca512aa8dc6d64dae59057963639.jpeg" data-download-href="https://discuss.pytorch.org/uploads/default/bde64ba31c5aca512aa8dc6d64dae59057963639" title="螢幕截圖 2023-06-29 下午6.21.07"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/b/d/bde64ba31c5aca512aa8dc6d64dae59057963639_2_690x323.jpeg" alt="螢幕截圖 2023-06-29 下午6.21.07" data-base62-sha1="r5VE9ARm6tJFJzNQPw5tX9qiMGt" width="690" height="323" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/b/d/bde64ba31c5aca512aa8dc6d64dae59057963639_2_690x323.jpeg, https://discuss.pytorch.org/uploads/default/optimized/3X/b/d/bde64ba31c5aca512aa8dc6d64dae59057963639_2_1035x484.jpeg 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/b/d/bde64ba31c5aca512aa8dc6d64dae59057963639_2_1380x646.jpeg 2x" data-dominant-color="303030"><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">螢幕截圖 2023-06-29 下午6.21.07</span><span class="informations">1920×901 131 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>Hope anyone can help on this.</p>
<p>Best regards,<br>
Chao</p>

ptrblck: <p>Based on the error message it seems a path is expected while you are passing a <code>None</code> object. Check if <code>graphs</code> is <code>None</code> and make  sure it’s the expected object for your <code>CustomDataset</code>.</p>
<p>PS: it’s always better to post code snippets by wrapping it into three backticks ``` instead of posting pictures.</p>
Putting a tensor into a list or a dictionary row-by-row leads to high memory usage

Vyce: <p>We would like to ask a question about python and pytorch. We found that putting a tensor into a container like list or dict row by row will cause a much larger memory overhead (double to quadruple the size of the tensor itself). But we confirmed by comparing data_ptr that the container contains reference of storage instead of copy of storage. And we also confirmed that the size of container itself is not too big. So we are wondering where the memory is going. Is there any method to identity?</p>
<p>Here is the reproducible script.</p>
<pre data-code-wrap="py"><code class="lang-py">import sys

import psutil
import torch

MB = 10 ** 6
N = 10 ** 6


def get_memory_usage():
    return psutil.virtual_memory().used / MB


def main():
    m1 = get_memory_usage()
    print("Memory usage before: {:.1f} MB".format(m1))
    x = torch.randn(N, 128)
    m2 = get_memory_usage()
    print("Memory usage after creating x: {:.1f} MB".format(m2))
    print("Memory usage diff: {:.1f} MB".format(m2 - m1))
    print("Size of x: {:.1f} MB".format(x.element_size() * x.nelement() / MB))

    d = {}
    for i in range(len(x)):
        d[i] = x[i]

    for i in range(len(x)):
        assert d[i].data_ptr() == x[i].data_ptr(), "Data pointer mismatch"

    m3 = get_memory_usage()
    print("Memory usage after creating dict: {:.1f} MB".format(m3))
    print("Memory usage diff: {:.1f} MB".format(m3 - m2))

    # size of dict
    print("Size of dict: {:.1f} MB, {:.1f} MB".format(
        sys.getsizeof(d) / MB, len(d) * sys.getsizeof(d[0]) / MB))


if __name__ == "__main__":
    main()

</code></pre>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/4/2/42f9d76ffdb5117fe99689552d74bb50dcbb0855.png" data-download-href="https://discuss.pytorch.org/uploads/default/42f9d76ffdb5117fe99689552d74bb50dcbb0855" title="image"><img src="https://discuss.pytorch.org/uploads/default/original/3X/4/2/42f9d76ffdb5117fe99689552d74bb50dcbb0855.png" alt="image" data-base62-sha1="9yuNmeG7OX0crC49YPkkKPx1Xy5" width="690" height="270" data-dominant-color="131413"><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">699×274 8.86 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>

tkasarla: <p>I run into the same issue when saving a torch tensor to a dict row-by-row. The size of dict itself is very small. Did you figure out how this can be solved?</p>
What are the differences between the batched_nms calculation logic of torchvision 0.8.0 and the calculation logic of the nonmaxsuppression operator of ONNX?

IIIIIPP: <p>Hi, I find that when I run torchvision’s nms and onnx’s nms single operator using the same input, the output of the two operators is inconsistent, and the output of onnx’s nms is a subset of the output of torchvision’s nms. Can someone tell us the difference between the logic of calculation? In my knowledge, the calculation logic of nms is consistent, but the inconsistency of results is puzzling.</p>
"Could not find schema for aten::empty.memory_format" in libtorch

sjmerel2: <p>I’m trying to use libtorch to load a PyTorch model file from native code on Android. When I load the file, I get the following exception:</p>
<pre><code class="lang-auto">terminating with uncaught exception of type c10::Error: Could not find schema for aten::empty.memory_format ()
Exception raised from findSchemaOrThrow at /Users/steve/work/torch/pytorch/aten/src/ATen/core/dispatch/Dispatcher.cpp:131 (most recent call first):

</code></pre>
<p>I had previously encountered this same problem on iOS, and fixed it by specifying the “-all_load” flag to the linker.</p>
<p>Based on what I saw on iOS, my guess is that there is some static initializer for the tensor code that is getting stripped out and is not getting called. However, what I thought was the equivalent for clang on Android (“-force_load”) causes some additional link errors that I am struggling to fix.</p>
<p>Is there another way to force that initialization? Where in the libtorch code is this schema usually getting registered?</p>

sjmerel2: <p>Make sure you’re building the libraries using version 21 of the NDK, and then use something like this in the target_link_libraries section of your CMakeLists.txt file:</p>
<pre><code class="lang-auto">    -Wl,--gc-sections
    -Wl,--whole-archive
    ${TORCH_LIB_DIR}/libtorch.a
    ${TORCH_LIB_DIR}/libtorch_cpu.a
    -Wl,--no-whole-archive
    ${TORCH_LIB_DIR}/libc10.a
    ${TORCH_LIB_DIR}/libnnpack.a
    ${TORCH_LIB_DIR}/libXNNPACK.a
    ${TORCH_LIB_DIR}/libpytorch_qnnpack.a
    ${TORCH_LIB_DIR}/libpthreadpool.a
    ${TORCH_LIB_DIR}/libeigen_blas.a
    ${TORCH_LIB_DIR}/libcpuinfo.a
    ${TORCH_LIB_DIR}/libclog.a
    ${TORCH_LIB_DIR}/libVulkanWrapper.a
</code></pre>
Complex CNN error related to torch version?

spacemeerkat: <p>Thanks to <a href="https://discuss.pytorch.org/t/complex-valued-cnn-layers/148491/2">this</a> post, I see that complex convolutions are supported in <a href="https://github.com/pytorch/pytorch/issues/71108#issue-1098121850" rel="noopener nofollow ugc">this PR</a>.</p>
<p>But I’m struggling to get this working in my complex CNN. I’m encountering the following error which appears in a few posts on this forum:</p>
<blockquote>
<p>RuntimeError: “slow_conv2d_cuda” not implemented for ‘ComplexDouble’</p>
</blockquote>
<p>…which I’m assuming to be likely as a result of the torch version I’m using.</p>
<p>I’m wondering when the complex conv functionalities were rolled out as I’m struggling to pin it down to a specific release (possibly <a href="https://github.com/pytorch/pytorch/releases/tag/v1.13.0" rel="noopener nofollow ugc">1.13</a>?)</p>
<p>The machine I’m using is currently utilising torch version <code>1.10.1+cu102</code>. Am I being stupid and this version is before the appropriate release?</p>
<p>Many thanks for any help on this!</p>

spacemeerkat: <p>Update: it looks like it is a version issue, as I installed the latest PyTorch version and the error goes away.</p>
OSError: /usr/local/lib/python3.10/dist-packages/torchtext/lib/libtorchtext.so: undefined symbol: _ZN2at4

lgarcia: <p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/6/c/6cdc400cabd4a3e840b7ebc8733caf41c5484b04.png" data-download-href="https://discuss.pytorch.org/uploads/default/6cdc400cabd4a3e840b7ebc8733caf41c5484b04" title="Captura de pantalla (150)"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/6/c/6cdc400cabd4a3e840b7ebc8733caf41c5484b04_2_690x330.png" alt="Captura de pantalla (150)" data-base62-sha1="fx1rWnCC6NNZLB5OSbjYL7gQM4c" width="690" height="330" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/6/c/6cdc400cabd4a3e840b7ebc8733caf41c5484b04_2_690x330.png, https://discuss.pytorch.org/uploads/default/optimized/3X/6/c/6cdc400cabd4a3e840b7ebc8733caf41c5484b04_2_1035x495.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/6/c/6cdc400cabd4a3e840b7ebc8733caf41c5484b04_2_1380x660.png 2x" data-dominant-color="F5F6F8"><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">Captura de pantalla (150)</span><span class="informations">1544×740 46.1 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>
I´m facing this error in google colab.<br>
Ant help?<br>
Regards</p>
<aside class="onebox allowlistedgeneric" data-onebox-src="https://colab.research.google.com/drive/1ihE6jM3oV9HWOaNCs8cRY_GCVjbtBrU7?usp=sharing#scrollTo=vohUiWo-I2HQ">
  <header class="source">
      <img src="https://ssl.gstatic.com/colaboratory-static/common/ac0e6bae38aa2b5a52a4f6e10b43c43d/img/favicon.ico" class="site-icon" width="128" height="128">

      <a href="https://colab.research.google.com/drive/1ihE6jM3oV9HWOaNCs8cRY_GCVjbtBrU7?usp=sharing#scrollTo=vohUiWo-I2HQ" target="_blank" rel="noopener nofollow ugc">colab.research.google.com</a>
  </header>

  <article class="onebox-body">
    <img width="260" height="260" src="https://colab.research.google.com/img/colab_favicon_256px.png" class="thumbnail onebox-avatar">

<h3><a href="https://colab.research.google.com/drive/1ihE6jM3oV9HWOaNCs8cRY_GCVjbtBrU7?usp=sharing#scrollTo=vohUiWo-I2HQ" target="_blank" rel="noopener nofollow ugc">Google Colaboratory</a></h3>



  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>
Inject cusomized gradient from the output

Mehdi_Djellabi: <p>Here’s my problem:<br>
I have a loss function composed of two terms, the first of which is correct but the second results from a function that I have to integrate. This integral is (imo) intractable, but this isn’t really a problem since I have the expression for the gradient in this case (relative to the model output).<br>
So I’d like to calculate a partial loss, composed of the known term, and then when starting the backpropagation, add the gradient of the known loss to the known gradient I had beforehand.<br>
Here’s an example code:</p>
<pre><code class="lang-auto">
class FR_loss():
    
    def __init__(self,G,X,k):
        self.X = X
        self.G = G 
        self.k = k 
        
        self.dists = {ord_edge((u,v)) : torch.norm(self.X[v]-self.X[u])
         for u in range(len(self.G)) for v in range(u+1,len(self.G))}
        self.disp = self.compute_disp()

    def compute_disp(self):
        disp = dict()
        for v in self.G:
            D_v = 0 
            not_v = list(set(self.G.nodes()) - {v})
            for u in not_v:
                e_uv = (self.X[v]-self.X[u])/self.dists[ord_edge((u,v))]
                D_v += -((self.k**2)/self.dists[ord_edge((u,v))])*e_uv
            for u in self.G.neighbors(v):
                e_uv = (self.X[v]-self.X[u])/self.dists[ord_edge((u,v))]
                D_v += ((self.dists[ord_edge((u,v))]**2)/self.k)*e_uv
            disp[v] = D_v
        return disp
    
    def compute_remaining_grad(self,t,lr):
        grad_E_v_larger = torch.zeros((len(self.G),self.X.shape[1]))
        
        for v in self.G:
            not_v = list(set(self.G.nodes()) - {v})
            D_v = self.disp[v]
            if torch.norm(D_v) &gt; t : 
                grad_E_v_larger[v] += t*(D_v/torch.norm(D_v))
        
        return grad_E_v_larger*1./lr 
        
    def compute_loss_partial(self,t,lr):
        E = 0
        for v in self.G:
            E_v = 0
            not_v = list(set(self.G.nodes()) - {v})
            D_v = self.disp[v]
            if torch.norm(D_v) &lt; t : 
                for u in not_v : 
                    E_v += -(self.k**2)*torch.log(self.dists[ord_edge((u,v))]) 
                for u in self.G.neighbors(v):
                    E_v += (1./(3*self.k))*((self.dists[ord_edge((u,v))])**3)
            E += E_v
       
        return E*1./lr
</code></pre>
<p>Then I run :</p>
<pre><code class="lang-auto">def train_emb_FR(model, data, k, t, optimizer):
    
    torch.set_grad_enabled(True)
    model.train()
    G = nx_from_torch(data.edge_index)
    Z = model(data.x)
    Loss = FR_loss(G, Z,k)

    loss = Loss.compute_loss_partial(t, optimizer.defaults['lr'])
    remain_grad = Loss.compute_remaining_grad(t, optimizer.defaults['lr'])
    optimizer.zero_grad()
    
    part_gradients = torch.autograd.grad(loss, Z, retain_graph=True)[0]
    if loss == 0 : 
        Z.grad = remain_grad
    else : 
        Z.grad = part_gradients+remain_grad

    loss.backward()
    optimizer.step()
    return loss.item()
</code></pre>
<p>But it does not work the way i want it to…</p>
Torch.cuda.is_available() : False CUDA:12.1 [Solved]

mayur: <p>torch.utils.collect_env :<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/b/5/b5f10ae61ea0af2a20d4449fb8ccb7d1e85cec54.png" data-download-href="https://discuss.pytorch.org/uploads/default/b5f10ae61ea0af2a20d4449fb8ccb7d1e85cec54" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/b/5/b5f10ae61ea0af2a20d4449fb8ccb7d1e85cec54_2_466x500.png" alt="image" data-base62-sha1="pXwQUN8cUDjFYcBsi7TbOgIAyG0" width="466" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/b/5/b5f10ae61ea0af2a20d4449fb8ccb7d1e85cec54_2_466x500.png, https://discuss.pytorch.org/uploads/default/optimized/3X/b/5/b5f10ae61ea0af2a20d4449fb8ccb7d1e85cec54_2_699x750.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/b/5/b5f10ae61ea0af2a20d4449fb8ccb7d1e85cec54.png 2x" data-dominant-color="3C1931"><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">801×858 133 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>Can anyone please help.</p>

mayur: <p>nvidia-smi :<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/e/d/ed33737383ab80cfdc408a68659bf0eb42903bca.png" data-download-href="https://discuss.pytorch.org/uploads/default/ed33737383ab80cfdc408a68659bf0eb42903bca" title="image"><img src="https://discuss.pytorch.org/uploads/default/original/3X/e/d/ed33737383ab80cfdc408a68659bf0eb42903bca.png" alt="image" data-base62-sha1="xQnoprrWGgWpcUFI9uGbz6QfDom" width="690" height="381" data-dominant-color="3B1830"><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">823×455 53.7 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>

mayur: <p>nvcc --version :<br>
<img src="https://discuss.pytorch.org/uploads/default/original/3X/b/8/b87cee828673ac69c5f2d5335b01bdd3958bca69.png" alt="image" data-base62-sha1="qk3wcLEZ6LMSvhV9jeyE2nBP6ZP" width="583" height="119"></p>

mayur: <p>I’ve managed to solved this on my own.</p>
<p>I was initially trying to install using conda.<br>
I uninstalled pytorch and tried reinstalling using pip and this time everything worked perfectly.</p>
<p>This post may be closed now.</p>

Shiming_Wang: <p>Hi, Mayur, thanks for sharing your experience. I met the same problem here. But I cannot install pytorch==1.12.1 with cuda==12.1 by using pip. What you installed is still pytorch 1.12.1 or pytorch 2.1? If possible, could you please share your installation command? Thank you so much!</p>
Making Pytorch Docs offline

deva: <p>How do we download/make offline the pytorch docs?</p>

ptrblck: <p>You can find the instructions to build the docs locally <a href="https://github.com/pytorch/pytorch/blob/master/CONTRIBUTING.md#building-documentation">here</a>.</p>

nlgranger: <p>A bit late to the party but for anyone ending up here: PyTorch doc is available on <a href="https://devdocs.io" rel="noopener nofollow ugc">https://devdocs.io</a>, sadly only in version 1.8.0.</p>
GPU:A800 Driver:515 pyTorch:1.13.1 CUDA:11.7, Cudnn:8.5 ubuntu=22.04 liver server

swsongwei: <p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/f/3/f38662a1c3feaebbaa0c19f76978eaf7fe079558.jpeg" data-download-href="https://discuss.pytorch.org/uploads/default/f38662a1c3feaebbaa0c19f76978eaf7fe079558" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/f/3/f38662a1c3feaebbaa0c19f76978eaf7fe079558_2_690x393.jpeg" alt="image" data-base62-sha1="yKjWyubiZWenntcwQ8FzEey7huE" width="690" height="393" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/f/3/f38662a1c3feaebbaa0c19f76978eaf7fe079558_2_690x393.jpeg, https://discuss.pytorch.org/uploads/default/optimized/3X/f/3/f38662a1c3feaebbaa0c19f76978eaf7fe079558_2_1035x589.jpeg 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/f/3/f38662a1c3feaebbaa0c19f76978eaf7fe079558_2_1380x786.jpeg 2x" data-dominant-color="525151"><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">1710×974 192 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>
I have restarted the server, do any of my friends have experience in solving this problem?<br>
Thank you.</p>

ptrblck: <p>The driver failed to initialize and you have MIG enabled. I would recommend disabling MIG first and, if this doesn’t help, reinstalling the driver.<br>
You can also post code snippets by wrapping them into three backticks ``` instead of posting pictures.</p>
Creating a Dockerfile for a Custom Service - How to install local python packages in requirements.txt?

dhx: <p>I have a local python package which can be installed through poetry. From what I can see, we have to do a git clone of the repo first, and then install it?</p>
<p>Could someone please share some type of resource that explains how to do this properly?</p>
<p>It seems like this Dockerfile needs to be in the ML repo where the model pth file is stored. So that when the docker image is created, the same environment can be used to set up the docker.</p>
<pre><code class="lang-auto">FROM pytorch/torchserve:latest-cpu

USER root # why?

COPY ./model-server/requirements.txt .

RUN apt-get install -y git poetry # for some reason this fails because it cannot find package Poetry 

# however, the following would look like:
RUN git clone https://github.com/user/repo.git

WORKDIR /repo

RUN poetry install 


RUN python3 -m pip install --no-cache-dir -r requirements.txt
USER model-server # why?



COPY path/to/local_file path/in/image # [ for all required files]
USER root # why ?
RUN printf "\nservice_envelope=json" &gt;&gt; /home/model-server/config.properties
RUN printf "\ninference_address=http://0.0.0.0:7080" &gt;&gt; /home/model-server/config.properties
RUN printf "\nmanagement_address=http://0.0.0.0:7081" &gt;&gt; /home/model-server/config.properties
USER model-server # why?

EXPOSE 7080
EXPOSE 7081

RUN torch-model-archiver -f   --model-name model_v1 --version 1.0 --serialized-file=/home/model-server/model.pth --model-file=/home/model-server/model.py --handler=/home/model-server/custom_handler.py --extra-files=/home/model-server/config.json,/home/model-server/conf.yaml --export-path=/home/model-server/model-store

CMD ["torchserve",      "--ncs", "--start",      "--ts-config=/home/model-server/config.properties",      "--models",      "model_v1.mar",      "--model-store",      "/home/model-server/model-store"]
</code></pre>
How to control the gradient reduction manually when using DDP?

Hope_Light: <p>We know that when calling:<code>loss.backward</code> in DDP mode, the gradients of the model on each device will reduce automatically.</p>
<p>In my case, the model in each device will conduct different procedures (like training on different data distributions) and I want to see the effects of them by evaluating models on the valiadation set. After the evaluation step, the models on all devices should be synchronized as usual and the training goes to the next round.</p>
<p>To realize this, I need to prevent the gradient reduction when calling “loss.backward()”, I wonder whether there is way to control the gradient reducetion precedure manully? If possible, how to synchronize the model parameters efficiently later?</p>
How to split a Tensor based on class id

AlphaBetaGamma96: <p>Hi All,</p>
<p>Let’s say I have a Tensor of shape <code>[batch_size, num_input]</code> where I have 2 classes for my input data. How could I get the indices for each of the classes?</p>
<pre><code class="lang-auto">batch_size=100
num_input=4
 
data = torch.randint(0,2,size=(batch_size,num_input)) #fake data has 0 and 1 as the two classes.
</code></pre>
<p>Let’s say I had one example that was <code>[0,1,1,0]</code>, I’d want a function that returns <code>[0,3]</code> for class_id = 0 or <code>[1,2]</code> for class_id = 1. This is with the idea I could have <code>idx0</code> and <code>idx1</code> and then simply do <code>data0 = data[idx0]</code> and <code>data1 = data[idx1]</code>. Is this possible?</p>
<p>I’ve had a look at doing <code>(data==0).nonzero(as_tuple=True)</code>, however, there’s a few issues with this. For example, if my data contains only one class (it misses that data sample entirely), also I’ve tried getting this to work for batches of data, however, it doesn’t seem to broadcast. I did try using <code>torch.func.vmap</code>, however, <code>vmap</code> doesn’t support dynamical shapes!</p>
<p>Another thought I had was to use <code>torch.where(data==1, data, 0)</code>, but that leaves me with numerous rows filled with zeros. Is it possible to delete rows that are only filled with zeros?</p>
<p>Any help would be greatly appreciated!</p>

ptrblck: <aside class="quote no-group" data-username="AlphaBetaGamma96" data-post="1" data-topic="183094">
<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/a/3da27b/48.png" class="avatar"> AlphaBetaGamma96:</div>
<blockquote>
<p>Let’s say I had one example that was <code>[0,1,1,0]</code>, I’d want a function that returns <code>[0,3]</code> for class_id = 0 or <code>[1,2]</code> for class_id = 1. This is with the idea I could have <code>idx0</code> and <code>idx1</code> and then simply do <code>data0 = data[idx0]</code> and <code>data1 = data[idx1]</code>. Is this possible?</p>
</blockquote>
</aside>
<p>Yes, that’s possible with a direct comparison:</p>
<pre data-code-wrap="python"><code class="lang-python">x = torch.tensor([0, 1, 1, 0])
idx0 = x == 0
idx1 = x == 1

x[idx0]
# tensor([0, 0])
x[idx1]
# tensor([1, 1])
</code></pre>
Training too slow on pytorch 1.7

a_d: <p>Hello all,<br>
I have a retinanet model I am trying to train on a custom dataset which consists of around 2500 images in total. The problem is that it takes approximately 30 minutes per epoch(resnet 101 as a backbone). Is it supposed to be this slow?<br>
I have PyTorch 1.7, Cuda 11.1 installed on the system with cuDNN8.0.5.<br>
System specs - i7 9750 with RTX 2070. All hardware benchmarks run fine. Is the slow training due to cuda and cudnn mismatch and will it go away if I build from source?</p>

ptrblck: <p>I don’t know what you mean by “CUDA and cudnn mismatch”, but you could try to use e.g. the CUDA10.2 binaries and see, if you would get a similar performance.<br>
Also note, that your training might suffer other bottlenecks such as the data loading, which should be visible by a low GPU utilization in <code>nvidia-smi</code>.</p>

a_d: <p>Hi, thanks for replying.<br>
by mismatch I meant pytorch binaries are shipped with 11.0 whereas I have 11.1, 1.7 uses cuDNN version 8.0.3 whereas I have 8.0.5. I was wondering maybe that’s the reason for the slowdown.<br>
During training, nvidia-smi shows GPU usage as 90%</p>

ptrblck: <p>Your local CUDA and cudnn versions won’t be used if you install the binaries, so you might indeed want to build from source and see if the performance improves.</p>

a_d: <p>Oh okay,  will try that out</p>

Dicko: <p>hello there, I am having some trouble training a RetinaNet model with a ResNet-101 backbone. I have everything set up correctly I think, i’ve tried a few learning rates but the model does not seem to be learning. I wondfered if you had any issues like this and wondered if you managed to resolve it ?</p>
Algorithmic Trading Utilizing Computer Vision: Exploring the Intersection of Finance and Visual AI

jmon1994: <p>Our focus lies in leveraging computer vision algorithms to process and interpret visual data, such as candlestick charts, in real-time. By extracting meaningful patterns, trends, and anomalies from these visual representations, we aim to develop predictive models that can assist in making informed trading decisions.</p>

ptrblck: <p>Could you describe what the question is and how it’s related to PyTorch, please?</p>

jmon1994: <p>How can PyTorch be utilized in the development of computer vision algorithms for algorithmic trading?</p>

jmon1994: <p>I’m curious about leveraging CNNs to develop a visual learning bot capable of analyzing candlestick charts. The goal is to extend its capabilities to live charts.</p>
Negative values on DICE loss during training

trixiew: <p>I am training an Unet arch on Medical image semantic segmentation, supervised learning - images/masks and I am getting weird numbers for DICE loss</p>
<pre><code class="lang-auto">Vanila_UNet
Epoch [0]
Mean loss on train: -140.31943819224836 
Mean DICE on train: 1.7142934219089918 
Mean DICE on validation: 1.8950854703170916
Epoch [1]
Mean loss on train: -154.01165542602538 
Mean DICE on train: 1.8439450739097656 
Mean DICE on validation: 1.923283325048502
Epoch [2]
Mean loss on train: -155.57704811096193 
Mean DICE on train: 1.8617926383475962 
Mean DICE on validation: 1.9318473889899364
Epoch [3]
Mean loss on train: -156.61962712605794 
Mean DICE on train: 1.8733720566917649 
Mean DICE on validation: 1.933697909810023
Epoch [4]
Mean loss on train: -157.22541224161785 
Mean DICE on train: 1.8788127825940564 
Mean DICE on validation: 1.9533974303968433
</code></pre>
<p>I am using argumentation for normalisation. However, my mask stays min 0 and max 255. Image is normalised. In this scenario I get some numbers and the network is trying to actually do something, see image <a href="https://imgur.com/a/WqRhbaM" rel="noopener nofollow ugc">https://imgur.com/a/WqRhbaM</a></p>
<p>If I change when loading the data to dataloader and if I divide mask with 255., my predictions are all Mean DICE on train and Mean DICE on validation are 0, mean loss still negative but small negative ~ -0.025. The final NN prediction is blank image.</p>
<p>I assume the problem is in data loading:</p>
<pre><code class="lang-auto">class DukePeopleDataset(Dataset):

    def __init__(self, df, img_w, img_h):
        self.IMG_SIZE_W = img_w
        self.IMG_SIZE_H = img_h
        self.df = df
        self.in_channels = 3
        self.out_channels = 1
        
        self.transforms = self.define_transorms()
        
    def __len__(self):
        return len(self.df)

    def __getitem__(self, idx):
        image = cv2.resize(cv2.imread(self.df.iloc[idx, 0]), (self.IMG_SIZE_W, self.IMG_SIZE_H))
        mask = cv2.resize(cv2.imread(self.df.iloc[idx, 1],0), (self.IMG_SIZE_W, self.IMG_SIZE_H))
#         mask = mask/255.

        augmented = self.transforms(image = image,
                                      mask = mask)
        
        image = augmented['image']
        mask = augmented['mask']
        mask = mask.unsqueeze(0)
        
        return image, mask

    def get_dataframe(self):
        return self.df

    def define_transorms(self):
        transforms = A.Compose([
            A.HorizontalFlip(p=0.5),
            A.Normalize(p=1.0),
            ToTensorV2(),

        ])
        return transforms
</code></pre>

ptrblck: <p>I don’t know which dice loss implementation you are using but check which value ranges are expected for the model output (e.g. logits or probabilities) and the target.<br>
I would expect the target should contain values in <code>[0, 1]</code>.</p>

nikhil-nakhate: <p>Is there a DICE loss implementation that you recommend?</p>

trixiew: <p>Yes, there are plenty of implementations online. Search for code available on kaggle ‘image segmentation’</p>
Cannot find `convert_color_space`

function2: <p>When I use <code>to_grayscale</code>, there’s a deprecation warning:</p>
<pre><code class="lang-plaintext">UserWarning: The function `to_grayscale(...)` is deprecated in will be removed in a future release. Instead, please use `convert_color_space(..., color_space=datapoints.ColorSpace.GRAY)`.
</code></pre>
<p>However, I can’t find this function in the current code base (commit: 5178a2e2b19f9c133e3304bdca1a4601a77e76bf).</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/6/a/6ab7de5f155b61bb3e84b4d8b8b826c9ccc3b7be.png" data-download-href="https://discuss.pytorch.org/uploads/default/6ab7de5f155b61bb3e84b4d8b8b826c9ccc3b7be" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/6/a/6ab7de5f155b61bb3e84b4d8b8b826c9ccc3b7be_2_690x207.png" alt="image" data-base62-sha1="fe4y0QL0rU4f8pLwhQVYtVO6fqC" width="690" height="207" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/6/a/6ab7de5f155b61bb3e84b4d8b8b826c9ccc3b7be_2_690x207.png, https://discuss.pytorch.org/uploads/default/optimized/3X/6/a/6ab7de5f155b61bb3e84b4d8b8b826c9ccc3b7be_2_1035x310.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/6/a/6ab7de5f155b61bb3e84b4d8b8b826c9ccc3b7be_2_1380x414.png 2x" data-dominant-color="272D34"><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">2760×831 203 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>That’s a bit weird as I also cannot find it via <code>grep -r</code> in the repository (besides the two <code>replacement</code> strings).<br>
CC <a class="mention" href="/u/pmeier">@pmeier</a> in case this method is planned to be integrated or in case the <code>replacement</code> method shows a wrong function name.</p>

pmeier: <p>Sorry for the late reply. I was OOO.</p>
<hr>
<p>Thanks <a class="mention" href="/u/function2">@function2</a> for the report. This is indeed a bug. I’ve opened an issue on the <a href="https://github.com/pytorch/vision/issues/7700" rel="noopener nofollow ugc"><code>torchvision</code> repository</a> for this.</p>

pmeier: <p>The right thing to do is to use the <code>rgb_to_grayscale</code> function. I’ve just merged a <a href="https://github.com/pytorch/vision/pull/7702" rel="noopener nofollow ugc">patch</a> to fix  the warning. Starting with tomorrows nightly release, the warning will tell you the same.</p>

pmeier: <p>Ultimately, this kicked off a discussion whether we want to deprecate <code>to_grayscale</code> at all. We decided that the deprecation was a mistake and took it back. Meaning, you can continue using it and don’t have to migrate.</p>