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测试成功,当前方法可行!

相关推荐
小宋0017 小时前
在Ubuntu上安装配置 LLaMA-Factory
ubuntu·计算机视觉
kfepiza8 小时前
Netplan 配置网桥(Bridge)的模板笔记250711
linux·tcp/ip·ubuntu
kfepiza9 小时前
用Netplan配置网桥bridge笔记250711
linux·ubuntu·debian
x县豆瓣酱13 小时前
ubuntu server配置静态IP
linux·运维·ubuntu
x县豆瓣酱16 小时前
ubuntu server远程连接
linux·运维·ubuntu
0wioiw016 小时前
Ubuntu基础(Python虚拟环境和Vue)
linux·python·ubuntu
史不了16 小时前
无 sudo 运行:让你的程序在 Ubuntu 低端口监听
linux·运维·ubuntu
longze_71 天前
Ubuntu连接不上网络问题(Network is unreachable)
linux·服务器·ubuntu
Dirschs1 天前
【Ubuntu22.04安装ROS Noetic】
linux·ubuntu·ros
vvw&1 天前
Linux 中的 .bashrc 是什么?配置详解
linux·运维·服务器·chrome·后端·ubuntu·centos