使用 Notebook 上传模型

将模型上传到模型仓库是发布 LLM 推理服务和创建微调任务的第一步。推荐使用 Workbench/Notebook 上传模型:

  • 最佳上传速度:由于 Workbench/Notebook 实例运行在平台上,因此可以提供最佳上传速度。
  • 内置 Git LFS:Notebook 自带 git lfs 工具,无需在本地单独安装。

当然,你也可以从本地机器上传模型,但需要先安装 Git LFS。

创建 Workbench/Notebook 实例

注意:Alauda AI >= 1.4 版本中,可以在左侧导航栏中通过 "Workbench" 创建 Notebook 实例。在 Alauda AI <= 1.3 版本中,可以通过 "Advanced - Notebook" 创建 Notebook 实例。

这里不详细介绍 Workbench/Notebook 的创建步骤,请参考 Workbench 文档。 需要注意的是,必须创建足够的存储空间来保存模型文件,上传流程才能成功完成。

准备模型

从任意开源社区下载所需模型。我们建议从以下三个网站下载,例如 https://hf-mirror.com/deepseek-ai/DeepSeek-R1

从 huggingface 或 hf-mirror 下载模型时,可以使用 huggingface-cli 命令(需要执行 pip install huggingface_hub)。更多命令行使用说明,请参考 https://hf-mirror.com。以下是下载模型 DeepSeek-R1-Distill-Qwen-1.5B 的示例命令:

export HF_ENDPOINT=https://hf-mirror.com
pip install huggingface_hub
huggingface-cli download --resume-download deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B --local-dir DeepSeek-R1-Distill-Qwen-1.5B

注意: 如果你的环境无法访问互联网,可以选择一台适合的、可联网的机器(例如连接集群高速网络的桌面机或服务器),先下载模型,再将其复制到 Notebook 环境中。

创建模型

注意: 此步骤将创建一个空模型,用于上传模型文件。如果你已经创建了模型仓库,可以跳过此步骤。

打开并登录 Alauda AI。在 "Model Repository" 页面中,点击 "Create Model Repository"。依次输入参数后,点击 "Create"。

  • Name:任意。建议使用下载的模型名称。本示例中使用 "DeepSeek-R1-Distill-Qwen-1.5B"。
  • Tag:任意。建议填写模型类别以便更方便地搜索,例如 "deepseek"。
  • Description:任意。

创建模型仓库后,你可以在 "Details" 页面找到该模型的 "Repository Address"。后续进行 git 构建时会用到该地址。用于推送时使用。

上传模型

INFO

为确保通过 Git LFS 稳定上传/下载大模型文件,请确保 Git 和 Git LFS 均已更新到最新正式版本。旧版本可能会触发 LFS batch-API 失败或 HTTP 层异常,尤其是在自带过旧构建版本的 Windows 系统上。

下载位置

参考版本(已验证):Git 2.43.0,Git LFS 3.6.1

注意: 开始之前,请确保你的 Notebook 环境中已安装 Git 和 Git LFS:git lfs install && git lfs version

在 Notebook 中打开 Terminal,执行以下命令,将模型文件推送到模型仓库。

# Navigate to the folder where you downloaded the model in the previous step.
cd <your-repo-name>
# Delete the previous Git repository information for the model (if any).
rm -rf .git
# Initialization Create a git repository and set the push URL to the model repository created in the previous step.
git init
git checkout -b main
git remote add origin <repository-url>

# In the .gitattributes file, specify the file types to tell Git LFS which files to track.
# The following file identifies common model file formats and can be used directly.

cat >.gitattributes <<EOL
*.7z filter=lfs diff=lfs merge=lfs -text
*.arrow filter=lfs diff=lfs merge=lfs -text
*.bin filter=lfs diff=lfs merge=lfs -text
*.bz2 filter=lfs diff=lfs merge=lfs -text
*.ckpt filter=lfs diff=lfs merge=lfs -text
*.ftz filter=lfs diff=lfs merge=lfs -text
*.gz filter=lfs diff=lfs merge=lfs -text
*.h5 filter=lfs diff=lfs merge=lfs -text
*.joblib filter=lfs diff=lfs merge=lfs -text
*.lfs.* filter=lfs diff=lfs merge=lfs -text
*.mlmodel filter=lfs diff=lfs merge=lfs -text
*.model filter=lfs diff=lfs merge=lfs -text
*.msgpack filter=lfs diff=lfs merge=lfs -text
*.npy filter=lfs diff=lfs merge=lfs -text
*.npz filter=lfs diff=lfs merge=lfs -text
*.onnx filter=lfs diff=lfs merge=lfs -text
*.ot filter=lfs diff=lfs merge=lfs -text
*.parquet filter=lfs diff=lfs merge=lfs -text
*.pb filter=lfs diff=lfs merge=lfs -text
*.pickle filter=lfs diff=lfs merge=lfs -text
*.pkl filter=lfs diff=lfs merge=lfs -text
*.pt filter=lfs diff=lfs merge=lfs -text
*.pth filter=lfs diff=lfs merge=lfs -text
*.rar filter=lfs diff=lfs merge=lfs -text
*.safetensors filter=lfs diff=lfs merge=lfs -text
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
*.tar.* filter=lfs diff=lfs merge=lfs -text
*.tar filter=lfs diff=lfs merge=lfs -text
*.tflite filter=lfs diff=lfs merge=lfs -text
*.tgz filter=lfs diff=lfs merge=lfs -text
*.wasm filter=lfs diff=lfs merge=lfs -text
*.xz filter=lfs diff=lfs merge=lfs -text
*.zip filter=lfs diff=lfs merge=lfs -text
*.zst filter=lfs diff=lfs merge=lfs -text
*tfevents* filter=lfs diff=lfs merge=lfs -text
EOL

# You can also add or modify manually .gitattributes file, for example:
# Track files with the specified suffix
git lfs track "*.h5" "*.bin" "*.pt"

# Add all changes, including the .gitattributes file (if created) and the model files
git add .
# Ensure all files that conform to LFS rules are correctly marked
git add --renormalize .

# Check the list of files currently tracked by LFS (optional)
# If larger model files you wish to store using LFS are not listed here, verify that the above command was executed correctly
git lfs ls-files -n

# Commit changes
# It is recommended to configure your username and email address, or ensure they are configured globally
# git config --global user.name "Your Name"
# git config --global user.email "your.email@example.com"
git commit -am "Add LLM model files with Git LFS"

# Push to the remote repository
git -c http.sslVerify=false -c lfs.activitytimeout=36000 push -u origin main

# If you need to force a push, for example after using git lfs migrate --import:
# git push -u origin main --force

编辑模型元数据

打开 "Model Details" 页面,进入 "File Management" 选项卡,点击 "Edit Metadata",根据已上传的模型选择 "task type" 和 "framework" 元数据,然后点击 "Confirm"。

注意: 只有在配置了 task type 和 framework 元数据后,才能使用 "Publish Inference Service" 页面发布推理服务。有关模型任务类型的更多信息,请参考 Huggingface pipelines

  • Task Type:决定如何基于模型创建推理服务(例如,text-generation、image-classification)。
    • 对于 LLM 模型,请选择 "text-generation"。
    • 对于从 Huggingface 下载的其他模型,请参考模型页面中列出的 task type。
    • 对于自定义模型,请根据模型的预期用途选择 task type。
  • Framework:模型的存储格式。

附录

根据文件大小标记 LFS 文件

git lfs migrate 命令可以帮助你查找并迁移 Git 历史中已存在但未被 LFS 跟踪的大文件。请注意,此命令会重写你的提交历史。如果仓库是共享的,请务必与协作者协调,并在推送时使用 --force

检查需要迁移的文件

git lfs migrate info

将已有的大文件迁移到 LFS:

以下命令会将所有大于 100MB 的文件迁移到 Git LFS。这个 100MB 限制基于 GitHub 建议的最佳性能文件大小上限。

git lfs migrate import --above 100MB

如果你的仓库是共享的,请务必在运行此命令前通知所有协作者,并准备在推送时使用 git push --force