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

相关推荐
杨~friendship1 小时前
Ubuntu上使用qt和opencv显示图像
linux·开发语言·c++·qt·opencv·ubuntu
王辉辉的猫8 小时前
026.(娱乐)魔改浏览器-任务栏图标右上角加提示徽章
chrome
IT-陈12 小时前
app抓包 chrome://inspect/#devices
前端·chrome
ForRunner12318 小时前
2024 年最佳 Chrome 验证码扩展,解决 reCAPTCHA 问题
前端·chrome
JNU freshman19 小时前
Chrome谷歌浏览器登录账号next无反应
前端·chrome
温小二的徐凤年20 小时前
ubuntu 22.04 ~24.04 如何修改登录背景
linux·ubuntu·插件
小龙在慢慢变强..20 小时前
Ubuntu 软件仓库镜像使用帮助
linux·ubuntu·https
Karen_bluu21 小时前
ROS2 Humble如何初步使用Livox-mid-360激光雷达 (viewer/rviz)以及解决一些问题
ubuntu·机器人
老K(郭云开)1 天前
汉王手写签批控件如何在谷歌、火狐、Edge等浏览器使用
前端·chrome·中间件·edge·创业创新·html5
慕羽★1 天前
Git常用指令整理【新手入门级】【by慕羽】
linux·git·ubuntu·gitlab·github·仓库·分布式协作