How to run the code on the lab server

1. Tool preparation

You can download an xshell or secureCRT or other shell tools, connect to the server through ssh, and then control the server through the local computer terminal. Enter the host (Host) and port number (usually 22) for the connection method. As shown in the figure below,
insert image description here
after the connection is successful, the server can be controlled locally through the shell tool. As shown in the figure below,
insert image description here
prepare a tool filezilla to transfer the code in the local computer to the server. The whole process is also very simple, first connect to the server, and then upload the specified file, all are graphical interface operations, so I won’t go into details here.
insert image description here

2. After connecting to the server, first install the dependency packages needed to run the code. Generally, deep learning code can directly install an anaconda.

2.1 Install anacondacn

Refer to this blog post: Install anaconda

2.2 After installation, conda may not find the problem

Refer to this blog post: You can configure the environment variable to find the conda configuration environment variable.
After success, enter the following command to successfully view the conda version:

conda --version

3 Run the code

3.1 It is recommended to create a virtual environment and run the code in the virtual environment. Different virtual environments for different codes can avoid package conflicts.

Create a virtual environment (conda_name is the name of the virtual environment, xx is the version number of python created)

conda create -n codea_name python=x.x

Activate the environment (that is, enter the virtual environment you created, and then run the code in the virtual environment)

conda activate conda_name
//conda_name为自定义的名字

Installation package : Enter the code you need to run, cd into the requirements.txt file, and install the dependent packages in requirements.txt in batches

pip install -r requirements.txt

run code

python train.py

Module Not Found may occur.
If the running py file needs to refer to classes or functions in other py files in the same level directory, the system path in the py file needs to be changed (the upper level folder of the package that reports an error in this path needs to be absolutely The path can be viewed through the pwd command, such as /home/lh/FederatedLearning/pFedHN-main). Otherwise, Module NOT Found will be reported. Add the following two lines of code at the beginning of the file:

import sys
sys.path.append('/home/lh/FederatedLearning/pFedHN-main')

Reference: Conda creates a virtual environment and installs the dependency package set requirements.txt

3.2 Use the screen command to keep the code running after exiting the server connection

Create a screen window screen_name as a custom window name

screen -S screen_name

view screen window

screen -ls

Enter the screen window

screen -r screen_name

Exit the screen window (the background is still running)

快捷键 CTRL+A+D

End the current screen window

exit

Reference: screen command

4 Google Free Colab Server Cloud Resources

If you don't have server resources, you can use the free Colab server resources provided by Google. The operation method is very similar to jupyternotebook.
Introduce several commonly used commands
to view server resources

!nvidia-smi

insert image description here

Mount cloud disk

# 挂载Google云盘
from google.colab import drive
drive.mount('/content/drive')

Switch to the project directory

# 切换到要运行的项目目录下
import os
os.chdir("/content/drive/MyDrive/lab/pFedHN-main")

show current directory files

# 显示当前目录文件
!ls

run code

!python ./experiments/pfedhn/trainer.py

For specific use of colab, please see the link below:
Use GOOGLE COLAB to run deep learning projects

5 thanks

It is fate to meet in the vast knowledge, thank you for reading, I hope it can inspire you, thank you!

Guess you like

Origin blog.csdn.net/qq_44850917/article/details/128460680
Recommended