Files
aigc-home/docs/hel-892/review_fourth_fields.py
T

364 lines
18 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Render source-bound fourth-batch decisions; never infer plugin definitions.
The prose decisions below are curated for the sixteen SHA-bound prior reviews.
Connection descriptions and exact values are mechanical evidence, not semantics.
Run once against 1390489 data. The resulting per-field records are runtime data.
"""
import copy
import hashlib
import json
from collections import Counter
from pathlib import Path
REPO = Path(__file__).resolve().parents[2]
BASE = REPO / "docs/hel-892"
DEST = BASE / "fourth-evidence"
def write(path, value):
path.write_text(
json.dumps(value, ensure_ascii=False, indent=2) + "\n", encoding="utf-8"
)
# These descriptions identify the source-side use, without promising units,
# valid ranges, special zero values, device availability, or adjustment effects.
COMMON = {
"video": "加载节点的视频素材选择;核对现值文件是否为本分支所需素材",
"image": "加载节点的图像素材选择;核对文件与下游参考槽的对应关系",
"force_rate": "视频读取阶段的强制帧率控件;零值含义不能从源图确认",
"custom_width": "素材加载阶段的自定义宽度控件;零值含义待节点定义",
"custom_height": "素材加载阶段的自定义高度控件;零值含义待节点定义",
"frame_load_cap": "视频读取上限控件;核对截取分支,不能把零直接解释为无限",
"image_load_cap": "文件夹图像读取上限控件;零值约定待定义",
"skip_first_frames": "视频读取的起始跳过控件;核对两路视频的起点是否匹配",
"skip_first_images": "图像序列起始跳过控件;核对文件夹中的素材排序",
"select_every_nth": "素材读取的间隔选择控件;实际抽帧规则待定义",
"frame_rate": "合成节点帧率设置;核对是否另有输入连线覆盖该控件",
"loop_count": "合成阶段的循环次数控件;零值约定和格式适用性待定义",
"filename_prefix": "输出命名前缀;核对输出分支和目录用途,实际落盘位置待环境核对",
"pix_fmt": "视频合成的像素格式选择;与编码格式配套核对",
"crf": "视频合成编码设置;仅确认处于合成步骤,不给出质量范围或调整效果",
"save_metadata": "视频合成的保存元数据开关;具体保存内容待插件定义",
"trim_to_audio": "视频合成的音频裁剪开关;先核对本节点是否接入音轨",
"pingpong": "视频合成的Ping-Pong控件;具体帧序列规则待插件定义",
"save_output": "视频合成的保存输出开关;源开关不等于当前已经生成或保存",
"width": "本节点的宽度设置;核对下游宽度槽及有无外部连线供值",
"height": "本节点的高度设置;核对下游高度槽及有无外部连线供值",
"batch_size": "空潜空间的批量设置;核对其后采样分支",
"seed": "采样节点种子现值;仅为本次源设置,不保证跨环境复现",
"noise_seed": "随机噪声节点种子现值;核对所接采样器的noise输入",
"cfg": "采样或引导节点的CFG设置;核对其正负条件和模型来源",
"sampler_name": "采样算法选择;核对当前采样分支及目标节点支持情况",
"scheduler": "采样调度选择;核对同一分支的模型和步数设置",
"steps": "调度/采样步骤设置;不能由模型文件名中的step字样替代现值",
"denoise": "本采样分支的denoise设置;不能据数值承诺去噪程度或合法范围",
"unet_name": "扩散模型文件引用;核对下游模型链,源引用不证明模型已安装",
"weight_dtype": "扩散模型加载的数据类型选择;不推断显存或速度",
"clip_name": "文本编码器文件引用;核对下游clip槽及模型配套",
"vae_name": "VAE文件引用;结合下游vae/audio_vae槽核对音视频分工",
"lora_name": "LoRA文件引用;核对本节点的输入模型及下游补丁顺序",
"strength_model": "LoRA模型强度设置;核对同链其他LoRA,不能承诺调整效果",
"device": "本节点设备选择;源现值不证明目标设备可用",
"type": "CLIP加载器的编码器类型选择;核对下游模型配套",
"delimiter": "文本拼接分隔字符串;检查拼接两侧文字及下游prompt连线",
"string_a": "拼接文本的A侧字面量;核对其触发词与实际LoRA文件引用",
"string_b": "拼接文本的B侧字面量;核对开关选中的提示词分支",
"text": "文本编码的字面量;结合正负条件的实际出口核对,空串保持原值",
"prompt": "条件编码的提示词字面量;核对正负条件出口,空串不自动补写",
"system_prompt": "条件编码的系统提示词字段;空串保持原值,默认模板行为待定义",
"aspect_ratio": "分辨率选择器的比例设置;核对输出0/1实际接入的宽高槽",
"megapixels": "分辨率选择器的规模设置;具体尺寸计算与取整规则待定义",
"multiple": "分辨率选择器的倍数约束设置;算法与合法范围待定义",
"upscale_method": "图像缩放方法选择;核对该图的参考图或上下文帧分支",
"keep_proportion": "图像缩放的比例处理选择;核对pad/resize现值,算法待定义",
"pad_color": "图像缩放的填充颜色字段;具体颜色格式及生效条件待定义",
"crop_position": "图像缩放的裁切位置选择;是否在当前模式生效待定义",
"divisible_by": "图像缩放的整除约束设置;实际取整结果待定义",
"scale_method": "图像/遮罩缩放的方法选择;结合接入尺寸槽核对",
"resize_type": "图像缩放模式选择;核对同节点所接尺寸或倍率字段",
"resize_type.scale": "缩放模式的具名倍率子字段;实际尺寸计算待插件定义",
"quality": "超分节点的质量档位选择;硬件支持与实际效果待验证",
"multiplier": "插帧节点的倍率设置;核对后续帧率表达式,不推断音轨已同步",
"sigmas": "手工噪声调度字符串;核对采样器sigmas连线,解析规则待定义",
"tile_size": "分块VAE解码的空间块设置;核对samples和vae来源",
"overlap": "分块VAE解码的空间重叠设置;约束关系待定义",
"temporal_size": "分块VAE解码的时间块设置;具体单位及限制待定义",
"temporal_overlap": "分块VAE解码的时间重叠设置;约束关系待定义",
}
def decision(node, field):
ct = node["class_type"]
if field in {
"choose video to upload",
"Update inputs",
"PowerLoraLoaderHeaderWidget",
"➕ Add Lora",
}:
return (
"frontend_state",
"前端上传/编辑控件状态;不确认为运行参数,不能原样冒充服务端输入",
)
if ct == "Power Lora Loader (rgthree)":
return (
"current_value_only",
"结构化LoRA控件仅可核对on/lora/strength现值及模型引用;服务端拆分序列化规则未知",
)
if ct == "SolAttnPatch":
return (
"semantic_unknown",
"仅确认位于LoRA之后、Sage补丁之前的模型链;此自定义注意力字段的算法含义无法从源图确认",
)
if ct in {"MiniMaxH3SigmaShift", "Krea2EditModelPatch"} or field in {
"grounding_px",
"ref_image_size",
}:
return (
"semantic_unknown",
"仅确认字段所属条件/模型补丁步骤和连线;此自定义字段的具体含义无法从源图确认,保留现值待定义",
)
if ct == "TextGenerate":
return (
"current_value_only",
"属于提示词改写分支的具名生成设置;仅确认现值与on_true出口,不由字段名推定采样算法、单位或效果",
)
if ct == "PathchSageAttentionKJ":
return (
"current_value_only",
"位于模型链的Sage补丁节点;具体注意力模式、编译开关行为和设备约束仍待插件定义",
)
if ct == "LTXVImgToVideoInplace":
return "semantic_unknown", (
"LTX二段潜空间链的图像注入字段;bypass是输入字段而非"
"UI节点mode,真实执行分支和strength含义待定义"
)
if ct == "ImageBatchMulti":
return (
"current_value_only",
"源图两路image_1/image_2接入本节点;inputcount现值可核对,动态槽的前端更新规则尚未知",
)
if field == "format":
return "runtime_parameter", (
"视频合成的编码格式选择;与pix_fmt及音轨连线配套核对"
if ct == "VHS_VideoCombine"
else "素材加载的格式选择;AnimateDiff/LTXV是此加载字段现值,不能当作最终输出封装格式"
)
if field == "model_name":
return (
"runtime_parameter",
"插帧/潜空间放大模型文件引用;核对下游模型槽,不证明文件已安装",
)
if field == "expression":
return (
"runtime_parameter",
"源表达式作为本图计算步骤;逐字保留并核对输入a和输出槽,不声明插件解析或取整行为已验证",
)
if field == "value":
if ct == "PrimitiveBoolean":
return (
"runtime_parameter",
"布尔源值控制下述switch输入;标题只作辅助,不能忽略实际on_true/on_false连线",
)
if ct == "PrimitiveStringMultiline":
return (
"runtime_parameter",
"多行文本源值供给下述提示词/拼接输入;系统提示词、用户词及共用两段条件须按实际出口核对",
)
if ct == "SolidMask":
return (
"runtime_parameter",
"常量遮罩值接入音频潜空间的mask链;不据数值推断遮罩反转或重绘效果",
)
return (
"runtime_parameter",
"浮点源值供给下述duration/FPS/规模计算输入;以实际连线核对用途,不从标题推导单位范围",
)
assert field in COMMON, (ct, field)
return "runtime_parameter", COMMON[field]
def main():
DEST.mkdir(exist_ok=True)
review_path = REPO / ("calliope-backend/src/calliope/comfyui/source_reviews.json")
reviews = json.loads(review_path.read_text())
assert not any(r.get("fourth_review") for r in reviews.values()), "already rendered"
baseline = copy.deepcopy(reviews)
manifest = json.loads((BASE / "offline/manifest.json").read_text())
prior_ids, mechanical, added = [], [], []
file_rows = []
markdown = [
"# 第四批逐字段审校",
"",
(
"类别是源侧用途的局部结论;runtime_parameter"
"也不代表单位/范围/效果已确认。连线和现值由工具原样整理。旧"
"542项保留,新685项列于下文。"
),
"",
]
for entry in manifest:
path = entry["path"]
doc = json.loads((BASE / "offline" / entry["document"]).read_text())
review = reviews[path]
raw = (REPO / path).read_bytes()
assert (
hashlib.sha1(raw).hexdigest() == review["source_sha"] == entry["source_sha"]
)
previous = {
(p["node_id"], p["field"]) for p in review.get("reviewed_named_fields", [])
}
prior_ids.extend([path, *key] for key in sorted(previous))
mechanical.extend([path, p["node_id"], p["field"]] for p in doc["params"])
remaining = [
p for p in doc["params"] if (p["node_id"], p["field"]) not in previous
]
if not remaining:
continue
assert "semantic_review" not in review
source = json.loads(raw)
ui = "nodes" in source
rows = []
markdown += [
f"## {path}",
f"SHA1 `{entry['source_sha']}`;本批 {len(remaining)} 项。",
"",
]
for p in remaining:
nid, field = p["node_id"], p["field"]
node = next(n for n in doc["source_nodes"] if n["node_id"] == nid)
incoming, outgoing = [], []
if ui:
original = next(n for n in source["nodes"] if str(n["id"]) == nid)
source_pointer = (
f"/nodes/{source['nodes'].index(original)}/widgets_values/{field}"
)
for i, link in enumerate(source.get("links", [])):
if str(link[1]) == nid or str(link[3]) == nid:
ref = {"pointer": f"/links/{i}", "link": link}
(outgoing if str(link[1]) == nid else incoming).append(ref)
socket = next(
(s for s in original.get("inputs", []) if s["name"] == field), None
)
binding = socket
else:
source_pointer = "/" + nid + "/inputs/" + field
incoming = [
{"field": k, "link": v}
for k, v in source[nid]["inputs"].items()
if isinstance(v, list)
]
outgoing = [
{"node_id": target, "field": k, "link": v}
for target, n in source.items()
for k, v in n["inputs"].items()
if isinstance(v, list) and len(v) == 2 and v[0] == nid
]
binding = None
category, meaning = decision(node, field)
where = json.dumps(
{"incoming": incoming, "outgoing": outgoing}, ensure_ascii=False
)
checks = [
"核对上述节点/槽位的素材、模型或提示词对应关系;缺连线不推断其为有效主路径。"
]
if node["mode"] != 0:
checks.append(
f"源mode={node['mode']};属于非普通模式,不把保存的控件设置当作有效执行分支。"
)
if binding and binding.get("link") is not None:
checks.append(
f"同名输入槽另接link={binding['link']};保存控件值不代表实际输入值,优先级待真实导出核对。"
)
if not outgoing:
checks.append(
"源未列本节点下游连线;是否输出节点及是否被提交仍须原前端导出核对。"
)
row = {
"node_id": nid,
"field": field,
"label": meaning,
"source_value": p["default"],
"category": category,
"scope": "源用途局部审校;单位/合法范围/调整效果均未确认",
"source_path": path,
"source_sha": entry["source_sha"],
"class_type": node["class_type"],
"source_pointer": source_pointer,
"source_title": node["title"],
"mode": node["mode"],
"input_socket": binding,
"connections": {"incoming": incoming, "outgoing": outgoing},
"operation_check": "".join(checks),
"evidence_kind": (
"curated_source_use_with_mechanical_values_and_connections"
),
}
rows.append(row)
added.append([path, nid, field])
markdown += [
f"- `{nid}` {node['class_type']}.`{field}`({category}),现值:`{json.dumps(p['default'], ensure_ascii=False)}`。{meaning}。{row['operation_check']} 源指针 `{source_pointer}`;连线 `{where}`。"
]
review["reviewed_named_fields"].extend(rows)
review["fourth_review"] = {
"batch": "HEL-892-fourth",
"fields": [[f["node_id"], f["field"]] for f in rows],
"classification_counts": dict(Counter(f["category"] for f in rows)),
"operation_check": f"本图新增{len(rows)}项具名字段局部审校;逐项按source_review.reviewed_named_fields的具体连线和operation_check核对;前端状态、仅现值和语义未知项不可当作已确认运行语义。",
"unknowns": [
"全部单位、范围、调整效果待可信节点定义;本图未实跑",
"不更改原图矛盾;原有说明与此前审校完整保留",
],
}
file_rows.append(
{
"path": path,
"source_sha": entry["source_sha"],
"document": entry["document"],
"prior_fields": len(previous),
"added_fields": len(rows),
"classification_counts": review["fourth_review"][
"classification_counts"
],
}
)
assert len(prior_ids) == 542 and len(mechanical) == 1227 and len(added) == 685
assert len(file_rows) == 16
assert len({tuple(k) for k in mechanical}) == 1227
assert {tuple(k) for k in mechanical} - {tuple(k) for k in prior_ids} == {
tuple(k) for k in added
}
write(
DEST / "field-partition.json",
{
"baseline_commit": "1390489",
"mechanical_1227": mechanical,
"prior_542": prior_ids,
"added_685": added,
"files": file_rows,
"prior_review_sha256": {
p: hashlib.sha256(
json.dumps(r, ensure_ascii=False, sort_keys=True).encode()
).hexdigest()
for p, r in baseline.items()
},
},
)
write(review_path, reviews)
(BASE / "逐字段第四批审校.md").write_text(
"\n".join(markdown) + "\n", encoding="utf-8"
)
print(
Counter(
f["category"]
for r in reviews.values()
for f in r["reviewed_named_fields"]
if "category" in f
)
)
if __name__ == "__main__":
main()