大模型—如何从huggingface上下载并调用模型

最近需要手动从huggingface上下载模型,尝试在调用模型时发现了不少问题,写个blogger记录一下,后续再行补充

1,下载meta-llama/Llama-3.2-3B到本地(推荐手动下载)

2,在下载到本地后,利用conda创建一个环境,并下载需要的包

conda create -n llm python==3.10
conda activate llm
pip install transformer

pytorch 根据自己的cuda版本选择合适的版本

pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118

3,写一个run.py脚本来调用,查看模型的结构

from transformers import AutoTokenizer, AutoModel
tokenizer = AutoTokenizer.from_pretrained("/data/Matrix/zh/Llama-3.2-3B", trust_remote_code=True)
model = AutoModel.from_pretrained("/data/Matrix/zh/Llama-3.2-3B", trust_remote_code=True).half().cuda()
print(model)

可能出现的问题:

 ValueError: `rope_scaling` must be a dictionary with with two fields, `type` and `factor`, got {'factor': 32.0, 'high_freq_factor': 4.0, 'low_freq_factor': 1.0, 'original_max_position_embeddings': 8192, 'rope_type': 'llama3'}               解决办法:更新最新的transformer

pip install --upgrade transformers

最后就能看到模型的结构啦!

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值