项目内容介绍
详细介绍信息如下:
一、入门岛任务
1.1. linux基础知识
任务目标如下:
- 完成SSH连接与端口映射并运行
hellow_world.py
- 将linux基础命令在开发机上完成一遍
- 使用VSCODE远程连接开发机并创建一个conda环境
- 创建并运行
test.sh
文件
1.1.1. 创建开发机
1.1.2. 配置SSH连接与端口映射并运行hellow_world.py
测试ssh连接开发机
配置秘钥登录开发机
使用命令生成秘钥对
ssh-keygen -t rsa
在powershell终端中,查看生成秘钥信息
在首页——配置SSH KEY——添加生成的公钥信息。
在vscode中新建一个powershell终端,输入ssh登录命令,不需要输入密码直接登录开发机。即表示ssh密钥对配置成功。
配置端口映射
第一步:在开发机上创建一个web_demo
新建目录与文件
mkdir /test
cd /test/
touch hello_world.py
在hello_world.py
中添加以下内容
import socket
import re
import gradio as gr
# 获取主机名
def get_hostname():
hostname = socket.gethostname()
match = re.search(r'-(\d+)$', hostname)
name = match.group(1)
return name
# 创建 Gradio 界面
with gr.Blocks(gr.themes.Soft()) as demo:
html_code = f"""
<p align="center">
<a href="https://intern-ai.org.cn/home">
<img src="https://intern-ai.org.cn/assets/headerLogo-4ea34f23.svg" alt="Logo" width="20%" style="border-radius: 5px;">
</a>
</p>
<h1 style="text-align: center;">☁️ Welcome {get_hostname()} user, welcome to the ShuSheng LLM Practical Camp Course!</h1>
<h2 style="text-align: center;">😀 Let’s go on a journey through ShuSheng Island together.</h2>
<p align="center">
<a href="https://github.com/InternLM/Tutorial/blob/camp3">
<img src="https://oss.lingkongstudy.com.cn/blog/202406301604074.jpg" alt="Logo" width="20%" style="border-radius: 5px;">
</a>
</p>
"""
gr.Markdown(html_code)
demo.launch()
安装hello_world.py
运行所需的依赖,并运行脚本
pip install gradio==4.29.0
python hello_world.py
第二步:在本地使用浏览器测试web_demo是否可以访问
-
前提条件:vscode中自动配置了端口转发
-
手动配置端口映射的命令(注意:此命令没有回显,回车执行即可)
浏览器能够访问此页面,即表示成功。
1.1.3. 实操Linux基础命令
- 创建文件:可以使用
touch
命令创建空文件。 - 创建目录:使用
mkdir
命令。 - 目录切换:使用
cd
命令。 - 显示所在目录:使用
pwd
命令。 - 查看文件内容:如使用
cat
直接显示文件全部内容,more
和less
可以分页查看。 - 编辑文件:如
vi
或vim
等编辑器。 - 复制文件:用
cp
命令。 - 创建文件链接:用
ln
命令。 - 移动文件:通过
mv
命令。 - 删除文件:使用
rm
命令。 - 删除目录:
rmdir
(只能删除空目录)或rm -r
(可删除非空目录)。 - 查找文件:可以用
find
命令。 - 查看文件或目录的详细信息:使用
ls
命令,如使用ls -l
查看目录下文件的详细信息。 - 处理文件:进行复杂的文件操作,可以使用
sed
命令。
touch
# touch demo.py
# ls
demo.py
mkdir
# mkdir test
# ls
demo.py test
cd
# cd test
# pwd
/test/test
# cd ..
# pwd
/test
pwd
# pwd
/test/test
cat
# cat demo.py
this is a simple text
vim
# vim demo.py //进入后可修改文件
cp
# cp demo.py ./test1/
# cd test1/
# pwd
/study/test/test1
# ls
demo.py
复制目录
# cp -r /study/test/test1/ /study/
# cd /study/
# ls -ll
total 8
drwxr-xr-x 3 root root 4096 Jul 15 14:45 test
drwxr-xr-x 2 root root 4096 Jul 15 14:47 test1
ln
# ln -s /study/test/test1/demo.py ./
# ls -ll
total 4
lrwxrwxrwx 1 root root 25 Jul 15 14:49 demo.py -> /study/test/test1/demo.py
mv
# mv test/demo.py ./
# ls -ll
total 16
-rw-r--r-- 1 root root 9681 Jul 15 14:41 demo.py
drwxr-xr-x 2 root root 4096 Jul 15 14:50 test
rm
# rm -rf test1
rmdir
只能删除非空目录
# rmdir test
rmdir: failed to remove 'test': Directory not empty
y# mkdir test1
# rmdir test1
find
# find /study -name demo.*
/study/demo.py
ls
# ls -al
total 24
drwxr-xr-x 3 root root 4096 Jul 15 14:52 .
drwxr-xr-x 22 root root 4096 Jul 15 14:30 ..
-rw-r--r-- 1 root root 9681 Jul 15 14:41 demo.py
drwxr-xr-x 2 root root 4096 Jul 15 14:50 test
# ls -llh
total 16K
-rw-r--r-- 1 root root 9.5K Jul 15 14:41 demo.py
drwxr-xr-x 2 root root 4.0K Jul 15 14:50 test
sed
# echo "InternLM" > file
# cat file
InternLM
# sed -e 's/InternLM/InternLM yyds/g' file
InternLM yyds
# sed -n '/InternLM/p' file
InternLM
# cat file
InternLM
ps
# ps -aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.0 5040 4144 ? Ss 15:05 0:00 /bin/bash /start.sh
root 6 0.0 0.0 2888 1996 ? S 15:05 0:00 sh /share/.aide/script/start_aide.sh
root 8 0.0 0.0 3960 2332 ? Ss 15:05 0:00 cron
root 22 0.2 0.0 188696 81720 ? S 15:05 0:00 /usr/bin/python3 /usr/local/bin/jupyter-lab --ip=0.0.root 30 0.1 0.0 722008 65916 ? Sl 15:05 0:00 /opt/code-server/lib/node /opt/code-server /root --diroot 120 0.0 0.0 12192 3040 ? Ss 15:05 0:00 sshd: /usr/sbin/sshd [listener] 0 of 10-100 startups
root 143 0.2 0.0 928656 76280 ? Sl 15:05 0:00 /opt/code-server/lib/node /opt/code-server/out/node/eroot 177 0.7 0.0 4715572 29056 ? Sl 15:05 0:01 aide-app
root 229 0.5 0.0 443932 20004 ? Sl 15:05 0:01 ./cmscc --gpu_model any --daemon --stand_alone --mem_root 249 0.0 0.0 0 0 ? Z 15:05 0:00 [bash] <defunct>
root 250 0.0 0.0 5040 2804 ? S 15:05 0:00 /bin/bash -c cd /opt/frp && export http_proxy="" && .root 251 0.0 0.0 726924 18188 ? Sl 15:05 0:00 ./frpc -c ./frpc_0.toml
root 272 0.0 0.0 2696 672 ? S 15:05 0:00 tail -f /dev/null
root 433 0.0 0.0 13600 8812 ? Ss 15:05 0:00 sshd: root@pts/0
root 442 0.0 0.0 4116 3428 pts/0 Ss 15:05 0:00 -bash
root 445 0.0 0.0 4248 3532 pts/0 S 15:05 0:00 /bin/bash
root 3362 0.0 0.0 4368 3324 pts/0 S+ 15:09 0:00 tmux
root 3364 0.0 0.0 4764 3828 ? Rs 15:09 0:00 tmux
root 3365 0.0 0.0 4116 3372 pts/1 Ss 15:09 0:00 -bash
root 3369 0.0 0.0 4248 3548 pts/1 S 15:09 0:00 /bin/bash
root 3569 0.0 0.0 6140 2916 pts/1 R+ 15:09 0:00 ps -aux
top
top - 15:10:10 up 187 days, 19:00, 2 users, load average: 105.54, 102.80, 96.44
Tasks: 21 total, 1 running, 19 sleeping, 0 stopped, 1 zombie
%Cpu(s): 5.7 us, 2.0 sy, 0.0 ni, 61.4 id, 30.6 wa, 0.1 hi, 0.2 si, 0.0 st
MiB Mem : 2063348.+total, 14312.0 free, 72660.5 used, 1976376.+buff/cache
MiB Swap: 0.0 total, 0.0 free, 0.0 used. 1977071.+avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 6 root 20 0 2888 1996 1612 S 0.0 0.0 0:00.00 sh 8 root 20 0 3960 2332 1972 S 0.0 0.0 0:00.00 cron 22 root 20 0 188696 81720 18176 S 0.0 0.0 0:00.69 jupyter-lab 30 root 20 0 722008 65916 38152 S 0.0 0.0 0:00.49 node 120 root 20 0 12192 3040 2124 S 0.0 0.0 0:00.00 sshd 143 root 20 0 928656 76280 41036 S 0.0 0.0 0:00.64 node 177 root 20 0 4863292 29948 9976 S 0.0 0.0 0:02.23 aide-app 229 root 20 0 443932 20004 6992 S 0.0 0.0 0:01.53 cmscc 249 root 20 0 0 0 0 Z 0.0 0.0 0:00.01 bash 250 root 20 0 5040 2804 1416 S 0.0 0.0 0:00.01 bash 251 root 20 0 726924 18188 10216 S 0.0 0.0 0:00.08 frpc 272 root 20 0 2696 672 452 S 0.0 0.0 0:00.00 tail 433 root 20 0 13600 8812 7392 S 0.0 0.0 0:00.01 sshd 442 root 20 0 4116 3428 2980 S 0.0 0.0 0:00.00 bash 445 root 20 0 4248 3532 2904 S 0.0 0.0 0:00.00 bash 3362 root 20 0 4368 3324 2984 S 0.0 0.0 0:00.00 tmux: client 3364 root 20 0 4764 3952 3092 S 0.0 0.0 0:00.00 tmux: server 3365 root 20 0 4116 3372 2892 S 0.0 0.0 0:00.00 bash 3369 root 20 0 4248 3548 2920 S 0.0 0.0 0:00.00 bash 3997 root 20 0 6160 3320 2776 R 0.0 0.0 0:00.00 top
pgrep
# pgrep -u root
1
6
8
22
30
120
143
kill
# ps -aux |grep tmux
root 3364 0.0 0.0 4888 3984 ? Ss 15:09 0:00 tmux
# kill -9 3364
nvidia-smi相关命令
# nvidia-smi //查看GPU的摘要信息
Mon Jul 15 15:16:58 2024
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 535.54.03 Driver Version: 535.54.03 CUDA Version: 12.2 |
|-----------------------------------------+----------------------+----------------------+
| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|=========================================+======================+======================|
| 0 NVIDIA A100-SXM4-80GB On | 00000000:89:00.0 Off | 0 |
| N/A 56C P0 193W / 400W | 36955MiB / 81920MiB | 53% Default |
| | | Disabled |
+-----------------------------------------+----------------------+----------------------+
+---------------------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=======================================================================================|
+---------------------------------------------------------------------------------------+
GPU摘要信息中,重要内容如下:
- NVIDIA-SMI 535.54.03:GRID驱动版本
- Persistence-M:驱动常驻模式
- 0 NVIDIA A100-SXM4-80GB:0表示GPU的序号,A100表示GPU的类型
- 56C:表示温度
- 193W / 400W:表示当前功率与总功率
- 36955MiB / 81920MiB:表示占用显存与总显存
1.1.4. conda环境管理
# conda config --show //查看当前conda配置信息
# conda create -n studyllm python=3.10 //创建conda环境
# conda env list //查看当前环境有哪些虚拟环境
(base) # conda activate studyllm //进入指定虚拟环境
(studyllm) # conda deactivate //退出当前虚拟环境
# conda remove --name name --all //删除指定虚拟环境
# conda env export --name studyllm > studyllm.yml //导出指定虚拟环境
1.1.5. 创建并运行test.sh
在根目录下新建test.sh
文件
# cd /
# touch test.sh
# vim test.sh
文件内容如下:
#!/bin/bash
# 定义导出环境的函数
export_env() {
local env_name=$1
echo "正在导出环境: $env_name"
# 导出环境到当前目录下的env_name.yml文件
conda env export -n "$env_name" > "$env_name.yml"
echo "环境导出完成。"
}
# 定义还原环境的函数
restore_env() {
local env_name=$1
echo "正在还原环境: $env_name"
# 从当前目录下的env_name.yml文件还原环境
conda env create -n "$env_name" -f "$env_name.yml"
echo "环境还原完成。"
}
# 检查是否有足够的参数
if [ $# -ne 2 ]; then
echo "使用方法: $0 <操作> <环境名>"
echo "操作可以是 'export' 或 'restore'"
exit 1
fi
# 根据参数执行操作
case "$1" in
export)
export_env "$2"
;;
restore)
restore_env "$2"
;;
*)
echo "未知操作: $1"
exit 1
;;
esac
赋予文件可执行权限
# ls -ll
total 89
-rw-r--r-- 1 root root 17294 Nov 10 2023 NGC-DL-CONTAINER-LICENSE
-rw-r--r-- 1 root root 0 Jul 15 16:10 test.sh
# chmod +x test.sh
# ls -ll |grep test.sh
-rwxr-xr-x 1 root root 902 Jul 15 16:12 test.sh
执行脚本文件
(base) root@intern-studio-50076697:/# ./test.sh restore xtuner0.1.17
正在还原环境: xtuner0.1.17
EnvironmentFileNotFound: '/xtuner0.1.17.yml' file not found
环境还原完成。