最近需要手动从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
最后就能看到模型的结构啦!