Auto DL platform rents a server (GPU) to run the code (alchemy) tutorial, bid farewell to the cumbersome SSH, the Jpyter that comes with the platform can be realized with a webpage

The Jupyter interface provided by the platform allows users to directly control the rented server on the web page.

No need to operate SSH directly.

After creating the instance, click Jupyter directly on the shortcut tool, and you are already operating the server you rented, and the connection with your server has been realized.

Open the black box of the terminal, and you are already using the Linux system of the server you rented, and you can already use the resources in the system you rented by entering Linux commands.

Environment construction:

The environment I set up at the beginning is the default environment of the server, which may be usable or not enough.

If it is not enough, you can build it through anconda:

To build, activate and view the environment on the server rented by the AutoDL platform, you can follow the steps below:

  1. Create and activate the environment

Tools such as conda or pip can be used to build the environment on the server rented by the AutoDL platform. The specific steps are as follows:

  • Use conda to create an environment:

conda create--name my_env python=3.7
source activate my_env

Here my_env is the environment name you specified, and python=3.7 is the Python version you specified. Activate the environment with the source activate my_env command.

  • Create a virtual environment with pip:

python -m venv my_env
source my_env/bin/activate

Here my_env is the environment name you specified. Activate the environment with the source my_env/bin/activate command.

After activating an environment, you can install and use the required Python libraries and tools in that environment.

  1. Tectonic environment

Take installing the PyTorch package as an example

You can use tools such as conda or pip to install PyTorch. The specific steps are as follows:

  • Install PyTorch using conda:

conda install pytorch torchvision cudatoolkit=10.1-c pytorch

The cudatoolkit=10.1 here is for CUDA 10.1 version. If you are using other versions of CUDA, you need to modify the corresponding parameters.

  • Install PyTorch using pip:

pip install torch torchvision

If you are using the GPU version of PyTorch, you need to install the corresponding tools such as CUDA and cuDNN.

  1. Check the environment

To view the environment, use the following command:

  • For conda environment:

conda info --envs

This lists all installed conda environments, along with information such as paths and Python versions for each environment.

  • For pip virtual environment:

source my_env/bin/activate
python -m pip list

这里的my_env是你指定的环境名称。使用python -m pip list命令列出该环境中

文件上传:

在Jupyter里有个按钮,点开就能选择本地的文件进行上传。

文件解压:

需要提前在服务器里安装一个解压缩软件

  • 对于Ubuntu/Debian系统:sudo apt-get install p7zip-full

  • 对于CentOS/Fedora系统:sudo yum install p7zip-full

  1. 安装完成后,你就可以在终端中使用7z解压缩软件进行文件的解压缩了。在终端中输入以下命令进行解压缩:要进入文件所属目录才行

7z x filename.7z

这里的filename.7z是你需要解压缩的文件名。

如果安装不了,可能是因为软件源出现了问题:

尝试使用apt-get update命令更新软件包源,并重新运行apt-get install

直接用这行命令解决:

sudo apt-get update

知识拓展:

更换软件源来解决问题。具体步骤如下:

  1. 打开终端,并输入以下命令备份原来的软件源列表:

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
  1. 输入以下命令打开软件源配置文件:

sudo nano /etc/apt/sources.list
  1. 将原来的软件源地址替换成其他可用的软件源地址。例如,如果你使用的是Ubuntu系统,可以参考Ubuntu官方文档更换软件源。在配置文件中加入新的软件源地址后,可以使用Ctrl+X键保存并退出。

  1. 更新软件包列表,使用以下命令更新软件包列表:

sudo apt-get update

跑模型:

单纯运行代码:

也就是在终端中直接运行。

打开控制台,

进入目标文件夹,

使用 python ***.py命令,

如果要运行的代码文件是python语言名叫***的话。

让代码在离线的情况下运行:

如果是在终端中直接运行的话,那么断开SSH连接时,程序就会停止。

也就是说断网或者关闭目前的Jupyter程序就会终止。

解决方法一:

  1. 启动训练程序,并使用nohup命令和&符号将程序放到后台运行。例如:

nohup python train.py &

这里的train.py是你的训练程序名称,nohub命令可以让程序在后台运行,并忽略所有挂起信号(SIGNUP).

其中&表示将程序放到后台运行,并输出日志到nohunp.out(自动生成)文件中。

  1. 如果需要查看训练日志,可以使用tail命令查看:

tail -f nohub.out

解决方法二:

  1. 使用tmux或screen等工具创建一个会话。

  • 如果你使用的是tmux,可以使用以下命令创建一个会话:

tmux new -s my_session_name
  • 如果你使用的是screen,可以使用以下命令创建一个会话:

screen -S my_session_name

这里的my_session_name是你指定的会话名称。

  1. 在会话中启动训练程序,例如:

python train.py

这样,训练程序将在会话中运行,即使你断开SSH连接或者退出终端,训练程序仍然会在后台继续运行。

  1. 如果你需要重新连接到AutoDL服务器并查看训练日志,可以使用以下命令重新连接到会话:

  • 如果你使用的是tmux,可以使用以下命令重新连接到指定的会话:

tmux attach -t my_session_name
  • 如果你使用的是screen,可以使用以下命令重新连接到指定的会话:

screen -r my_session_name

让程序终止运行:

方法一:

输入

sudo killall python

这个命令可以停止所有python程序的运行。

如果出现command not found错误可能是系统没装这个命令,

可以通过

sudo apt-get install psmisc

来安装

再不行就用:

sudo pkill python

同样可以停止所有python程序的运行

方法二:

  1. 找到正在运行模型的进程ID,使用以下命令查找:

ps aux | grep python

ps aux | grep train.py

这里的python是你使用的深度学习框架的解释器名称,例如TensorFlow和PyTorch都是使用python作为解释器。查找结果会显示正在运行的所有python进程及其进程ID。

如果把python换成train的话,就会列出所有正在运行的train进程。

  1. 使用kill命令停止模型的运行,例如:

kill -9 process_id

这里的process_id是你查找到的模型进程ID。

  1. 确认模型已经停止运行,你可以使用以下命令查看进程是否已经终止:

ps aux | grep python

如果模型的进程已经终止,将不会显示在查找结果中。

需要注意的是,使用kill命令可以强制停止模型的运行,但是这样可能会导致模型在停止前未保存的训练结果丢失。因此,在停止模型之前,建议保存训练结果和模型参数,以便以后继续训练或者使用。

路径问题:

pwd 命令查看当前路径

如果是绝对路径,那么一定是/root开头

Guess you like

Origin blog.csdn.net/weixin_52449030/article/details/129779129