question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

make_grid broken with mps device Tensors, whole grid is the 'first' image

See original GitHub issue

šŸ› Describe the bug

When calling make_grid on Tensor and List of Tensors where the device in ā€˜mps’ it returns a grid where all the Tensors are the same.

Simple example create a venv and activate cd into the venv directory install the nightlies pip3 install --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu

unzip the attached zip file, it contains a python script and two images. validate the python script and run it.

from PIL import Image
from torchvision.utils import make_grid
import torchvision.transforms as transforms
import torch
 

img1 = Image.open('00035.png')
img2 = Image.open('00036.png')

transform = transforms.Compose([
    transforms.PILToTensor()
])


t_img1 = transform(img1).to(torch.device("mps"), dtype=torch.float32)  / 256.0
t_img2 = transform(img2).to(torch.device("mps"), dtype=torch.float32)  / 256.0

grid = make_grid([t_img1, t_img2], nrow=1)

gridImage =  transforms.ToPILImage()(grid.cpu());

gridImage.save('mps_grid.png')

t_img1 = transform(img1).to(torch.device("cpu"), dtype=torch.float32)  / 256.0
t_img2 = transform(img2).to(torch.device("cpu"), dtype=torch.float32)  / 256.0

grid = make_grid([t_img1, t_img2], nrow=1)

gridImage =  transforms.ToPILImage()(grid.cpu());

gridImage.save('cpu_grid.png')

It generate two images, you’ll see the cpu_grid image are the two images vertically stacked, the mps_grid image has the same image vertically stacked twice.

make_grid_bug.zip

Versions

PyTorch version: 1.13.0.dev20220901 Is debug build: False CUDA used to build PyTorch: None ROCM used to build PyTorch: N/A

OS: macOS 12.5.1 (arm64) GCC version: Could not collect Clang version: 13.1.6 (clang-1316.0.21.2.5) CMake version: version 3.22.4 Libc version: N/A

Python version: 3.10.4 (main, May 10 2022, 03:52:14) [Clang 13.0.0 (clang-1300.0.29.30)] (64-bit runtime) Python platform: macOS-12.5.1-arm64-arm-64bit Is CUDA available: False CUDA runtime version: No CUDA GPU models and configuration: No CUDA Nvidia driver version: No CUDA cuDNN version: No CUDA HIP runtime version: N/A MIOpen runtime version: N/A Is XNNPACK available: True

Versions of relevant libraries: [pip3] numpy==1.23.2 [pip3] torch==1.13.0.dev20220901 [pip3] torchaudio==0.13.0.dev20220901 [pip3] torchvision==0.14.0.dev20220901 [conda] Could not collect

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Vargolcommented, Sep 4, 2022

I’ve edited the code, but it will be a while before I can test the edit is right, looks like a reference to the zip file split a line in half.

0reactions
datumboxcommented, Sep 4, 2022

Thanks for raising it at PyTorch Core. I believe the issue is there so I’ll close this issue to avoid duplicates. I’ll keep an eye on the other issue but if it turns out the problem is on TorchVision’s end, feel free to reopen.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[MPS] einsum returns incorrect matmul result on first ... - GitHub
I believe it was broken at least as far back as 1.13.0.dev20220826 (from which I upgraded today to see if this was fixed)....
Read more >
make_grid — Torchvision main documentation - PyTorch
Make a grid of images. Parameters: tensor (Tensor or list) – 4D mini-batch Tensor of shape (B x C x H x W)...
Read more >
Why does torchvision.utils.make_grid() return copies of the ...
imshow() given that it is supposed to take in a 2D array, not a 3D one as grid clearly is. import torch import...
Read more >
Pytorch make_grid() function - Medium
Pytorch make_grid() function. Display training images in a grid is an important data visualization task in deep learning, specifically computerĀ ...
Read more >
tf.device | TensorFlow v2.11.0
Used in the notebooks Ā· Customization basics: tensors and operations Ā· Solve GLUE tasks using BERT on TPUĀ ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found