Workflows2026年5月7日·1 分钟阅读

Modal Volumes — Persistent Storage for AI Workloads

Modal Volumes are content-addressed persistent storage for Modal. Mount as a Linux filesystem, share across runs, version with .commit().

Agent 就绪

这个资产可以被 Agent 直接读取和安装

TokRepo 同时提供通用 CLI 命令、安装契约、metadata JSON、按适配器生成的安装计划和原始内容链接,方便 Agent 判断适配度、风险和下一步动作。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:New
入口
Asset
通用 CLI 安装命令
npx tokrepo install af427a6d-eecc-4a38-ade8-69caf6274e0b

简介

Modal Volume 给 Modal Function 和 Sandbox 跨运行保留的持久存储。挂载成普通 Linux 文件系统、跨 Function / Sandbox 共享、用 .commit() 做版本 checkpoint。适合缓存 pip 包和模型权重、ML 训练数据集、跨多次运行的 agent 工作区。需要 Modal SDK。装机时间 1 分钟。


创建 + 挂载

import modal

app = modal.App("ml-pipeline")
volume = modal.Volume.from_name("model-cache", create_if_missing=True)

@app.function(volumes={"/cache": volume})
def download_model():
    import huggingface_hub
    huggingface_hub.snapshot_download(
        "meta-llama/Llama-3-8B",
        cache_dir="/cache",
    )
    volume.commit()  # checkpoint 到持久存储

跨运行缓存 pip 包

pip_cache = modal.Volume.from_name("pip-cache", create_if_missing=True)

image = modal.Image.debian_slim().run_commands(
    "pip install --target=/pip-cache transformers torch",
).env({"PYTHONPATH": "/pip-cache"})

@app.function(image=image, volumes={"/pip-cache": pip_cache})
def train(): ...

冷启动从几分钟降到几秒,因为包已经在 volume 上了。

Function 和 Sandbox 之间共享数据

data_vol = modal.Volume.from_name("ingest", create_if_missing=True)

@app.function(volumes={"/data": data_vol})
def ingest():
    download_csv_files("/data/raw/")
    data_vol.commit()

@app.function(volumes={"/data": data_vol})
def analyze():
    data_vol.reload()  # 拿最新 commit 的快照
    return run_analysis("/data/raw/")

当 agent 工作区用

workspace = modal.Volume.from_name("agent-runs", create_if_missing=True)

# 每次 agent 运行有自己的子目录
sb = modal.Sandbox.create(
    image=image,
    volumes={"/work": workspace},
    workdir="/work/run-{run_id}",
)

sb.exec("python", "agent.py")
workspace.commit()  # 保存工作

后续运行读工作区历史,agent 有跨会话的长期记忆。


FAQ

Q: Volume 跟 S3 啥区别? A: Volume 挂成 Linux 文件系统(不用 S3 API 转换)。随机读更快,跟 Modal 镜像缓存集成。纯归档或外部访问 S3 还是更合适。

Q: Volume 有版本吗? A: 有 —— 每次 .commit() 创建一个新版本。可以用 volume.reload(commit_id=...) 读旧版本。回滚和可复现有用。

Q: Volume 能多大? A: 实际上无上限。热层快(NVMe 级),冷数据透明卸载。按使用容量计费,但没有硬上限。


🙏

来源与感谢

Built by Modal. Commercial product with free tier.

modal.com/docs — Volumes documentation

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产