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

相关推荐
草上爬6 小时前
OpenWrt:使用ALSA实现边录边播
ubuntu·openwrt·record·alsa·play
藥瓿亭12 小时前
K8S认证|CKS题库+答案| 6. 创建 Secret
运维·ubuntu·docker·云原生·容器·kubernetes·cks
舰长11513 小时前
Ubuntu挂载本地镜像源(像CentOS 一样挂载本地镜像源)
linux·ubuntu·centos
Theodore_102213 小时前
大数据(2) 大数据处理架构Hadoop
大数据·服务器·hadoop·分布式·ubuntu·架构
Unpredictable22215 小时前
【VINS-Mono算法深度解析:边缘化策略、初始化与关键技术】
c++·笔记·算法·ubuntu·计算机视觉
姓刘的哦17 小时前
ubuntu中使用docker
linux·ubuntu·docker
MrWang.17 小时前
Ubuntu中SSH服务器安装使用
服务器·ubuntu·ssh
_lizhiqiang17 小时前
联想拯救者R9000P 网卡 Realtek 8852CE Ubuntu/Mint linux 系统睡眠后,无线网卡失效
linux·运维·ubuntu·r9000p·无线网卡·8852ce
笑醉踏歌行19 小时前
NVM,Node.Js 管理工具
运维·ubuntu·node.js
bbsh20991 天前
WebFuture:Ubuntu 系统上在线安装.NET Core 8 的步骤
linux·ubuntu·.netcore·webfuture