99re热这里只有精品视频,7777色鬼xxxx欧美色妇,国产成人精品一区二三区在线观看,内射爽无广熟女亚洲,精品人妻av一区二区三区

PyTorch Windows 常見問題

2020-09-16 14:44 更新

原文:PyTorch Windows 常見問題

從源頭建造

包括可選組件

Windows PyTorch 支持兩個組件:MKL 和 MAGMA。 以下是使用它們構建的步驟。

REM Make sure you have 7z and curl installed.


REM Download MKL files
curl https://s3.amazonaws.com/ossci-windows/mkl_2018.2.185.7z -k -O
7z x -aoa mkl_2018.2.185.7z -omkl


REM Download MAGMA files
REM cuda100/cuda101 is also available for `CUDA_PREFIX`. There are also 2.4.0 binaries for cuda80/cuda92.
REM The configuration could be `debug` or `release` for 2.5.0\. Only `release` is available for 2.4.0.
set CUDA_PREFIX=cuda90
set CONFIG=release
curl -k https://s3.amazonaws.com/ossci-windows/magma_2.5.0_%CUDA_PREFIX%_%CONFIG%.7z -o magma.7z
7z x -aoa magma.7z -omagma


REM Setting essential environment variables
set "CMAKE_INCLUDE_PATH=%cd%\\mkl\\include"
set "LIB=%cd%\\mkl\\lib;%LIB%"
set "MAGMA_HOME=%cd%\\magma"

加快 Windows 的 CUDA 構建

Visual Studio 當前不支持并行自定義任務。 或者,我們可以使用Ninja并行化 CUDA 構建任務。 只需輸入幾行代碼即可使用它。

REM Let's install ninja first.
pip install ninja


REM Set it as the cmake generator
set CMAKE_GENERATOR=Ninja

一鍵安裝腳本

您可以看看這組腳本。 它將為您帶路。

延期

CFFI 擴展

CFFI Extension 的支持是試驗性的。 在 Windows 下啟用它通常需要兩個步驟。

首先,在Extension對象中指定其他libraries以使其在 Windows 上構建。

ffi = create_extension(
    '_ext.my_lib',
    headers=headers,
    sources=sources,
    define_macros=defines,
    relative_to=__file__,
    with_cuda=with_cuda,
    extra_compile_args=["-std=c99"],
    libraries=['ATen', '_C'] # Append cuda libaries when necessary, like cudart
)

其次,這里是“ extern THCState *state;導致的外部符號狀態(tài)無法解析”的工作場所

將源代碼從 C 更改為 C ++。 下面列出了一個示例。

#include <THC/THC.h>
#include <ATen/ATen.h>


THCState *state = at::globalContext().thc_state;


extern "C" int my_lib_add_forward_cuda(THCudaTensor *input1, THCudaTensor *input2,
                                        THCudaTensor *output)
{
    if (!THCudaTensor_isSameSizeAs(state, input1, input2))
    return 0;
    THCudaTensor_resizeAs(state, output, input1);
    THCudaTensor_cadd(state, output, input1, 1.0, input2);
    return 1;
}


extern "C" int my_lib_add_backward_cuda(THCudaTensor *grad_output, THCudaTensor *grad_input)
{
    THCudaTensor_resizeAs(state, grad_input, grad_output);
    THCudaTensor_fill(state, grad_input, 1);
    return 1;
}

Cpp 擴展

與前一個擴展相比,這種擴展具有更好的支持。 但是,它仍然需要一些手動配置。 首先,您應該打開 x86_x64 VS 2017 的交叉工具命令提示符。 然后,您可以開始編譯過程。

安裝

在 Win-32 頻道中找不到軟件包。

Solving environment: failed


PackagesNotFoundError: The following packages are not available from current channels:


- pytorch


Current channels:
- https://conda.anaconda.org/pytorch/win-32
- https://conda.anaconda.org/pytorch/noarch
- https://repo.continuum.io/pkgs/main/win-32
- https://repo.continuum.io/pkgs/main/noarch
- https://repo.continuum.io/pkgs/free/win-32
- https://repo.continuum.io/pkgs/free/noarch
- https://repo.continuum.io/pkgs/r/win-32
- https://repo.continuum.io/pkgs/r/noarch
- https://repo.continuum.io/pkgs/pro/win-32
- https://repo.continuum.io/pkgs/pro/noarch
- https://repo.continuum.io/pkgs/msys2/win-32
- https://repo.continuum.io/pkgs/msys2/noarch

PyTorch 在 32 位系統(tǒng)上不起作用。 請使用 Windows 和 Python 64 位版本。

為什么 Windows 沒有 Python 2 軟件包?

因為它不夠穩(wěn)定。 在我們正式發(fā)布之前,有一些問題需要解決。 您可以自己構建。

導入錯誤

from torch._C import *


ImportError: DLL load failed: The specified module could not be found.

該問題是由于缺少基本文件引起的。 實際上,除了 VC2017 可再發(fā)行和一些 mkl 庫,我們幾乎包含了 PyTorch 的 conda 軟件包所需的所有基本文件。 您可以通過鍵入以下命令來解決此問題。

conda install -c peterjc123 vc vs2017_runtime
conda install mkl_fft intel_openmp numpy mkl

至于 wheel 軟件包,由于我們沒有打包一些庫和 VS2017 可再發(fā)行文件,因此請確保手動安裝它們。 可以下載 VS 2017 可再發(fā)行安裝程序。 而且您還應該注意安裝 Numpy。 確保它使用 MKL 而不是 OpenBLAS。 您可以輸入以下命令。

pip install numpy mkl intel-openmp mkl_fft

另一個可能的原因可能是您使用的是沒有 NVIDIA 顯卡的 GPU 版本。 請用 CPU 之一替換您的 GPU 軟件包。

from torch._C import *


ImportError: DLL load failed: The operating system cannot run %1.

這實際上是 Anaconda 的上游問題。 當您使用 conda-forge 頻道初始化環(huán)境時,就會出現(xiàn)此問題。 您可以通過此命令修復 intel-openmp 庫。

conda install -c defaults intel-openmp -f

用法(并行處理)

沒有 if 子句保護的并行處理錯誤

RuntimeError:
       An attempt has been made to start a new process before the
       current process has finished its bootstrapping phase.


   This probably means that you are not using fork to start your
   child processes and you have forgotten to use the proper idiom
   in the main module:


       if __name__ == '__main__':
           freeze_support()
           ...


   The "freeze_support()" line can be omitted if the program
   is not going to be frozen to produce an executable.

multiprocessing的實現(xiàn)在 Windows 上有所不同,Windows 使用spawn代替fork。 因此,我們必須用 if 子句包裝代碼,以防止代碼多次執(zhí)行。 將代碼重構為以下結構。

import torch


def main()
    for i, data in enumerate(dataloader):
        # do something here


if __name__ == '__main__':
    main()

并行處理錯誤“管道破裂”

ForkingPickler(file, protocol).dump(obj)


BrokenPipeError: [Errno 32] Broken pipe

當子進程在父進程完成發(fā)送數(shù)據(jù)之前結束時,就會發(fā)生此問題。 您的代碼可能有問題。 您可以通過將 DataLoadernum_worker減小為零來調試代碼,然后查看問題是否仍然存在。

并行處理錯誤“驅動程序關閉”

Couldn't open shared file mapping: <torch_14808_1591070686>, error code: <1455> at torch\lib\TH\THAllocator.c:154


[windows] driver shut down

請更新您的圖形驅動程序。 如果這種情況持續(xù)存在,則可能是圖形卡太舊或計算量太大。 請根據(jù)此帖子更新 TDR 設置。

CUDA IPC 操作

THCudaCheck FAIL file=torch\csrc\generic\StorageSharing.cpp line=252 error=63 : OS call failed or operation not supported on this OS

Windows 不支持它們。 像對 CUDA 張量執(zhí)行并行處理之類的操作無法成功,有兩種選擇。

1.不要使用multiprocessing。 將 DataLoadernum_worker設置為零。

2.改為共享 CPU 張量。 確保自定義DataSet返回 CPU 張量。

以上內容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號