hpc AI(2) 服务器环境部署AI模型
服务器使用指南slurm系统学习在服务器上部署Qwen3-0.6B模型并使用V100跑通infenerce.py1.通过修改原代码内部进行提问问题的修改2.可以在终端里面直接提问问题。——推理脚本编写3.运行过程当中实时监测V100的性能释放对每次运行进行简单性能分析。例如Input tokens: 20Generated tokens: 80Inference time: 1.23 sGeneration speed: 65.xx tokens/s在运行时打开另一个终端实时监测GPU的运行状态登录ssh-i密钥文件路径-p端口用户名登录节点申请gpusrun-pgpu--gresgpu:1-t2:00:00--ptybash查看剩余时间squeue-j$SLURM_JOB_ID-o%L从登录节点进入计算节点1.检查python环境1.1虚拟环境创建python3-mvenv路径# --module 跑**模块**# 告诉解释器去找到这个模块并执行它 可以是标准库模块、第三方包也可以是包里的子模块激活source虚拟环境名 如.venv/bin/activate1.2安装依赖pytorchtransformermodelscopeacceleratepipinstalltransformers accelerate modelscope sentencepiece tiktokena. 检查python3-cimport torch, transformers, accelerate, modelscope, sentencepiece, tiktoken; print(torch, torch.__version__); print(transformers, transformers.__version__); print(modelscope, modelscope.__version__); print(accelerate, accelerate.__version__)确认 torch 能识别到 GPUpython3-cimport torch; print(cuda available:, torch.cuda.is_available()); print(device count:, torch.cuda.device_count()); print(device name:, torch.cuda.get_device_name(0) if torch.cuda.is_available() else N/A)b. 依赖版本导出(requirements.txt)只导出相关依赖版本在项目目录中执行pip freeze|grep-iE^(torch|torchvision|torchaudio|transformers|modelscope|accelerate|sentencepiece|tiktoken)requirements.txt生成后查看确认内容catrequirements.txt预期torch2.8.0cu128 torchvision0.23.0cu128 torchaudio2.8.0cu128 transformers4.xx.x modelscope1.xx.x accelerate1.xx.x sentencepiece0.xx.x tiktoken0.xx.x2.编写推理脚本在终端执行catinference.py然后直接输入你的 Python 代码。输入完成后按Ctrl D保存并退出。之后可以用cat inference.py检查内容2.1 修改代码内部进行提问2.15 在终端中提问2.2 实时监测与性能分析实时监测V100的性能释放 | 实时监测GPU的运行状态对每次运行进行简单性能分析3.实时监测原终端squeue-u用户名记下任务id——JOBID新终端srun--overlap--jobid你的JOBID--ptybash开启监测朴素版nvidia-smi-l刷新间隔秒数高级版用到一个工具安装pip install nvitop运行nvitop建议同样装一个虚拟环境进行隔离参数nvitop-mauto# 自动选择监控模式默认nvitop--interval5# 每 5 秒刷新跑训练时更友好nvitop-mgpu# 只看 GPU 信息简洁模式常用命令删除目录rm-rf文件路径cdcdqwen-proj激活qwen-envsourceqwen-env/bin/activatenvitop-envsourcenvitop-env/bin/activatesqueue-urecruit20