Skip to main content

Modal Benchmark

最新版本:0.3.1。发布原因与兼容性见 简体中文更新说明。

将 Hugging Face 模型下载到 Modal Volume。其他项目通过 Python 调用 create_downloader() 选择存储盘,再调用 download() 指定模型。

from modal_benchmark.hf import create_downloader

downloader = create_downloader(volume_name="my-models")
result = downloader.download("sshleifer/tiny-gpt2")
print(result["models"][0]["path"])  # 模型在云端容器里的完整目录

精确挂载 Volume V2 子目录(0.3.1)

sub_path 可选。默认 None 保持与 0.3.0 完全一致;传入时 Coordinator/Writer 使用同一子树,下载目录 base 仍按容器内路径填写:

downloader = create_downloader(
    volume_name="model-store",
    volume_version=2,
    mount_path="/data",
    sub_path="/comfyui",
    max_workers=3,
)
result = downloader.download("sshleifer/tiny-gpt2", base="/data/hf/tiny-gpt2")

真实 Volume 路径为 /comfyui/hf/tiny-gpt2,下载容器访问路径为 /data/hf/tiny-gpt2。SDK 完成标记回读自动添加子树前缀;同卷下的其他子树不可通过这个容器挂载访问。不同 sub_path 的活动指针与下载锁互不冲突。注意 downloader.volume 是原始 Volume SDK 对象,不会自动限制其 API 权限;仅容器挂载受 sub_path 限制。

下载后去哪里找

加载模型时,使用返回值中的 path。一个下载任务的目录(result["base"])内包含以下文件。

<base>/
├── download-manifest.json               本次任务的仓库、版本和文件清单
├── reports/latest.json                  下载报告
└── <仓库所有者>/<仓库名>/<commit>/
    ├── model/                           模型加载器读取这里
    ├── _verification/                   每个文件的下载凭证
    ├── _shards/                         分片下载的临时目录
    └── all-components-complete.json     整体完成标记,放在第一个仓库下

从哪里读代码

从 hf/modal.py 开始。文件顶部的 Downloader.download() 是调用入口,create_downloader() 创建云端函数。随后按执行顺序阅读 coordinate()(检查已有文件并分配工作)、consume_files()(下载并提交)、_publish()(发布并回读完成标记)。单个文件如何落盘见 hf/download.py。生产库在 src/modal_benchmark/,调用示例在 examples/,历史实验在 benchmarks/ 和 archive/。

架构

  1. 客户端只调用一次 Coordinator;它在一个 CPU 容器内发现 HF 仓库及固定 Revision、扫描已有 Volume 文件。
  2. Coordinator 根据文件大小分组并并行启动 N 个 Writer;每个 Writer 使用 Xet 下载、重试及分批 Volume Commit。
  3. Worker 全部结束后,Coordinator 调用 Volume.reload() 并核查文件和凭证;缺失文件可在限定批次内重新分配。
  4. 验证通过后,Coordinator 在一次最终 Commit 中写入完成标记、报告,以及调用方可选的活动模型清单。
  5. 使用 Volume SDK 回读完成标记,只有成功才返回 VERIFIED 和模型路径。

0.2.1 修复:远程 Worker 崩溃重新扫描并有限恢复;跨容器 Commit 导致的 Xet 凭证时间戳漂移不会触发完整 SHA-256;超时取消仍在运行的 Writer;同仓库不同 Revision 不再被合并;提交失败回滚本地活动模型指针;缓存命中不再重复 Commit 或反复执行 Strict 完整哈希。

独立 Coordinator 与两个 Writer 是三次远程函数调用,不代表固定只有三次 Volume/Hub RPC。空缓存首次运行需要 Modal 容器准备;已完整缓存时不会启动 Writer。

0.2.2 Xet 优化:可信传输凭证匹配不再依赖文件 mtime,默认 xet 模式不会因时间戳变化触发整文件 SHA-256;旧文件凭证真正缺失时重新下载并取得可信证据。无 Xet 元数据的小文件通过官方 HF HTTP 下载和 ETag/大小凭证检查,不在应用层重哈希。完整 SHA-256 仅由显式 fast/strict 或其他独立工具执行。

安装

在本仓库执行:

uv sync
uv run --with pytest python -m pytest -q
uv build

其他项目可通过 wheel 或固定 Git commit 安装。

Python API

from modal_benchmark.hf import create_downloader

downloader = create_downloader(
    volume_name="my-models",
    max_workers=2,
    verification_mode="xet",
)

result = downloader.download([
    "owner/target",
    {"repo_id": "owner/draft", "revision": "main"},
])
print(result["status"])
print(result["models"])
print(result["timings"])

生产默认:2 Writer、每个 4 CPU / 8 GiB、Xet 并发 8、每 8 文件或达到 16 GiB 时提交,Volume v2,新版不兼容旧 discover_many/run_manifest 接口。

在原有 v1 Volume 上使用 volume_version=None。同一目标目录不能同时运行两个协调器。版本固定在 Hugging Face commit SHA;同样的清单生成相同的下载路径,复跑只处理缺失部分。

若要一次发布供下游直接挂载的角色映射:

result = downloader.download(
    ["owner/target", "owner/draft"],
    active_manifest=".modal-model-manifest.json",
    aliases={"target": "owner/target", "draft": "owner/draft"},
)

验证成功后,Volume 根目录出现上述指针;更新仅发生在最终提交。

验证

  • xet 默认:权重经官方 Xet 完成证明,非 Xet 文件经官方 HTTP 元数据/大小/凭证验证;应用层不重新计算完整 SHA-256(不等于严格内容复核)
  • fast:下载/补齐凭证时验证来源 SHA-256,提交后检查凭证
  • strict:Coordinator 完成后对有来源 SHA-256 的文件重新读取并计算哈希

参见 Xet 信任边界 与 安装/参数/API。

实际验证与示例

# 默认免费预览
uv run python scripts/smoke_tiny_gpt2.py
uv run python examples/download_ltx25.py
uv run python examples/download_minimax_image.py

# 小模型真实 CPU 验证(需要 Modal 认证和 HF Secret)
uv run python scripts/smoke_tiny_gpt2.py --execute --volume my-smoke
# 再次执行相同命令验证缓存命中

2026-11-22,新的 Coordinator + Writer 真实下载 tiny-gpt2(9 文件 / 4.73 MB),Coordinator 内部 19.11 秒,完整命令约 76.8 秒;缓存命中复测 Coordinator 3.24 秒、无 Writer。两组数字不是 Qwen 27 GB 的等条件对照,不可据此推断大模型速度提升倍数。

旧版 0.1.5 曾下载 Qwen3.8 + DFlash2 共 27.62 GB:下载器内部 124.44 秒、完整命令 155.95 秒。该记录用于后续同模型、同缓存条件 A/B 比较。

历史研究和旧接口测试保留在 benchmarks/ 与 archive/,不再作为生产接口。默认回归只执行 tests/;任何删除的旧接口可从 Git 提交 b3d1a82 找回。

本项目按阿里规范使用简体中文提交,修改后测试与推送要求见 交付约定。

Metadata

Release files for modal-benchmark 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for modal-benchmark 0.3.1
File Size Uploaded Provenance Actions
modal_benchmark-0.3.1.tar.gz 52.7 kB Without provenance Details for modal_benchmark-0.3.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for modal-benchmark 0.3.1
File Interpreter ABI Platform Actions
modal_benchmark-0.3.1-py3-none-any.whl Python 3 none any Details for modal_benchmark-0.3.1-py3-none-any.whl

Total release size: 78.9 kB

Security for modal-benchmark 0.3.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page