Skip to main content

UniStore

UniStore 是面向 RL 训练的数据访问层,统一处理 bytes、Python 对象、Tensor 和文件。 业务只使用逻辑 key 或 ObjectRef,不需要感知对象位于远端内存、本地 SSD 还是共享 文件系统(WekaFS / GPFS)。

为什么需要它

Mooncake 提供 RDMA、分布式内存、placement 和磁盘副本,但业务仍需自行处理 Tensor 元数据、大对象分块、版本校验、批量传输和存储状态。每个训练模块各写一套,会造成 多套协议、重复数据和不同的失败语义。UniStore 把这些收进一层:

  • 一份数据可被多个训练节点和教师模型共享,不需要每个节点各存一份;
  • Tensor、DataProto、checkpoint 和普通对象使用一致的 key、版本与校验规则;
  • 热数据在分布式内存,容量不足时由 Mooncake offload 到本地 SSD;
  • WekaFS 和 GPFS 统一视为共享文件存储(SHARED 层),用于跨节点可见的副本;
  • 大对象使用有界窗口和预注册内存,不按对象总大小申请中转缓冲;
  • 业务不再依赖 p2pstore。
业务模块
   |
   v
UniStore API   bytes / tensor / file / batch / prefetch
   |
   v
Mooncake Engine
  分布式内存 <---- RDMA/TCP ----> 远端节点内存
       |
       +---- eviction ----> 本地 SSD
       +---- persistence -> 共享文件系统

Mooncake Master 只管理对象和副本元数据,数据字节不经过 Master。

快速开始

在 Linux 上安装 UniStore:

python -m pip install unistore

下面用共享文件后端写入并读回一条数据。先指定数据目录:

export UNISTORE_BACKEND_MODE=shared
export UNISTORE_SHARED_DIR="$HOME/.local/share/unistore/shared"
from unistore import UniStore

with UniStore().start() as store:
    ref = store.put("sample/1", b"payload")
    assert store.get(ref) == b"payload"

接入 Mooncake 集群时,将 UNISTORE_BACKEND_MODE 设为 mooncake,并设置 UNISTORE_MASTER(RPC 地址)和 UNISTORE_MEM_MASTER_HTTP_URL(管理地址)。部署步骤见源码仓库的 docs/api.md。

常用配置(代码参数 > 环境变量 > YAML > 默认值):

配置 默认值 作用
UNISTORE_MASTER 127.0.0.1:50051 Mooncake Master 地址
UNISTORE_MEM_HOLD_SIZE auto 本进程贡献给集群的内存(auto 初始 4 GiB;节点 80% 水位触发翻倍;共享 64 GiB 上限)
UNISTORE_MEM_AUTO_ENABLED 按容量输入推导 不传容量/auto 开启;显式整数默认固定;true 可将整数作为动态初始值
UNISTORE_MEM_NODE_LIMIT 68719476736 单物理节点存储段上限;同节点所有 Client 必须一致
UNISTORE_MEM_COORD_DIR /var/tmp/unistore-memory 节点本地协调目录;同机多容器必须挂载同一宿主机目录
UNISTORE_MEM_MASTER_HTTP_URL 空 auto 必填的 Master 管理 HTTP 地址,如 http://master:9003
UNISTORE_MEM_TRANSFER_BUFFER_SIZE 2 GiB Mooncake 引擎自己的传输缓冲区
UNISTORE_MEM_READ_BUFFER_SIZE 2 GiB UniStore 预注册的读缓冲区(只服务读路径)
UNISTORE_MEM_PREALLOC_SIZE 0(关) 在集群容量里预分配一批固定 part,本机不占
UNISTORE_GPU_STAGING_SIZE 2 GiB GPU↔主机暂存池(0 关闭),与读缓冲区独立
UNISTORE_SHARED_DIR 部署路径 共享文件系统目录
UNISTORE_SSD_DIR 自动探测 本节点 SSD offload 目录
UNISTORE_PROTOCOL rdma 数据传输协议,可回退 TCP

五个内存配置分别是什么、哪条路径用哪块,见 docs/api.md §3。

Master 配置直接决定写带宽:纯内存 master 68.7 GiB/s,offload 开只有 ~1.2 GiB/s。 热路径(训练同步、checkpoint 快速通道)用 UNISTORE_PERSISTENCE_ENABLED=false UNISTORE_ENABLE_OFFLOAD=false UNISTORE_ENABLE_SNAPSHOT=false bash deploy/start_master.sh <port>。 完整数字与机制见 docs/internals.md 第三部分。

最低延迟内存池

对象普遍在 10 MiB 以上、且初始化时间不计入业务延迟时,可以让 start() 一次性建好 固定 Mooncake payload,之后普通 put/get 自动使用,不需要传 pool key:

from unistore import UniConfig, UniStore

store = UniStore(UniConfig(
    master="<nodeA_IP>:<port>",
    mem_prealloc_size=50 << 30,
)).start()          # start 返回时 50 GiB pool 已就绪

ref = store.put("tensor/1", tensor)   # 自动申请固定 part 并批量写
value = store.get(ref)                # bytes 或 Tensor,按 metadata 自动还原
store.delete("tensor/1")              # part 归还 pool
store.clear()                         # 删除所有 key 并释放 store-owned pool

要把申请延迟到 start() 之后,先不配容量,再调 store.initialize_memory_pool(50 << 30)。 池空闲不足时按内部策略自动增长,不重建也不搬迁已有对象;part 分布由 Master 选择。 只有负责分配的 writer 需要填 mem_prealloc_size,其他 reader 只连同一 Master。

代码目录导读

想快速定位?包内是平铺的 11 个模块(没有子包),按"我要干什么"找文件:

我要… 去哪
看怎么调 API docs/api.md
改数据读写逻辑(put/get/tensor/file/batch/prefetch/admin) unistore/apis.py
改启动/关闭/内存池等生命周期 unistore/store.py
碰 mooncake 原生调用、重试、RDMA 选卡 unistore/transport.py
改 tensor 布局、并发读、GPU staging、注册缓冲池 unistore/io.py
改内存池 / LRU 索引 / 写侧 staging unistore/memory.py
改共享文件后端或盘副本直读 unistore/backends.py
加错误类型、常量、ObjectRef/Tier、工具函数 unistore/types.py
加配置项 unistore/config.py
加指标、日志、trace unistore/observability.py
改命令行 unistore/__main__.py
加离线单测(首选) tests/unit/
加需要真实 master 的场景 tests/e2e/
压测 benchmarks/run_memory_suite.py
起 master / 监控栈 deploy/ / monitoring/

模块内部按"段"排列,每段段首有 # ==== 标题 ==== 注释。依赖是单向的,自底向上:

types          定义与工具:错误类型、Tier/ObjectRef、协议常量、checksum/NUMA、在飞门禁
config         三层配置解析(代码 > 环境变量 > YAML)与设备探测
observability  日志 / operation 日志 / 调用链 span / Prometheus 指标
io  memory  backends   字节搬运 / 池与索引 / 非 mooncake 后端
transport      与 mooncake 打交道的唯一出口(apis 与 store 不直接调原生库)
apis           数据面七族 mixin
store          UniStore 门面:组装 mixin + 独占生命周期

backend_mode 有两种取值:mooncake(默认,分布式内存)和 shared(纯共享文件)。 在 Mooncake 后端,put 默认使用 mode="memory"。需要额外写一份共享文件副本并等待落盘时,配置 UNISTORE_SHARED_DIR 并传入 mode="disk"。共享文件后端的写入都落到共享目录。

每个文件里"哪一段负责什么、为什么这么放"见 docs/internals.md 第一部分。

文档

只有三份,加上给 AI 代理看的红线清单:

  • docs/api.md — 使用指南:安装、部署、全部公共 API、异步、内存池、监控
  • docs/internals.md — 代码结构导读 / 依赖取舍 / 性能口径与实测基线
  • AGENTS.md — 改代码红线、测试矩阵、踩坑记录(人也建议读)

验证

ruff check .                           # pyflakes + 120 列(规则见 pyproject.toml)
python -m pytest tests/unit -q         # 首选质量门,全离线
bash tests/e2e/run_all.sh              # 需要真实 master

ruff 也由 pre-commit 托管(pre-commit install),与 ruff check . 共用 pyproject 里的规则。

Metadata

Release files for unistore 0.0.1

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

Built distribution (wheel)

Table of built distributions (wheels) for unistore 0.0.1
File Interpreter ABI Platform Actions
unistore-0.0.1-py3-none-any.whl Python 3 none any Details for unistore-0.0.1-py3-none-any.whl

Release files / unistore-0.0.1-py3-none-any.whl

Download URL unistore-0.0.1-py3-none-any.whl
Size 242.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
78bbcdafd944d894d2b10dd71e5e269b87b976b8560c63939e517d853daa4784
BLAKE2b-256 checksum
How to use checksums
ef0ebc4788f69ba47d24ca27d56b0cdfd2deeeb813279735d11d262f76e74342
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.19

Security for unistore 0.0.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.

Release history Release notifications | RSS feed

This release

0.0.1 This release

1 release file No provenance

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