Ubuntu+Tesla V100环境配置

系统基本信息

`nvidia-smi'

nvidia-smi 470.182.03 driver version:470.182.03 cuda version: 11.4

查看系统体系结构

复制代码
uname -a
  • UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

下载miniconda

https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/?C=M\&O=A

https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-latest-Linux-x86_64.sh

shell 复制代码
wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-latest-Linux-x86_64.sh

注意路径,用bash命令去安装。

认真看安装过程提示信息,需要按Enter (回车键)或者输入yes,(如果输入yes时,不小心输多了,就按control和退格键删除),

(1)看到more就是按空格键翻页查看协议,按q退出

(2)接受协议,输入yes

(3)默认安装路径,按enter

(4)会询问是否需要初始化,输入yes

(5)显示安装已完成的提示信息

激活刚安装完成的软件

一般安装软件完成后需要重启,在Linux叫激活,有两种方式,第一种是重新登录服务器,第二种是输入以下命令:

shell 复制代码
source ~/.bashrc
##比较常用

配置conda镜像地址

shell 复制代码
conda config --add channels r 
conda config --add channels conda-forge 
conda config --add channels bioconda

#(1)下面这四行配置清华大学的conda的channel地址,国内用户推荐
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --set show_channel_urls yes
##配置清华镜像,四句代码一起复制粘贴到服务器
​
# (2)下面四行配置北京外国语大学的conda的channel地址
conda config --add channels https://mirrors.bfsu.edu.cn/anaconda/pkgs/main/ 
conda config --add channels https://mirrors.bfsu.edu.cn/anaconda/cloud/conda-forge/ 
conda config --add channels https://mirrors.bfsu.edu.cn/anaconda/cloud/bioconda/ 
conda config --set show_channel_urls yes

查看配置镜像结果

配置镜像完成后会出现一个.condarc 文件,会在 ~/.condarc 文件中 写入以下内容

安装pytorch

复制代码
conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 cudatoolkit=11.3 -c pytorch

安装huggingface&离线下载LLama2并在本地运行全流程

配置所需环境

尝试过 torch 1.12.1,发生报错,
module 'torch' has no attribute 'fx'

故从头开始,配置torch 2.1.0成功。

shell 复制代码
conda create -n hfllama2 python=3.10.13
conda activate hfllama2
shell 复制代码
# 从官网上找的,尽管和系统有些不匹配,但是work
pip install torch==2.1.0 torchvision==0.16.0 torchaudio==2.1.0 --index-url https://download.pytorch.org/whl/cu118
shell 复制代码
pip install transformers

最终用到的完整的包版本如下(很简洁):

text 复制代码
Package            Version
------------------ ------------
accelerate         0.24.1
certifi            2022.12.7
charset-normalizer 2.1.1
filelock           3.9.0
fsspec             2023.10.0
huggingface-hub    0.19.4
idna               3.4
Jinja2             3.1.2
MarkupSafe         2.1.3
mpmath             1.3.0
networkx           3.0
numpy              1.24.1
packaging          23.2
Pillow             9.3.0
pip                23.3.1
psutil             5.9.6
PyYAML             6.0.1
regex              2023.10.3
requests           2.28.1
safetensors        0.4.0
setuptools         68.2.2
sympy              1.12
tokenizers         0.15.0
torch              2.1.0+cu118
torchaudio         2.1.0+cu118
torchvision        0.16.0+cu118
tqdm               4.66.1
transformers       4.35.2
triton             2.1.0
typing_extensions  4.4.0
urllib3            1.26.13
wheel              0.41.3

llama2离线下载

https://hf-mirror.com/

shell 复制代码
huggingface-cli download --token hf_XX你的tokenXX --resume-download --local-dir-use-symlinks False meta-llama/Llama-2-7b-hf --local-dir Llama-2-7b-hf

运行官方测试代码

python 复制代码
from transformers import AutoTokenizer
import transformers
import torch

model = "Llama-2-7b-hf" #注意,这里改成下载好的离线模型的相对路径了

tokenizer = AutoTokenizer.from_pretrained(model)
pipeline = transformers.pipeline(
    "text-generation",
    model=model,
    torch_dtype=torch.float16,
    device_map="auto",
)

sequences = pipeline(
    'I liked "Breaking Bad" and "Band of Brothers". Do you have any recommendations of other shows I might like?\n',
    do_sample=True,
    top_k=10,
    num_return_sequences=1,
    eos_token_id=tokenizer.eos_token_id,
    max_length=200,
)
for seq in sequences:
    print(f"Result: {seq['generated_text']}")

报错小问题1:
huggingface_hub.utils._validators.HFValidationError: Repo id must use alphanumeric chars or '-', '_', '.', '--' and '..' are forbidden, '-' and '.' cannot start or end the name, max length is 96:

原因是官方代码用的是在线模式,地址用的简称,不对改成离线地址后用的是./XXX的格式,报此错误,直接改成相对路径'XXX'work了。

报告小问题2:
ImportError: Using low_cpu_mem_usage=True or a device_map requires Accelerate: pip install accelerate

安装一下包用于GPU加速:
pip install accelerate

打印结果:

"简简单单"搞了一天...

明天醒了再把13B测一下,估计问题不大。

20231127: 相同的流程,13B测试成功,当前方法可行!

相关推荐
理智的煎蛋5 分钟前
CentOS/Ubuntu安装显卡驱动与GPU压力测试
大数据·人工智能·ubuntu·centos·gpu算力
XingYuyu_Coder32 分钟前
通过PXE的方式实现Ubuntu 24.04 自动安装
ubuntu·pxe
IOT-Power1 小时前
树莓派 Ubuntu 24.04 开机换源总结
linux·数据库·ubuntu
蓝纹绿茶2 小时前
Python程序使用了Ffmpeg,结束程序后,文件夹中仍然生成音频、视频文件
python·ubuntu·ffmpeg·音视频
quqi993 小时前
Enable FIPS in ubuntu (by quqi99)
linux·运维·ubuntu
人工智能训练师3 小时前
在Ubuntu中如何使用PM2来运行一个编译好的Vue项目
linux·运维·服务器·vue.js·ubuntu·容器
Mr. Cao code8 小时前
探索OpenResty:高性能Web开发利器
linux·运维·服务器·前端·nginx·ubuntu·openresty
Molesidy18 小时前
【UAV】基于PX4+Ubuntu24.04.3的无人机制作的开发环境搭建
ubuntu·无人机·px4·gazebo·uav
绿箭柠檬茶21 小时前
Ubuntu 使用 Samba 共享文件夹
linux·运维·ubuntu
小猫挖掘机(绝版)1 天前
通过tailscale实现一台电脑上vscode通过ssh连接另一台电脑上的VMware Linux 虚拟机
linux·windows·vscode·ubuntu·ssh