【candle】(3):安装rust环境,使用GPU进行加速,成功运行qwen的0.5b,4b,7b模型,搭建rust环境,配置candle,使用hf-mirror下载模型

本文详细介绍了如何在Rust环境中安装和配置CANDLE框架,利用GPU加速运行HuggingFace的Qwen模型,包括0.5B和4B版本,以及在浏览器中的WASM支持。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1,视频地址

https://www.bilibili.com/video/BV1AF4m1E73d/

【candle】(3):安装rust环境,使用GPU进行加速,成功运行qwen的0.5b,4b,7b模型,搭建rust环境,配置candle,下使用hf-mir

https://gitee.com/fly-llm/candle-run-llm

3,关于candle项目

https://github.com/huggingface/candle

Hugging Face 使用rust开发的高性能推理框架。
语法简单, 风格与 PyTorch 相似。
CPU 和 Cuda Backend:m1、f16、bf16。
支持 Serverless(CPU)、小型和快速部署
支持 WASM,可在浏览器中运行模型。

3,rust环境搭建

安装软件文档:
https://www.rust-lang.org/tools/install

设置目录:


export RUSTUP_HOME=/root/autodl-tmp/cargo
export CARGO_HOME=/root/autodl-tmp/cargo

# 安装rust 软件
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

安装成功:

info: default toolchain set to 'stable-x86_64-unknown-linux-gnu'

  stable-x86_64-unknown-linux-gnu installed - rustc 1.76.0 (07dca489a 2024-02-04)


Rust is installed now. Great!

To get started you may need to restart your current shell.
This would reload your PATH environment variable to include
Cargo's bin directory (/root/autodl-tmp/cargo/bin).

To configure your current shell, run:
source "/root/autodl-tmp/cargo/env"

执行命令:
source “/root/autodl-tmp/cargo/env”

# rustc -V
rustc 1.76.0 (07dca489a 2024-02-04)

4,下载 candle 项目

设置学术加速


cd /root/autodl-tmp/

# 设置hf 路径:
export HF_HOME=/root/autodl-tmp/hf_cache
# 下载项目
git clone https://github.com/huggingface/candle.git 

cd /root/autodl-tmp/candle

5,运行qwen-4b大模型


python3 download.py Qwen/Qwen1.5-4B
export HF_HOME=/root/autodl-tmp/hf_cache
cargo run --example qwen --features cuda -- --model 4b --prompt 北京景点推荐

6,运行qwen-0.5b的聊天模型


python3 download.py Qwen/Qwen1.5-0.5B-Chat
export HF_HOME=/root/autodl-tmp/hf_cache
cargo run --example qwen --features cuda -- --model-id Qwen/Qwen1.5-0.5B-Chat --prompt 北京景点推荐

7,运行效果

在这里插入图片描述

在这里插入图片描述

8,总结下

使用 candle还是非常方便的,使用另外一种方案运行大模型。
可以对模型进行加速。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值