pytorch / pytorch

Tensors and Dynamic neural networks in Python with strong GPU acceleration
https://pytorch.org
Other
78.9k stars 21.27k forks source link

Add windows support please #494

Closed jf003320018 closed 6 years ago

jf003320018 commented 7 years ago

I think pytorch should add Windows support. Other deep learning frameworks, like tensorflow, theano and mxnet, all support Windows. I only use Windows in my work. So I want to know whether pytorch will support Windows in future.

peterjc123 commented 7 years ago

There're some remaining longs in the csrc that caused this problem. I replaced almost all of them into int64_t except the one in the template definition of python_function.cpp and then the problem was solved. BTW: All of the test cases passed including CUDA except multiprocessing.

darthdeus commented 7 years ago

@tylergenter I just tried compiling your fork on Python 3.5 (anaconda) with VS2015 and am getting test failures and a bunch of warnings.

and then Cannot open include file: 'TH.h' and LINK : fatal error LNK1181: cannot open input file 'c:\dev\pytorch\torch\lib\tmp_install\lib\libopenblas.lib' [C:\dev \pytorch\torch\lib\build\TH\TH.vcxproj]

edit: I found compiled binaries of OpenBLAS here http://www.openblas.net/, any chance those might work instead of compiling them ourselves via cygwin?

magic282 commented 7 years ago

It seems that @peterhj has successfully built and run pytorch. I also tested it with opennmt. So will pytorch provide official Windows support next? Thanks.

Matrixio commented 7 years ago

my platform base windows, still waiting pytorch windows version.

peterjc123 commented 7 years ago

I've built a conda package of PyTorch for Windows 10 x64, Anaconda3(Python 3.5/3.6) and CUDA 8.0. Use this command to install if you want.

# for CPU only package (also for AMD and Intel Graphics since these GPUs are unsupported)
conda install -c peterjc123 pytorch-cpu

# for Windows 10 and Windows Server 2016, CUDA 8
conda install -c peterjc123 pytorch

# for Windows 10 and Windows Server 2016, CUDA 9
conda install -c peterjc123 pytorch cuda90

# for Windows 7/8/8.1 and Windows Server 2008/2012, CUDA 8
conda install -c peterjc123 pytorch_legacy

Note that the support for sm_20 and sm_30 has been dropped, so some old cards can't use PyTorch any more. If you fail to import torch, try to install it in a new virtual environment like this:

conda create -n test python=3.6
activate test

Use it with caution, the multiprocessing part is broken so you need to wrap the main code with the following code if you use GPU and DataLoader.

if __name__ == '__main__':

If you can understand Chinese, here is my tutorial.

andy-gh commented 7 years ago

I just installed the build from peterjc123 - it's working! Note that if you try to use the package in Python 3.6.0, you will get an error upon import. Once I upgraded to 3.6.1 everything ran smoothly. This seems to be a common issue

lantiga commented 7 years ago

I confirm the build by @peterjc123 is working. Great job!

soumith commented 6 years ago

this is great @peterjc123 !!!

Neltherion commented 6 years ago

Congratulations to @peterjc123 for his great effort. I just hope the Developers would start showing some love towards Windows after this...

peterjc123 commented 6 years ago

@ywwbill I don't have any PCs with Windows 7 presently. So maybe someone that can build it successfully can upload a package. BTW my code is hosted here. The tutorial (in Chinese) for building it is here. @Neltherion Yes, we need official support for Windows by the official dev team!

apaszke commented 6 years ago

Well we're not going to be officially supporting Windows, just because none of us has experience with developing Windows libraries, we don't have machines for setting up Windows contbuilds, etc. Still, we're going to accept PRs that fix Windows compatibility.

CodesInChaos commented 6 years ago

Doesn't the above windows build prevent 32 bit builds on every platform? (assuming those ever worked)

soumith commented 6 years ago

32-bit builds've never worked, and pytorch/torch has never correctly supported 32-bit.

shingte commented 6 years ago

Is there a windows build of torchvision?

selimarikan commented 6 years ago

@shingte If you are using Anaconda, after activating your environment, you can directly use conda install torchvision -c soumith

outterback commented 6 years ago

@tyathalae This results in

(dev) C:\Users\Oscar\Anaconda3>conda install --channel soumith torchvision
Fetching package metadata .............

PackageNotFoundError: Package missing in current win-64 channels:
  - torchvision

The repository only hosts an osx and a linux version. Do you have a suggestion for getting around this?

bordingj commented 6 years ago

@outterback: just pip install torchvision

outterback commented 6 years ago

D'oh. Thank you @bordingj .

emulvihill commented 6 years ago

I want to thank everybody who helped with this! It's working well AFAICT. Hopefully it will be rolled into the official build.

Moondra commented 6 years ago

Hi guys, is there a link to the unofficial build for Windows?

saulthu commented 6 years ago

Thanks for the work done :). Hopefully the changes made by @tylergenter, @peterjc123 and others here will be merged to the main repo soon so the Windows support (though not official) is not left behind.

magic282 commented 6 years ago

@saulthu Agree!

emulvihill commented 6 years ago

@Moondra Maybe I am not understanding what you're asking. But the method to install the Windows build is above,, namely: conda install -c peterjc123 pytorch=0.1.12 Once that's done you can optinally add torchvision with: pip install torchvision

Moondra commented 6 years ago

@emulvihill Thank you =). Yeah I wanted to know how to install pytorch.;I was thinking I need to download a .whl file

peterjc123 commented 6 years ago

After reinstalling one of the unused PCs into Windows 8.1, I compiled a package for legacy windows versions such as Windows 7, 8/8.1 and Server 2008/2012. You can install that through the command below.

conda install -c peterjc123 pytorch_legacy

P.S. still needs CUDA 8.0 and Anaconda3(Python 3.6.1)

soumith commented 6 years ago

@peterjc123 you are doing really great work. i want to get pytorch master to be windows ready and then i can setup circle-ci contbuilds, atleast for release candidates. did you have to make significant changes to master to compile pytorch on windows? what do you think is the best plan to merge these back

peterjc123 commented 6 years ago

The changes mainly fall into four categories:

  1. data type conversions like long to int64_t
  2. Windows-specific scripts like build_all.bat
  3. Windows-specific C++ codes or libs like libshm-windows
  4. Windows-specific python codes helps finding DLLs

There's no big problem for merging, but i can't confirm that works on Linux/Mac. Maybe i can try creating a PR and see whether the code works on Linux/Mac OS. If it works, then the Windows branch can be moved into the main repo. Finally, the Windows branch can be merged into the master branch. The PR is #1786 for your information.

danche354 commented 6 years ago

@peterjc123 Hi, thanks for your works!! It helps me a lot. But I find that the functional doesn't have some common function like cosine similarity, etc. Will the conda package update?

peterjc123 commented 6 years ago

@danche354 No, there won't be new conda packages until the Windows branch is merged into the pytorch master branch.

ET-CS commented 6 years ago
$ conda install -c peterjc123 pytorch=0.1.12

The following NEW packages will be INSTALLED:

    pytorch: 0.1.12-py36_0.1.12cu80 peterjc123

Proceed ([y]/n)? y

pytorch-0.1.12 100% |###############################| Time: 0:03:58   2.04 MB/s

Kudos! Like a charm!

Thank you @tylergenter @peterjc123 and everybody else envolved. great work!

artdana commented 6 years ago

What about pip?

magic282 commented 6 years ago

Hi, recently I want to map the entire Anaconda folder to a Windows cluster. But it reports an error:

Traceback (most recent call last):
  File "test.py", line 21, in <module>
    input_emd = torch.cat((wb, bb), dim=2)
  File "Z:\user\v\Anaconda3\lib\site-packages\torch\autograd\variable.py", line 837, in cat
    return Concat.apply(dim, *iterable)
  File "Z:\user\v\Anaconda3\lib\site-packages\torch\autograd\_functions\tensor.py", line 287, in forward
    return torch.cat(inputs, dim)
RuntimeError: cuda runtime error (8) : invalid device function at D:\users\v-qizhou\pytorch\pytorch\torch\lib\THC\THCGeneral.c:833
THCudaCheck FAIL file=D:\users\v\pytorch\pytorch\torch\lib\THC\THCGeneral.c line=833 error=8 : invalid device function

The test code is:

# CUDA TEST
import torch
from torch.autograd import Variable
from torch import nn
x = torch.Tensor([1.0])
xx = x.cuda()
print(xx)

# CUDNN TEST
from torch.backends import cudnn
print(cudnn.is_acceptable(xx))

word_embedding = nn.Embedding(10, 300).cuda()
bio_embedding = nn.Embedding(10, 32).cuda()
# a batch of 2 samples of 4 indices each
word_input = Variable(torch.LongTensor([[1,2,4,5],[4,3,2,9]]).cuda())
bio_input = Variable(torch.LongTensor([[1,2,4,5],[4,3,2,9]]).cuda())
wb = word_embedding(word_input)
bb = bio_embedding(bio_input)

input_emd = torch.cat((wb, bb), dim=2)
print(input_emd.size())
loss = input_emd.sum()
print(loss)
loss.backward()

Is there any idea about this error? Thanks.

selimarikan commented 6 years ago

@magic282 What are the outputs of print(xx) and print(cudnn.is_acceptable(xx)) ? Sounds like either CUDA configuration is wrong or you have a very old GPU.

magic282 commented 6 years ago

@tyathalae The output of print(cudnn.is_acceptable(xx)) is True. I compiled the package on a windows server 2012 R2 with K40, and deploy it on M40, which seems not to be very old.

ngimel commented 6 years ago

If you compiled it for K40 (compute capability 3.5) without specifying TORCH_CUDA_ARCH_LIST to include M40 (compute capability 5.2), that would explain what you are seeing. export TORCH_CUDA_ARCH_LIST="3.5 5.2" before compiling (or however it is done on Windows).

devinbostIL commented 6 years ago

To the official developers of PyTorch, I just want to point out that if you were to decide to find a way to officially support Windows, you would gain tremendous momentum and interest with this project because TensorFlow doesn't support Windows and Theano doesn't handle multi-GPU on Windows.

devinbostIL commented 6 years ago

Is something blocking the merge of the Windows branch into master?

magic282 commented 6 years ago

@ngimel Thank you! I will try.

fmassa commented 6 years ago

@devinbostIL There are still changes that needs to be fixed in the PR https://github.com/pytorch/pytorch/pull/1786

apaszke commented 6 years ago

The main blocker is that the PR has a few commits that have 26k lines changed. It's impossible for us to review. We can merge it once someone splits it into smaller, reviewable parts (think at least independent commits of size <1k lines)

devinbostIL commented 6 years ago

Was that the result of the PR adding: #1408 ? I'm looking at: Pull 1786

devinbostIL commented 6 years ago

I'm running Windows 10 x64 with CUDA 7.5 and Python 3.6.1, and I ran: conda install -c peterjc123 pytorch=0.1.12 from a new conda environment, and I was able to run:

# CUDA TEST
import torch
from torch.autograd import Variable
from torch import nn
x = torch.Tensor([1.0])
xx = x.cuda()
print(xx)

# CUDNN TEST
from torch.backends import cudnn
print(cudnn.is_acceptable(xx))

word_embedding = nn.Embedding(10, 300).cuda()
bio_embedding = nn.Embedding(10, 32).cuda()
# a batch of 2 samples of 4 indices each
word_input = Variable(torch.LongTensor([[1,2,4,5],[4,3,2,9]]).cuda())
bio_input = Variable(torch.LongTensor([[1,2,4,5],[4,3,2,9]]).cuda())
wb = word_embedding(word_input)
bb = bio_embedding(bio_input)

input_emd = torch.cat((wb, bb), dim=2)
print(input_emd.size())
loss = input_emd.sum()
print(loss)
loss.backward()

without any errors (to my astonishment).

magic282 commented 6 years ago

@devinbostIL Thanks for your test. I can also run this test on my K40 server. The error occurs on the M40 cluster node. I guess it is my build option problem since I install a fresh anaconda and directly install the peterjc123 conda package and it can be deployed on the cluster node.

LyubomyrD commented 6 years ago

Hello. I am looking for no GPU pytorch version (for studying purpose). Are there any modifications for this case in the following command? conda install -c peterjc123 pytorch=0.1.12

andytimm commented 6 years ago

@LyubomyrD You should be fine with that command. The PyTorch tutorials are all pretty clear on how/when things are shifted over to the GPU, so you can just install as usual, and avoid those steps.

Phylliida commented 6 years ago

I made a precompiled binaries for PyTorch with CUDA for Python 3.5 on Windows x64 here if you guys are interested.

KP-Zhang commented 6 years ago

@Phylliida Thank you for your contribution.

ghost commented 6 years ago

@devinbostIL What do you mean TensorFlow doesn't support Windows?

devinbostIL commented 6 years ago

@DeepLearningJohnDoe I stand corrected. It looks like TensorFlow finally supports Windows, which surprises me because I remember they were having major issues with Bazel's heavy requirements on symlinks.

magic282 commented 6 years ago

Hope pytorch can support Windows officially later. :smile: