fix: make pools.json freeze atomic + add split manifest
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
"""结果驱动视频级切分的冻结溯源 manifest。
|
||||
|
||||
冻结的 pools.json 是切分产物;manifest 记录产出这份切分的关键输入
|
||||
(baseline_run_id、诊断指纹、随机种子、配置)与 pools.json 的内容指纹
|
||||
(pools_sha256),供后续 build_split 写溯源、以及复现校验时比对。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import hashlib
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from app.harness.pools import _atomic_write_json
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def write_manifest(
|
||||
path: Path,
|
||||
*,
|
||||
baseline_run_id: str,
|
||||
diag_fingerprint: str,
|
||||
seed: int,
|
||||
config: dict,
|
||||
pools_json_text: str,
|
||||
coverage_report: dict,
|
||||
generated_at: str,
|
||||
) -> dict:
|
||||
"""写切分冻结溯源 manifest(原子写),返回写入的 dict。
|
||||
|
||||
pools_sha256 = sha256(pools_json_text),供复现时校验冻结的 pools.json 内容
|
||||
是否与本次切分一致。generated_at 由调用方传入(库内不用 datetime.now),
|
||||
以保证相同输入产出相同 manifest,可复现。
|
||||
|
||||
参数:
|
||||
path: manifest 目标 JSON 文件路径。
|
||||
baseline_run_id: 产出本次切分所依据的基线 run 标识。
|
||||
diag_fingerprint: 诊断结果指纹(决定 train/val 归属的输入)。
|
||||
seed: 切分使用的随机种子。
|
||||
config: 切分相关配置快照(如 train_ratio 等)。
|
||||
pools_json_text: 冻结的 pools.json 完整文本,用于计算内容指纹。
|
||||
coverage_report: 各类别 train/val 覆盖统计报告。
|
||||
generated_at: 生成时间戳(ISO 字符串),由调用方传入。
|
||||
|
||||
返回:
|
||||
写入 manifest 的 dict(与落盘内容一致)。
|
||||
"""
|
||||
manifest = {
|
||||
"baseline_run_id": baseline_run_id,
|
||||
"diag_fingerprint": diag_fingerprint,
|
||||
"seed": seed,
|
||||
"config": config,
|
||||
"pools_sha256": hashlib.sha256(pools_json_text.encode("utf-8")).hexdigest(),
|
||||
"coverage_report": coverage_report,
|
||||
"generated_at": generated_at,
|
||||
}
|
||||
_atomic_write_json(path, manifest)
|
||||
return manifest
|
||||
Reference in New Issue
Block a user