触发问题

「数据集这块怎么做的?」(2026-11-04,harbor-framework/harbor)

harbor 讲功能层,harbor-deep-dive 讲 Job→Trial→Verifier 调用链,两页都只把数据集当一行覆盖矩阵。本页补中间那层:任务从哪来、怎么落到本地、版本怎么锁、跑完怎么聚合。行号基于本地 clone 的 v0.25.0-40-g00dc6a70(2026-11-02),未实机运行。

一条判断

数据集在 Harbor 里只是「一组 task id + 一个聚合指标」,不是运行单元。 运行时真正被编排的是 TaskConfig,数据集在 JobPlan.resolve_task_configs()(job_plan.py:117)就被展开掉了。理解这一点,后面所有设计都顺:dataset.toml 只存指针、registry 可以用任意 JSON 提供、换后端只换 id 的类型。

三层对象

层定义载体代码
Task最小评测单元目录:instruction.md + task.toml + environment/ + tests/ + 可选 solution/models/task/task.py:101 is_valid_dir
Dataset一组 task,可带聚合指标隐式目录 / dataset.toml / registry 里的一条记录models/job/config.py:24 DatasetConfig
Registry数据集解析来源Hub 包注册中心 / registry.json / Git 仓库registry/client/factory.py:11

task 与 dataset 是 many-to-many(adapters/ADAPTER_CONTRIBUTING.md:512):同一 task 可属于多个数据集,所以 dataset.toml 只写指针、绝不复制 task 内容。

四种取数入口

全部由 DatasetConfig 的扁平字段决定(models/job/config.py:24),判定在 :108-118:

def is_repo(self):      return self.repo is not None
def is_local(self):     return self.path is not None and self.repo is None
def is_package(self):   return self.repo is None and self.name is not None and "/" in self.name
def is_registry(self):  return self.repo is None and self.name is not None and "/" not in self.name
入口命令展开实现产出 id
本地目录-p ./my-dataset_get_local_task_configs(config.py:174),iterdir() + is_valid_dir() 过滤LocalTaskId
Hub 包-d org/name@v1.0PackageDatasetClient(registry/client/package.py),Supabase 查版本与任务边PackageTaskId(org, name, sha256:…)
JSON registry-d name@version --registry-url/--registry-pathJsonRegistryClient(registry/client/json.py)GitTaskId / LocalTaskId
Git 仓库--repo org/repo@ref [-p subdir / -d name]GitRepoRegistryClient(registry/client/git_repo.py)GitTaskId

两个容易踩的点:

  • 默认注册中心有两套。RegistryClientFactory.create() 不带参数时走 HarborRegistryClient(Hub/Supabase);但 harbor dataset list 不带参数时显式走 PackageDatasetClient(cli/datasets.py:107-120)。数据源不同,列表结果可能不一致。
  • --repo 把 path 和 registry_path 变成 repo 相对路径,不是本地路径(config.py:79-99)。

三种 task id 与缓存布局

models/task/id.py:

id字段本地落点
GitTaskId(:24)git_url / git_commit_id / path~/.cache/harbor/tasks/<shortuuid>/<task 名>
PackageTaskId(:55)org / name / ref~/.cache/harbor/tasks/packages/<org>/<name>/<content_hash>
LocalTaskId(:43)path原地使用,不复制

PackageTaskId 是内容寻址:目录名就是 sha256 摘要,同一版本天然只存一份、天然不可变。GitTaskId 靠 git_commit_id 锁定;path 做了 .. 逃逸校验(normalize_git_task_path,:12)。

下载链路(tasks/client.py)

download_tasks()(:586)按 id 类型分三路并发:

Git 路径(_download_tasks_from_git_url,:233):

  1. 按 git_url 分组,每个仓库只 clone 一次:--depth 1 --no-checkout --filter=blob:none;HuggingFace 例外不带 filter,因为它的 git server 不支持 promisor lazy blob,后续 checkout <sha> 会 fatal: expected 'packfile'(:264-272 有注释说明)。
  2. 稀疏检出:把所有 task 的相对路径拼成 git sparse-checkout set --no-cone --stdin,只落需要的目录(--stdin 是为了绕开 Windows 命令行长度限制)。
  3. 分两批 checkout:git_commit_id 为空 = 跟默认分支,checkout 后 rev-parse HEAD 回填真实 commit;有 commit 的走 git fetch --depth 1 origin <sha> + checkout <sha>,保证同一批里不同 commit 都能取到。
  4. LFS 单独拉(_pull_lfs_files,:113):按 task path 拼 lfs include;没装 git-lfs 只 warn 不失败——静默拿到 LFS 指针文件是最常见的隐性损坏。
  5. 失效判定(:505-515):目录不存在 / --overwrite / commit 不是 40 或 64 位 hex(说明没锁死)/ 目录存在但为空。

包路径(_download_package_tasks,:368):先查 digest 缓存目录是否已存在,命中直接返回;否则从 storage 下 dist.tar.gz 解包到 <org>/<name>/<hash>。并发上限 100(max_concurrency)。

本地路径(_download_local_tasks,:477):只校验存在,不做任何拷贝。

两种落盘布局(:600-604 注释):

  • export=True → <output>/<task-name>/,扁平,重名会直接报错(:617-632)
  • export=False → 缓存布局,带 hash,允许重名

harbor datasets download 默认 export(cli/datasets.py:295-301),所以 -o 不给时会下到当前目录。

registry.json 与 dataset.toml 的职责边界

registry.json(models/registry.py:66)是 JSON 数组,一条记录 = 数据集的一个版本:

{"name": "...", "version": "...", "description": "...",
 "tasks": [{"name": "...", "git_url": "...", "git_commit_id": "<40位 sha>", "path": "..."}],
 "metrics": [{"type": "mean", "kwargs": {}}]}

本机 HEAD 上实测:80 条数据集版本、75 个唯一名、51,625 条 task 引用;最大 code-contests 9,644 题、kumo 5,300、simpleqa 4,326;terminal-bench@2.0 89、terminal-bench-pro@1.0 200。adapters/ 下 85 个目录是这些数据集的来源实现。

dataset.toml(models/dataset/manifest.py:161)是发布清单:

[dataset]
name = "org/name"
version = "1.0.0"
[[tasks]]
name = "org/task-name"
digest = "sha256:<64 hex>"
[[files]]
path = "metric.py"
  • DatasetTaskRef.digest 必须是 sha256:<64 hex>(:24 起有强校验),即 task 的 content hash
  • compute_content_hash()(:249)对排序后的 task digest 与 file digest 再算一次 sha256 —— 这就是发布出的数据集版本哈希
  • 空任务集是合法的「纯文件数据集」,只是不能跑

内容哈希怎么来的:publisher/packager.py:88 compute_content_hash 收集 task.toml/instruction.md/README.md/trajectory/environment//tests//solution//steps/,按 <相对路径>\0<文件sha256>\n 排序累加。.harborignore 会同时影响上传、发布与哈希——改它等于改版本。

发布走 publisher/publisher.py:409 publish_dataset:先传 dataset 级文件(如 metric.py)到 storage,再 RPC 写版本,applied_tags = {"latest"} | tags——每次 publish 自动获得 latest。

选版规则在 registry/client/base.py:35 resolve_version:head 优先,其次 PEP440 最高,最后字典序最大。所以省略 @version 时拿到的可能是移动目标 head,跨版本对比必须显式锁版本。

Adapter:一个新 benchmark 怎么变成数据集

adapters/ADAPTER_CONTRIBUTING.md 的九步,只有四条是硬门槛:

  1. 脚手架:harbor adapter init 生成 src/<name>/{adapter.py, main.py, task-template/};main.py 必须支持 --output-dir / --limit / --overwrite / --task-ids
  2. 命名:每个生成的 task.toml 必须带 name 字段,唯一且 registry-safe(小写、特殊字符转连字符),否则注册不进去
  3. oracle 100% 通过(:249):这是区分「adapter 写错」「oracle 本身坏」「环境装不起来」的唯一手段。oracle 挂了不要先怀疑模型
  4. parity 是验收线(:323 起):两侧同 agent、同带日期的模型 id、同安装脚本、同启动参数、同 prompt;判定标准是跑分区间重叠
    max(A) >= min(B) and max(B) >= min(A)
    
    且必须报 mean ± sample SEM(不是样本标准差);n < 2 时 SEM 无定义,要求每侧 ≥2 次、推荐 3 次
  5. 执行顺序强制对称:两侧各跑 5-10 题 sanity → 两侧各 1 次全量 → 两侧各 3 次。不允许先把一侧跑满三次

大基准允许只跑 parity 子集,但要支持 --split parity 并把子集单独发成 @parity。结果先传 HuggingFace harborframework/parity-experiments(目录结构固定,见 :486 起),再提 PR 到 laude-institute/harbor-datasets,由官方 publish。

聚合指标

默认 mean,缺失记 0;多维 reward 按 key 各自聚合(metrics/base.py aggregate_reward_dicts)。内置五种(models/metric/type.py):sum / min / max / mean / uv-script。

uv-script 就是 metric.py 的契约,极简:

uv run metric.py -i rewards.jsonl -o metric.json

输入是每行一个 reward 对象或 null,输出是 {"mean": 0.31} 这类扁平数字对象(models/dataset/manifest.py:75 DatasetFileRef 会把它钉进数据集哈希)。

聚合 key 是 agent__model__dataset(job_plan.py:391 evals_key_for_result),dataset 取自 task_config.source——本地数据集取目录名,包数据集取数据集名。所以同名任务来自不同数据集时不会被合到一起。

三处代码与文档不一致

前两条已被 harbor-as-orchestration-base 先行记录并附了 issue/PR 号,这里补源码位置做交叉验证:

  1. harbor run -p <path-to-dataset.toml> 会崩(issue #3960,修复 PR #3919 未合并) docs-mintlify/datasets/create-a-dataset.mdx:71 明确写支持,但 _get_local_task_configs(config.py:174)只做 self.path.iterdir(),传文件直接 NotADirectoryError;全库 MANIFEST_FILENAME 只命中 add/sync/publish/remove/lint,运行链路没有读 dataset.toml 的入口。dataset.toml 只服务发布链路,不服务运行链路。

  2. 本地数据集的 metric.py 不生效(修复 PR #2852 未合并) docs-mintlify/datasets/metrics.mdx:14 说本地数据集会自动用目录里的 metric.py;但 job.py:816 / job_plan.py:194 的 _resolve_dataset_metrics 只在 package 分支挂 UvScript,local 分支只挂 job 级 metrics。要自定义聚合,走 job config 的 metrics: [{type: uv-script, kwargs: {script_path: ...}}]。

  3. task_names glob 只按 task_id.get_name() 匹配 config.py:120 _filter_task_ids 用 fnmatch 匹配;git/package id 的 get_name() 是目录名或 org/name,所以 -i/-x 的 pattern 不能带路径。匹配不上时会列出可选项报错,这点设计得还算友好。

实操建议

  • 自己造数据集:harbor dataset init org/name → task 目录放一起 → harbor dataset add <task-dir>(自动算 digest)→ harbor run -p <dataset-dir> 本地验证 → harbor publish
  • 追上游基准:永远显式 -d <name>@<version>,别依赖默认(可能是 head)
  • 内网/空气隔离:--registry-path 指本地 registry.json、--repo 指内网 Git,Hub 不是必需
  • 省磁盘:走包数据集(内容寻址,同 hash 只存一份),别用 export 扁平布局(还会因重名报错)
  • 复现对比:确认 registry 里 git_commit_id 是 40 位 hex;缺失时 Harbor 会当 head 重拉,跨版本比较立刻失效

相关页面