记录书生大模型任务L0G4000 玩转HF/魔搭/魔乐社区
要求:熟悉平台、下载模型使用
1、完成Hugging Face注册
2、使用免费的CodeSpaces 平台链接使用
https://github.com/codespaces,该平台可以免费使用;
选择选择Jupyter Notebook进行创建环境
并添加以下依赖:
pip install transformers4.38
pip install sentencepiece0.1.99
pip install einops0.8.0
pip install protobuf5.27.2
pip install accelerate==0.33.0
3、我们可以先尝试下载一个简单的文件让自己有点成就感
创建文件,并添加以下代码:
import os
from huggingface_hub import hf_hub_download
# 指定模型标识符
repo_id = "internlm/internlm2_5-7b"
# 指定要下载的文件列表
files_to_download = [
{"filename": "config.json"},
{"filename": "model.safetensors.index.json"}
]
# 创建一个目录来存放下载的文件
local_dir = f"{repo_id.split('/')[1]}"
os.makedirs(local_dir, exist_ok=True)
# 遍历文件列表并下载每个文件
for file_info in files_to_download:
file_path = hf_hub_download(
repo_id=repo_id,
filename=file_info["filename"],
local_dir=local_dir
)
print(f"{file_info['filename']} file downloaded to: {file_path}")
运行该文件:python hf_download_josn.py
得到以下结果,我们便完成了第一个简单模型文件的下载