1,视频演示地址
https://www.bilibili.com/video/BV1Dc41117wT/?vd_source=4b290247452adda4e56d84b659b0c8a2
【candle】(2):使用hf-mirror镜像下载TheBloke/Llama-2-7B-GGML的q4
2,安装rust到其他目录
默认的安装模式:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
https://forge.rust-lang.org/infra/other-installation-methods.html
https://static.rust-lang.org/dist/rust-1.74.1-x86_64-unknown-linux-gnu.tar.gz
wget https://static.rust-lang.org/dist/rust-1.74.1-x86_64-unknown-linux-gnu.tar.gz
tar -zxf rust-1.74.1-x86_64-unknown-linux-gnu.tar.gz
cd rust-1.74.1-x86_64-unknown-linux-gnu/
./install.sh --prefix=/root/autodl-tmp/rust --without=rust-docs
这样就可以将 rust 安装到其他目录了:
同时不要安装 rust-docs 有 700 多MB ,实在是没有用。
./install.sh --list-components
# Available components
* rustc
* rust-std-x86_64-unknown-linux-gnu
* rust-docs
* rust-docs-json-preview
* rust-demangler-preview
* cargo
* rustfmt-preview
* rls-preview
* rust-analyzer-preview
* llvm-tools-preview
* clippy-preview
* rust-analysis-x86_64-unknown-linux-gnu
然后执行安装即可:
./install.sh --prefix=/root/autodl-tmp/rust --without=rust-docs
# 安装完成,设置好 PATH 路径:
export PATH=/root/autodl-tmp/rust/bin:$PATH
# 执行 rustc 就可以生效了:
可以执行 rust 命令了:
3,下载 candle 项目
#设置学术加速,不再区分不同地区
# 设置hf 路径:
export HF_HOME=/root/autodl-tmp/hf_cache
# 下载项目
git clone https://github.com/huggingface/candle.git
cd candle
# 执行一个简单的demo
cargo run --example quantized
然后就是漫长的下载库:
Downloaded ttf-parser v0.15.2
Downloaded zerofrom v0.1.3
Downloaded zstd-safe v6.0.6
Downloaded anstream v0.6.5
Downloaded approx v0.5.1
Downloaded bitflags v1.3.2
Downloaded bytemuck v1.14.0
Downloaded bytes v1.5.0
Downloaded wav v1.0.0
Downloading 81 crates, remaining bytes: 128.3 KB
4,下载文件方法 huggingface_hub 使用镜像下载
pip3 install huggingface_hub
然后使用模型下载脚本:
download_model.py :
# 设置镜像
# export HF_ENDPOINT="https://hf-mirror.com"
import os
os.environ['HF_ENDPOINT'] = 'https://hf-mirror.com'
from huggingface_hub import snapshot_download
# 下载第一个模型
snapshot_download(repo_id="TheBloke/Llama-2-7B-GGML", allow_patterns=["llama-2-7b.ggmlv3.q4_0.bin"])
# 下载第二个模型
snapshot_download(repo_id="hf-internal-testing/llama-tokenizer")
# 设置hf home 目录,防止下载到其他目录,磁盘满了。
export HF_HOME=/root/autodl-tmp/hf_cache
# 执行下载方法:
python3 download_model.py
下载速度还可以:
Fetching 1 files: 0%| | 0/1 [00:00<?, ?it/s]
llama-2-7b.ggmlv3.q4_0.bin: 32%|███████████████████▍ | 1.21G/3.79G [04:54<10:59, 3.92MB/s]
还可以使用 https://aliendao.cn/#/ 进行加速下载。
5,然后就可以运行模型了
cargo run --example quantized
Compiling candle-examples v0.3.1 (/root/autodl-tmp/candle/candle-examples)
Finished dev [unoptimized + debuginfo] target(s) in 7.87s
Running `target/debug/examples/quantized`
avx: true, neon: false, simd128: false, f16c: true
temp: 0.80 repeat-penalty: 1.10 repeat-last-n: 64
loaded 291 tensors (3.79GB) in 9.32s
params: HParams { n_vocab: 32000, n_embd: 4096, n_mult: 256, n_head: 32, n_layer: 32, n_rot: 128, ftype: 2 }
model built
My favorite theorem is 0 (
zero). It's just a random
3,运行yi-6b
cargo run --example yi --features cuda
# 设置镜像
# export HF_ENDPOINT="https://hf-mirror.com"
# export HF_HOME=/root/autodl-tmp/hf_cache
import os
os.environ['HF_ENDPOINT'] = 'https://hf-mirror.com'
os.environ['HF_HOME'] = '/root/autodl-tmp/hf_cache'
from huggingface_hub import snapshot_download
snapshot_download(repo_id="01-ai/Yi-6B")
Yi.svg: 980B [00:00, 1.76MB/s] | 0/16 [00:00<?, ?it/s]
LICENSE: 17.4kB [00:00, 14.3MB/s]
config.json: 605B [00:00, 1.20MB/s]
generation_config.json: 132B [00:00, 43.9kB/s]
.gitattributes: 1.52kB [00:00, 1.27MB/s]/s]
md5: 184B [00:00, 377kB/s]██▎ | 1/16 [00:00<00:11, 1.34it/s]
README.md: 24.8kB [00:00, 262kB/s]
model.safetensors.index.json: 23.9kB [00:00, 33.6MB/s] | 3/16 [00:00<00:03, 3.96it/s]
pytorch_model.bin.index.json: 23.9kB [00:00, 34.6MB/s]
tokenizer_config.json: 320B [00:00, 453kB/s]?B/s]
tokenizer.json: 3.56MB [00:00, 6.32MB/s]
tokenizer.model: 100%|████████████████████████████████████████████████████████████████| 1.03M/1.03M [00:00<00:00, 1.16MB/s]
pytorch_model-00001-of-00002.bin: 2%|▊ | 168M/9.94G [00:10<09:14, 17.6MB/s]
pytorch_model-00001-of-00002.bin: 4%|█▉ | 409M/9.94G [00:25<09:49, 16.2MB/s]
model-00001-of-00002.safetensors: 4%|██ | 430M/9.94G [00:26<09:15, 17.1MB/s]
model-00002-of-00002.safetensors: 20%|█████████▍ | 430M/2.18G [00:25<01:37, 17.9MB/s]
pytorch_model-00002-of-00002.bin: 19%|█████████▏ | 419M/2.18G [00:25<01:40, 17.5MB/s]
TheBloke/Yi-34B-Chat-AWQ · Hugging Face
还有34b模型,但是没有测试。
4,总结
使用candle 可以运行大模型了,可以运行 yi-6b的模型,使用镜像下载成功。
candle目前支持的模型还不多,但是未来会慢慢流行起来的。
提前做好学习准备。