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

相关推荐
Hello.Reader1 小时前
在 Ubuntu 环境为 Elasticsearch 引入 `icu_tokenizer
ubuntu·elasticsearch·jenkins
浪裡遊7 小时前
Linux常用指令
linux·运维·服务器·chrome·功能测试
鸿蒙布道师12 小时前
OpenAI为何觊觎Chrome?AI时代浏览器争夺战背后的深层逻辑
前端·人工智能·chrome·深度学习·opencv·自然语言处理·chatgpt
袈裟和尚12 小时前
如何在安卓平板上下载安装Google Chrome【轻松安装】
前端·chrome·电脑
foo1st14 小时前
JDK(Ubuntu 18.04.6 LTS)安装笔记
java·笔记·ubuntu
maotou52619 小时前
Ubuntu22学习记录
linux·ubuntu
放飞自我的Coder20 小时前
【win11 安装WSL2 详解一遍过!!】
linux·ubuntu
蜕变的土豆20 小时前
Ubuntu下软件运行常见异常退出问题汇总分析
linux·ubuntu
HtwHUAT21 小时前
五、web自动化测试01
前端·css·chrome·python·功能测试·selenium·html
浏览器爱好者1 天前
如何下载适用于语音识别功能增强的Google Chrome浏览器
人工智能·chrome·语音识别