microsoft / DirectML

DirectML is a high-performance, hardware-accelerated DirectX 12 library for machine learning. DirectML provides GPU acceleration for common machine learning tasks across a broad range of supported hardware and drivers, including all DirectX 12-capable GPUs from vendors such as AMD, Intel, NVIDIA, and Qualcomm.
MIT License
2.18k stars 288 forks source link

Pytorch 3D Convolution Error #375

Open Darustc4 opened 1 year ago

Darustc4 commented 1 year ago

I was trying to make 3D convolutions work with DirectML with the following snippet:

import numpy as np
import torch
import torch.nn as nn
import torch_directml as tdml

dml = tdml.device()

tensor = torch.tensor(np.random.normal(0, 1, (10, 1, 128, 128, 128)).astype(np.float32)).to(dml)

test = nn.Sequential(
    nn.Conv3d(1, 8, kernel_size=3, stride=1, padding=1),
    nn.BatchNorm3d(8),
    nn.ReLU(),
    nn.MaxPool3d(kernel_size=2, stride=2)
).to(dml)

for i in range(10000):
    out = test(tensor)
print("It works!")

But I get the following error: RuntimeError: input must be 4-dimensional

I have tried switching the layer to use 2D operations and removing 1 dimension from the tensor and it works no problem. Is this a bug with the 3D operations? Is it not implemented? If not, could you give me some pointers so that I can try to implement it/fix it and make a PR? I'm happy to help.

Adele101 commented 1 year ago

Thank you for submitting this issue. While I can't provide a timeline for resolution as the moment, please know that your feedback is valuable to us. We will follow up once we can review this issue.

dmenig commented 12 months ago

I have the same issue.

ratkiller98 commented 2 months ago

@fdwr @jstoecker Hi, I am wondering if there has been any improvement whatsoever for Pytorch directml. Using version 0.2.3.dev240715 and the timm_3d library for standard deep learning convolutional networks, I always the get

File ~\AppData\Roaming\Python\Python310\site-packages\torch\nn\modules\conv.py:605 in _conv_forward return F.conv3d( RuntimeError: input must be 4-dimensional

no matter which model I use. But I can readily use the same models run on CPU or image models using 2D convolution with torch-directml. I believe implementing 3D convolutions is much needed. This is one of the main areas of computer vision with large computational requirements and is needed for both 3D volumetric and video processing models.

fdwr commented 2 months ago

Hi, I am wondering if there has been any improvement whatsoever for Pytorch directml

@smk2007 and @linnealovespie work on the PyTorch-on-DML fork and would know more (Justin and I are more DirectML.dll experts), but I heard PyTorch-on-DML recently got many updates (release date unknown).

I believe implementing 3D convolutions is much needed.

Sheil might know directly if that was in those pending updates.

If not, could you give me some pointers so that I can try to implement it/fix it and make a PR? I'm happy to help.

Sheil, is the PyTorch fork not open source? Just like https://github.com/microsoft/tensorflow-directml, I'd expect an equivalent https://github.com/microsoft/pytorch-directml repo.

dmenig commented 2 months ago

Still very interested in this

ratkiller98 commented 1 month ago

@smk2007 and @linnealovespie work on the PyTorch DML fork and would know more (Justin and I are more DirectML.dll experts), but I heard PyTorch recently got many updates to use DML.

'3dConv's were broken from the start. With tensorflow-directml no longer being updated, torch-directml was the only way we could use Radeon/ARC GPU acceleration for model training.

Sheil, is the PyTorch fork not open source? Just like https://github.com/microsoft/tensorflow-directml, I'd expect an equivalent https://github.com/microsoft/pytorch-directml repo.

Quite interesting because we are redirected here for raising issues either way.