Windows install the latest version of detector2 (0.6)

1. Environment:

win10 64,anaconda3,python3.8,VS2019

2. conda creates a new environment

CONDA create - N torch (environment name) python==3.8
activate torch
By the way, conda adds the image source of Tsinghua, which is faster

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/

3. Install CUDA and cudnn

You can download it on the official website according to the traditional old method, or a big man uploaded Baidu cloud: CUDA and cudnn . You can also use conda to download and install directly according to your computer driver. Download the official website of various versions of pytorch: Previous PyTorch Versions | PyTorch

## I used this
pip install torch==1.8.1+cu111 torchvision==0.9.1+cu111 torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html

Refer to: Install cuda and cudnn in conda virtual environment and solve PIP install or Python setup Py install installs the installation package into the global environment (Part 1.2)- Know

Verify that:

import  torch
#Returns the current device index
# torch.cuda.current_device()
#Returns the number of GPU s
# torch.cuda.device_count()
#Returns the gpu name. The device index starts from 0 by default
# torch.cuda.get_device_name(0)
#cuda available
# torch.cuda.is_available()

# pytorch view cuda version
# Since the whl installation package names of pytorch are the same, it is difficult to distinguish which version is based on cuda.
# print(torch.version.cuda)

# Determine whether pytorch supports GPU acceleration
# print (torch.cuda.is_available())


# [PyTorch] check whether your computer is ready for GPU acceleration (CUDA)
# Then on the computer ready for CUDA, cuda:0 will be output
# On computers without CUDA, the output is: cpu
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
print(device)

4. Install other libraries: cocoapi, fvcore, etc

1. Install cythpon first

pip install Cython -i https://pypi.tuna.tsinghua.edu.cn/simple
2. Install cocoapi

click GitHub - philferriere/cocoapi: Clone of COCO API - Dataset @ http://cocodataset.org/ - with changes to support Windows build and python3 Download and then execute the following instructions

pip install Cython -i https://pypi.tuna.tsinghua.edu.cn/simple
cd coco/PythonAPI
python setup.py build_ext --inplace
python setup.py build_ext install


(2) conda installs fvcore and ninja

conda install -c fvcore -c iopath -c conda-forge fvcore

## conda install ninja error!!!!

Error will be reported: subprocess CalledProcessError: Command ‘[‘ninja‘, ‘-v‘]‘ returned non-zero exit status 1.

1. Doubt ninja is not safe: choose ninja win Zip download. Releases · ninja-build/ninja (github.com)

2. cuda version is incorrect. cuda is not automatically installed during pip installation. Change conda:

conda install pytorch==1.8.0 torchvision==0.9.0 torchaudio==0.8.0 cudatoolkit=10.2 -c pytorch

Error:

error: Setup script exited with error: SandboxViolation: mkdir('C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\easy_install-pzhrecod\\easydict-1.9\\build', 511) {}

The package setup script has attempted to modify files on your system
that are not within the EasyInstall build area, and has been aborted.

This package cannot be safely installed by EasyInstall, and may not
support alternate installation locations even if you run its setup
script by hand.  Please inform the package's author and the EasyInstall
maintainers to find out if a fix or workaround is available.

So enter optional features in the run to enable the sandbox function.

Solution 2: windows built-in linux wsl middle run code

5 steps to build wsl2+cuda+docker to solve the problem of windows deep learning development - Zhihu (zhihu.com)https://zhuanlan.zhihu.com/p/408403790?utm_source=wechat_session&utm_medium=social&utm_oi=763742012275986432&utm_campaign=shareopn matters needing attention:

  • Windows development Edition (i.e. OS build) from 20211 to 20215 will fail to start WSL virtual machine. NVIDIA Drivers for CUDA on WSL does not support windows open 20211-20221. If the current host is these versions, be sure to decide whether to go down.
  • No one can guarantee whether the future updates of Microsoft and Nvidia are fully available. Please turn off Windows automatic update and make a full system backup.
  • The host cannot install Docker Desktop, which conflicts with the virtual machine docker. (uninstall the docker originally installed in windows)
  • Microsoft official tutorial: Enable NVIDIA CUDA on WSL 2 | Microsoft Docs

Problems I encountered:

/sbin/ldconfig.real: /usr/lib/wsl/lib/libcuda.so.1 is not a symbolic link 

Find the answer:

/usr/lib/wsl/lib/libcuda.so.1 is not a symbolic link · Issue #5663 · microsoft/WSL · GitHub

​​This is specifically for Nvidia CUDA in WSL 2 with the Windows Insider Preview on the Dev Channel. I followed this guide after I had Windows Insider Preview on Dev Channel set up: Enable NVIDIA CUDA on WSL 2 | Microsoft Docs​​​​​

According to Microsoft's official reply:

Hi! We've identified this issue as a duplicate of another one that already exists in this repository. This specific instance is being closed in favor of tracking the concern over on the referenced thread.

Thanks for your report!

I first look at the system kernel

C:\Users\Administrator> wsl cat /proc/version
Linux version 5.4.72-microsoft-standard-WSL2 (oe-user@oe-host) (gcc version 8.2.0 (GCC)) #1 SMP Wed Oct 28 23:40:43 UTC 2020

The official tutorial says:

For these features, you need a kernel version of 5.10.43.3 or higher. You can check the version number by running the following command in PowerShell.

So update the system kernel

How to update the Linux kernel of Win10 WSL2 - know many features of WSL2 of Windows 10, which brings better integration than traditional virtual machine and host; At the same time, the support of vscode follows up quickly. For developers, the step of installing Linux on bare metal is almost eliminated. Problem if you install a distribution according to the official documentation and download the pagehttps://zhuanlan.zhihu.com/p/355606922

  1. Find the kernel update installation file msi released by Microsoft https://www.catalog.update.microsoft.com
  2. Completely shut down the current WSL and update the kernel - run WSL as an administrator - shutdown; Run the file downloaded in step 2 to complete the kernel update;

2, Install docker and NVIDIA docker

This needs to be installed through the command line. I started using Docker Desktop and found problems. If Docker Desktop is used, it needs to be uninstalled.

Refer to this tutorial to install docker and NVIDIA docker

The ubuntu subsystem of WSL2 of Windows system installs docker and NVIDIA docker to call GPU_SUNbrightness blog - CSDN blog_ nvidia-docker windows

Test whether docker is successfully installed and whether it can access GPU resources

sudo docker run --gpus all nvcr.io/nvidia/k8s/cuda-sample:nbody nbody -gpu -benchmark    

Display:

Run "nbody -benchmark [-numbodies=<numBodies>]" to measure performance.
        -fullscreen       (run n-body simulation in fullscreen mode)
        -fp64             (use double precision floating point values for simulation)
        -hostmem          (stores simulation data in host memory)
        -benchmark        (run benchmark to measure performance)
        -numbodies=<N>    (number of bodies (>= 1) to run in simulation)
        -device=<d>       (where d=0,1,2.... for the CUDA device to use)
        -numdevices=<i>   (where i=(number of CUDA devices > 0) to use for simulation)
        -compare          (compares simulation results running once on the default GPU and once on the CPU)
        -cpu              (run n-body simulation on the CPU)
        -tipsy=<file.bin> (load a tipsy model file for simulation)

NOTE: The CUDA Samples are not meant for performance measurements. Results may vary when GPU Boost is enabled.

> Windowed mode
> Simulation data stored in video memory
> Single precision floating point simulation
> 1 Devices used for simulation
GPU Device 0: "Turing" with compute capability 7.5

> Compute 7.5 CUDA device: [NVIDIA GeForce RTX 2060 with Max-Q Design]
30720 bodies, total time for 10 iterations: 68.014 ms
= 138.754 billion interactions per second
= 2775.083 single-precision GFLOP/s at 20 flops per interaction
Through the output information, you know that you can correctly access GPU resources.

Three points must be noted:

1. It is necessary to add windows insider program. Other methods can install wsl, but cannot access gpu resources.

2. Download the nvidia driver dedicated to wsl and install it in windows.

3. Delete the desktop docker in windows

tips:

WSL2 has no systemd service by default and needs to be installed by itself.

System D is a Linux system tool, which provides a complete solution for system startup and management. It has become the standard configuration for most distributions.

According to Linux convention, the letter d is the abbreviation of daemon. The meaning of the name system d is to protect the whole system.

System D is not a command, but a set of commands, involving all aspects of system management.

WLS2 installation systemd

Download the zip file of the warehouse and unzip it to any path in windows (E:/script /) as an example

Link: file · master · mirrors / DamionGans / ubuntu-wsl2-systemd-script · GitCode

Execute command

cp -r /mnt/e/script ~
cd ~/script/ubuntu-wsl2-systemd-script-master
bash ubuntu-wsl2-systemd-script.sh


Verify installation results

cz@PC-20201218TQUE:~/script/ubuntu-wsl2-systemd-script-master$ systemctl --version
systemd 245 (245.4-4ubuntu3.4)
+PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD +IDN2 -IDN +PCRE2 default-hierarchy=hybrid

reference resources: wsl2 configuration enables systemd one click script | Feng (ukiyo.top)https://blog.ukiyo.top/post/9214/

Download Anaconda3-5.3.1-Linux-x86_64.sh, installed in wsl2

bash Anaconda3-2020.02-Linux-x86_64.sh

Note the path in the box, that is, the path of conda. We need to add it to the environment variable.

  • Edit profile
sudo vim /etc/profile
  • Configure the environment variables such as conda, which is the path mentioned above, and write it to bin.

At the bottom of the document, add the following sentence:

export PATH=/home/cz/anaconda3/bin:$PATH
  • Reload environment variables
source /etc/profile
  • Check whether it is successful. Enter python to see if it is in anaconda environment.
Python 3.7.0 (default, Jun 28 2018, 13:15:42)
[GCC 7.2.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

. . . . . . . . .

Additional bonus:

WSL2 installs GUI and uses XRDP to realize connection (including Chinese operation) - Jianshu (jianshu.com)

Keywords: Windows TensorFlow Pytorch

Added by Ruchi on Thu, 03 Feb 2022 13:22:03 +0200