当前位置:网站首页>Server create virtual environment run code

Server create virtual environment run code

2022-06-26 14:17:00 AC doesn't know the depth

One 、 Preface

I am busy running code on the server recently

Learn and accumulate some experience and skills

It is used to record and share with you

Two 、 Create a virtual environment to run code

I will use an example as a template , After learning , Delete again

Will not occupy everyone's server

1、 Connect to the server

For example, my connection method is :ssh -p Your number username-host

2、 Creating a virtual environment

Here I take one Code For example

 Insert picture description here
Creating a virtual environment

conda create -n KDDocRE python==3.7.4

3、 Enter the virtual environment

conda activate KDDocRE

 Insert picture description here

4、 install cuda

conda install cudatoolkit=10.2

If the speed is a little slow, you can consider replacing Tsinghua source

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

5、 install PyTorch

Here are two ways to install

pip3 install torch torchvision torchaudio 

 perhaps 

conda install pytorch torchvision torchaudio cudatoolkit=10.2 -c pytorch

Either way , But be sure to confirm your version number

Official website ad locum
 Insert picture description here

6、 install Transformer

pip install transformers==4.8.2

Here's the reader's attention , If the third-party library is not followed by the version number

The latest version will be installed by default

If you have already installed another version

Consider installing the specified version again

Previous versions will be uninstalled automatically ( Figure 2 )

 Insert picture description here
 Insert picture description here

7、 install numpy

pip install numpy==1.19.4

 Insert picture description here

8、 install apex

This third-party library is difficult to install

git clone https://github.com/NVIDIA/apex
cd apex
pip install -v --disable-pip-version-check --no-cache-dir --global-option="--cpp_ext" --global-option="--cuda_ext" ./

If there is any error, please refer to this article article

 Insert picture description here

9、 install opt-einusm

pip install opt_einsum==3.3.0

 Insert picture description here

10、 install axial-attention

pip install axial_attention==0.6.1

 Insert picture description here

11、 install ujson

pip install ujson

 Insert picture description here

12、 install tqdm

pip install tqdm

13、 Run code

All the above environments have been configured

Next you can use pycharm Open the entire file

I still take the above project as an example

 Insert picture description here
This is what it looks like when it's opened

And then use pycharm The remote connection server starts running code happily

Remote connection server Here

How to run the code

In general projects READ.md There will be introductions
 Insert picture description here

13、 Out of the environment

conda deactivate

14、 View the current list of virtual environments

conda env list

15、 Delete environment

conda remove -n KDDocRE

So since , We have completed the environment creation , Run code , Delete environment and other operations

You can practice with your own projects

原网站

版权声明
本文为[AC doesn't know the depth]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/177/202206261316476522.html