505 lines
20 KiB
Python
505 lines
20 KiB
Python
"""Static exact-declaration reference; parse source AST without executing plugins."""
|
|
|
|
import ast
|
|
import copy
|
|
import hashlib
|
|
import json
|
|
from pathlib import Path
|
|
|
|
REPO = Path(__file__).resolve().parents[3]
|
|
OUT = Path(__file__).resolve().parent
|
|
REF = OUT.parent / "wantalk-reference"
|
|
PATHS = [
|
|
"example_ComfyUI_workflows/5-数字人/Wan2.1_I2V_InfiniteTalk_提示词调度动作控制图生视频数字人(KJ版).json"
|
|
]
|
|
BINDINGS = {
|
|
"307": ("layer", "py/image_scale_by_aspect_ratio_v2.py", "ImageScaleByAspectRatioV2"),
|
|
"316": ("wan373", "nodes_model_loading.py", "WanVideoBlockSwap"),
|
|
"170": ("audio", "src/separation.py", "AudioSeparation"),
|
|
"293": ("core0350", "comfy_extras/nodes_preview_any.py", "PreviewAny"),
|
|
"291": ("kj6df", "nodes/image_nodes.py", "GetImageSizeAndCount"),
|
|
"237": ("wanff", "nodes.py", "WanVideoClipVisionEncode"),
|
|
"128": ("wanc3", "nodes.py", "WanVideoSampler"),
|
|
"238": ("core0350", "nodes.py", "CLIPVisionLoader"),
|
|
"194": ("wan3d", "multitalk/nodes.py", "MultiTalkWav2VecEmbeds"),
|
|
"306": ("wan058", "nodes.py", "LoadWanVideoT5TextEncoder"),
|
|
"137": ("wan058", "nodes.py", "DownloadAndLoadWav2VecModel"),
|
|
"318": ("wan373", "multitalk/nodes.py", "Wav2VecModelLoader"),
|
|
"305": ("wanbd", "nodes.py", "WanVideoTextEncode"),
|
|
"314": ("cr", "nodes/nodes_core.py", "CR_PromptText"),
|
|
"138": ("wan058", "nodes.py", "WanVideoLoraSelect"),
|
|
"192": ("wan494", "multitalk/nodes.py", "WanVideoImageToVideoMultiTalk"),
|
|
"159": ("audio", "src/crop.py", "AudioCrop"),
|
|
"130": ("wanc3", "nodes.py", "WanVideoDecode"),
|
|
"131": ("combine", "videohelpersuite/nodes.py", "VideoCombine"),
|
|
"284": ("core0350", "nodes.py", "LoadImage"),
|
|
"125": ("core0341", "comfy_extras/nodes_audio.py", "LoadAudio"),
|
|
"319": ("kj136", "nodes/nodes.py", "INTConstant"),
|
|
"320": ("kj136", "nodes/nodes.py", "INTConstant"),
|
|
"122": ("wan058", "nodes.py", "WanVideoModelLoader"),
|
|
"129": ("wanc3", "nodes.py", "WanVideoVAELoader"),
|
|
"120": ("wan058", "nodes.py", "MultiTalkModelLoader"),
|
|
}
|
|
LAYOUTS = {
|
|
"307": [
|
|
"aspect_ratio",
|
|
"proportional_width",
|
|
"proportional_height",
|
|
"fit",
|
|
"method",
|
|
"round_to_multiple",
|
|
"scale_to_side",
|
|
"scale_to_length",
|
|
"background_color",
|
|
],
|
|
"316": [
|
|
"blocks_to_swap",
|
|
"offload_img_emb",
|
|
"offload_txt_emb",
|
|
"use_non_blocking",
|
|
"vace_blocks_to_swap",
|
|
"prefetch_blocks",
|
|
"block_swap_debug",
|
|
],
|
|
"170": ["chunk_fade_shape", "chunk_length", "chunk_overlap"],
|
|
"293": ["position_0", "position_1", "position_2"],
|
|
"237": [
|
|
"strength_1",
|
|
"strength_2",
|
|
"crop",
|
|
"combine_embeds",
|
|
"force_offload",
|
|
"tiles",
|
|
"ratio",
|
|
],
|
|
"128": [
|
|
"steps",
|
|
"cfg",
|
|
"shift",
|
|
"seed",
|
|
"control_after_generate",
|
|
"force_offload",
|
|
"scheduler",
|
|
"riflex_freq_index",
|
|
"denoise_strength",
|
|
"batched_cfg",
|
|
"rope_function",
|
|
"start_step",
|
|
"end_step",
|
|
"add_noise_to_samples",
|
|
],
|
|
"238": ["clip_name"],
|
|
"194": [
|
|
"normalize_loudness",
|
|
"num_frames",
|
|
"fps",
|
|
"audio_scale",
|
|
"audio_cfg_scale",
|
|
"multi_audio_type",
|
|
"add_noise_floor",
|
|
"smooth_transients",
|
|
],
|
|
"306": ["model_name", "precision", "load_device", "quantization"],
|
|
"137": ["position_0", "position_1", "position_2"],
|
|
"318": ["model", "base_precision", "load_device"],
|
|
"305": ["positive_prompt", "negative_prompt", "force_offload", "use_disk_cache", "device"],
|
|
"314": ["prompt"],
|
|
"138": ["lora", "strength", "low_mem_load", "merge_loras"],
|
|
"192": [f"position_{i}" for i in range(9)],
|
|
"159": ["start_time", "end_time"],
|
|
"130": [
|
|
"enable_vae_tiling",
|
|
"tile_x",
|
|
"tile_y",
|
|
"tile_stride_x",
|
|
"tile_stride_y",
|
|
"normalization",
|
|
],
|
|
"284": ["image", "upload"],
|
|
"125": ["audio", "audioUI", "upload"],
|
|
"319": ["value"],
|
|
"320": ["value"],
|
|
"122": [
|
|
"model",
|
|
"base_precision",
|
|
"quantization",
|
|
"load_device",
|
|
"attention_mode",
|
|
"rms_norm_function",
|
|
],
|
|
"129": ["model_name", "precision", "use_cpu_cache", "verbose"],
|
|
"120": ["position_0"],
|
|
}
|
|
LABELS = {
|
|
"aspect_ratio": "比例策略",
|
|
"proportional_width": "自定比例宽",
|
|
"proportional_height": "自定比例高",
|
|
"fit": "适配方式",
|
|
"method": "缩放方法",
|
|
"round_to_multiple": "对齐倍数字符串",
|
|
"scale_to_side": "缩放边策略",
|
|
"scale_to_length": "目标边长缓存(受564覆盖)",
|
|
"background_color": "背景颜色字符串",
|
|
"blocks_to_swap": "迁移块数",
|
|
"offload_img_emb": "图像嵌入卸载",
|
|
"offload_txt_emb": "文本嵌入卸载",
|
|
"use_non_blocking": "非阻塞迁移",
|
|
"vace_blocks_to_swap": "VACE迁移块数",
|
|
"prefetch_blocks": "预取块数",
|
|
"block_swap_debug": "块迁移调试开关",
|
|
"chunk_fade_shape": "分段淡化方式",
|
|
"chunk_length": "分段长度",
|
|
"chunk_overlap": "重叠原值(提示与公式分列)",
|
|
"strength_1": "第一图嵌入强度",
|
|
"strength_2": "第二图嵌入强度原精确小数",
|
|
"crop": "视觉裁切策略",
|
|
"combine_embeds": "嵌入合并策略",
|
|
"force_offload": "卸载条件保存",
|
|
"tiles": "视觉分块数",
|
|
"ratio": "视觉分块比例",
|
|
"steps": "步数缓存",
|
|
"cfg": "CFG精确小数",
|
|
"shift": "shift精确小数",
|
|
"seed": "独立seed缓存",
|
|
"control_after_generate": "种子前端辅助randomize",
|
|
"scheduler": "调度器原名",
|
|
"riflex_freq_index": "RIFLEX索引",
|
|
"denoise_strength": "降噪强度",
|
|
"batched_cfg": "CFG批处理",
|
|
"rope_function": "RoPE选择",
|
|
"start_step": "额外起始步保存(准确schema无此项)",
|
|
"end_step": "额外结束步保存(准确schema无此项)",
|
|
"add_noise_to_samples": "额外加噪保存(准确schema无此项)",
|
|
"clip_name": "完整CLIP视觉模型引用",
|
|
"normalize_loudness": "响度标准化条件",
|
|
"num_frames": "帧数缓存(受565覆盖)",
|
|
"fps": "音频嵌入fps缓存",
|
|
"audio_scale": "音频条件强度",
|
|
"audio_cfg_scale": "音频CFG强度",
|
|
"multi_audio_type": "多音频组合策略",
|
|
"add_noise_floor": "额外噪声底保存(准确schema无此项)",
|
|
"smooth_transients": "额外瞬态保存(准确schema无此项)",
|
|
"model_name": "完整模型引用",
|
|
"model": "完整模型引用",
|
|
"precision": "精度字符串",
|
|
"base_precision": "基础精度字符串",
|
|
"load_device": "初始加载设备",
|
|
"quantization": "量化策略",
|
|
"positive_prompt": "完整原正向缓存(受559覆盖)",
|
|
"negative_prompt": "完整负向提示缓存",
|
|
"use_disk_cache": "文本磁盘缓存条件",
|
|
"device": "文本编码设备",
|
|
"prompt": "完整中文提示源",
|
|
"lora": "完整LoRA引用",
|
|
"strength": "LoRA强度",
|
|
"low_mem_load": "低内存加载条件",
|
|
"merge_loras": "额外合并保存(准确schema无此项)",
|
|
"start_time": "裁音开始字符串",
|
|
"end_time": "裁音结束字符串",
|
|
"enable_vae_tiling": "VAE切块条件",
|
|
"tile_x": "切块宽度",
|
|
"tile_y": "切块高度",
|
|
"tile_stride_x": "切块横向步距",
|
|
"tile_stride_y": "切块纵向步距",
|
|
"normalization": "额外归一化字符串(准确schema无此项)",
|
|
"image": "完整输入图片名",
|
|
"audio": "完整输入音频名",
|
|
"audioUI": "原音频UI辅助null",
|
|
"upload": "原上传辅助保存",
|
|
"value": "整数常量(源外线用途另列)",
|
|
"attention_mode": "注意力实现选择",
|
|
"rms_norm_function": "额外RMS选择(准确schema无此项)",
|
|
"use_cpu_cache": "额外CPU缓存保存(准确schema无此项)",
|
|
"verbose": "额外详细输出保存(准确schema无此项)",
|
|
"frame_rate": "合成帧率原整数",
|
|
"loop_count": "额外循环次数",
|
|
"filename_prefix": "完整输出前缀",
|
|
"format": "动态格式原名",
|
|
"pix_fmt": "像素格式",
|
|
"crf": "CRF质量参数",
|
|
"save_metadata": "元数据保存条件",
|
|
"trim_to_audio": "按音轨裁切条件",
|
|
"pingpong": "往返帧序条件",
|
|
"save_output": "输出目录保存条件",
|
|
"videopreview": "完整历史预览对象(仅文本)",
|
|
}
|
|
|
|
|
|
def canonical(v):
|
|
return json.dumps(v, ensure_ascii=False, sort_keys=True, separators=(",", ":")).encode()
|
|
|
|
|
|
def node_schema(class_node):
|
|
"""Extract INPUT_TYPES expressions only, never interpret plugin code."""
|
|
method = next(
|
|
(
|
|
m
|
|
for m in class_node.body
|
|
if isinstance(m, (ast.FunctionDef, ast.AsyncFunctionDef)) and m.name == "INPUT_TYPES"
|
|
),
|
|
None,
|
|
)
|
|
if method is None:
|
|
return {}
|
|
literals = {}
|
|
for assignment in method.body:
|
|
if isinstance(assignment, ast.Assign) and len(assignment.targets) == 1:
|
|
target = assignment.targets[0]
|
|
if isinstance(target, ast.Name):
|
|
try:
|
|
ast.literal_eval(assignment.value)
|
|
except (ValueError, TypeError):
|
|
continue
|
|
literals[target.id] = assignment.value
|
|
|
|
class LiteralNames(ast.NodeTransformer):
|
|
def visit_Name(self, node):
|
|
return copy.deepcopy(literals.get(node.id, node))
|
|
|
|
schema = {}
|
|
for d in ast.walk(method):
|
|
if not isinstance(d, ast.Dict):
|
|
continue
|
|
for k, v in zip(d.keys, d.values, strict=True):
|
|
if (
|
|
isinstance(k, ast.Constant)
|
|
and isinstance(k.value, str)
|
|
and isinstance(v, ast.Tuple)
|
|
):
|
|
default = "无显式default;动态枚举或首项依准确代码,目标选项未知"
|
|
for opts in v.elts[1:]:
|
|
if isinstance(opts, ast.Dict):
|
|
for dk, dv in zip(opts.keys, opts.values, strict=True):
|
|
if isinstance(dk, ast.Constant) and dk.value == "default":
|
|
default = ast.unparse(dv)
|
|
schema[k.value] = (default, ast.unparse(LiteralNames().visit(copy.deepcopy(v))))
|
|
return schema
|
|
|
|
|
|
def build(index=0):
|
|
raw = (REPO / PATHS[index]).read_bytes()
|
|
g = json.loads(raw)
|
|
prose = json.loads((OUT / "prose.json").read_bytes())
|
|
editorial = json.loads((OUT / "editorial.json").read_bytes())
|
|
manifest = json.loads((REF / "sources.json").read_bytes())["sources"]
|
|
sources = []
|
|
trees = {}
|
|
for e in manifest:
|
|
data = (REF / e["local_file"]).read_bytes()
|
|
assert hashlib.sha256(data).hexdigest() == e["sha256"]
|
|
sources.append(
|
|
dict(
|
|
e,
|
|
local_file="../wantalk-reference/" + e["local_file"],
|
|
lines=[1, len(data.decode().splitlines())],
|
|
claim="准确声明提交或锁定发布成员原文;仅静态读取,许可不等于模型素材授权,目标安装/恢复未知",
|
|
)
|
|
)
|
|
if e["file"].endswith(".py"):
|
|
trees[e["local_file"]] = ast.parse(data)
|
|
fields = []
|
|
comments = []
|
|
bindings = []
|
|
empty = []
|
|
flow = []
|
|
schemas = {}
|
|
refs = {}
|
|
for ni, n in enumerate(g["nodes"]):
|
|
nid = str(n["id"])
|
|
ptr = f"/nodes/{ni}"
|
|
flow.append(nid + " 原节点完整保存 " + json.dumps(n, ensure_ascii=False))
|
|
if n["type"] in ["Note", "MarkdownNote"]:
|
|
comments.append(
|
|
dict(
|
|
node_id=nid,
|
|
pointer=ptr + "/widgets_values/0",
|
|
text=n["widgets_values"][0],
|
|
meaning=prose["notes"][nid],
|
|
evidence=[],
|
|
)
|
|
)
|
|
continue
|
|
key, file, symbol = BINDINGS[nid]
|
|
ei = next(i for i, e in enumerate(manifest) if e["id"] == key and e["file"] == file)
|
|
entry = manifest[ei]
|
|
cl = next(
|
|
(
|
|
c
|
|
for c in trees[entry["local_file"]].body
|
|
if isinstance(c, ast.ClassDef) and c.name == symbol
|
|
),
|
|
None,
|
|
)
|
|
rs = [i for i, e in enumerate(manifest) if e["id"] == key]
|
|
if cl is not None:
|
|
sources.append(
|
|
dict(
|
|
sources[ei],
|
|
lines=[cl.lineno, cl.end_lineno],
|
|
claim=f"节点{nid}准确{key}类{symbol} schema与实现,非目标运行证明",
|
|
)
|
|
)
|
|
rs.append(len(sources) - 1)
|
|
schema = node_schema(cl)
|
|
candidates = [dict(source=ei, symbol=symbol, lines=[cl.lineno, cl.end_lineno])]
|
|
source_id = key
|
|
else:
|
|
schema = {}
|
|
candidates = []
|
|
source_id = "unresolved-" + key
|
|
schemas[nid] = schema
|
|
refs[nid] = rs
|
|
bindings.append(
|
|
dict(
|
|
node_id=nid,
|
|
class_type=n["type"],
|
|
source_version=n["properties"]["ver"],
|
|
source_id=source_id,
|
|
candidates=candidates,
|
|
declared_provider=n["properties"].get("cnr_id"),
|
|
implementation_verified=cl is not None,
|
|
scope="准确类/发布成员静态绑定;图中额外schema/端口冲突独立记录,不认证全图转换或目标安装",
|
|
)
|
|
)
|
|
effect = (
|
|
editorial[nid]
|
|
+ f" 原mode={n['mode']}"
|
|
+ ("旁路保存态,不模拟穿透/执行。" if n["mode"] == 4 else "活动保存态,不认证执行。")
|
|
)
|
|
flow.append(effect)
|
|
if n["widgets_values"] == []:
|
|
empty.append(
|
|
dict(
|
|
node_id=nid,
|
|
class_type=n["type"],
|
|
pointer=ptr,
|
|
scope="root",
|
|
state="empty_list",
|
|
named_state="missing",
|
|
effect=effect,
|
|
)
|
|
)
|
|
continue
|
|
items = (
|
|
list(n["widgets_values"].items())
|
|
if isinstance(n["widgets_values"], dict)
|
|
else list(zip(LAYOUTS[nid], n["widgets_values"], strict=True))
|
|
)
|
|
for j, (name, value) in enumerate(items):
|
|
escaped = name.replace("~", "~0").replace("/", "~1")
|
|
p = (
|
|
ptr
|
|
+ "/widgets_values/"
|
|
+ (escaped if isinstance(n["widgets_values"], dict) else str(j))
|
|
)
|
|
inp = next((i for i, x in enumerate(n["inputs"]) if x["name"] == name), None)
|
|
known = name in schema
|
|
if nid == "131" and name in ["pix_fmt", "crf", "save_metadata", "trim_to_audio"]:
|
|
format_schema = {
|
|
"pix_fmt": ("首项yuv420p", "['yuv420p','yuv420p10le']"),
|
|
"crf": ("19", "('INT', {'default':19,'min':0,'max':100,'step':1})"),
|
|
"save_metadata": ("True", "('BOOLEAN', {'default':True})"),
|
|
"trim_to_audio": ("False", "('BOOLEAN', {'default':False})"),
|
|
}
|
|
schema[name] = format_schema[name]
|
|
known = True
|
|
aux = (
|
|
(nid == "128" and name == "control_after_generate")
|
|
or (nid == "284" and name == "upload")
|
|
or (nid == "131" and name == "videopreview")
|
|
)
|
|
linked = known and inp is not None and n["inputs"][inp].get("link") is not None
|
|
role = (
|
|
"linked_override"
|
|
if linked
|
|
else "frontend_only"
|
|
if aux
|
|
else "schema_input"
|
|
if known
|
|
else "extra_saved"
|
|
)
|
|
default, limits = schema.get(
|
|
name,
|
|
(
|
|
"未知:准确schema无该保存位置/类未核准,不由后版补值",
|
|
"未知:额外保存或准确类未核准,不认证位置映射/枚举/恢复",
|
|
),
|
|
)
|
|
unit = prose["units"].get(
|
|
nid + "." + name,
|
|
"无源码物理单位声明;按准确schema类型/枚举和原JSON类型分列"
|
|
if known
|
|
else "未知:此位置后端映射未核准,原类型不是物理单位",
|
|
)
|
|
fields.append(
|
|
dict(
|
|
node_id=nid,
|
|
definition_node_id=nid,
|
|
scope="root",
|
|
class_type=n["type"],
|
|
field=name,
|
|
label=LABELS.get(name, f"原保存位置{j}(未核后端映射)"),
|
|
pointer=p,
|
|
value=value,
|
|
json_type=type(value).__name__,
|
|
named_state="missing",
|
|
input_pointer=f"{ptr}/inputs/{inp}"
|
|
if known and inp is not None
|
|
else "未知:无准确后端字段映射,不从原位置/同名/后版补实",
|
|
input_name=name if known and inp is not None else None,
|
|
type=limits,
|
|
role=role,
|
|
schema_default=default,
|
|
limits=limits,
|
|
unit=unit,
|
|
effect=effect
|
|
+ " 无原具名保存,不补具名值/双指针。"
|
|
+ (" 源外线覆盖缓存意图按物理边记录,非运行结果。" if linked else "")
|
|
+ (
|
|
" 此额外保存不在准确schema;保留原值但不认证生效/恢复。"
|
|
if not known and not aux
|
|
else ""
|
|
),
|
|
evidence=rs,
|
|
execution_note="仅静态原数据与准确源码;未构造prompt或执行插件/模型/下载/随机/调度/采样/解码/裁音/分离/编码/清理,执行与转换资格不变。",
|
|
)
|
|
)
|
|
flow += ["root 物理边 " + json.dumps(e, ensure_ascii=False) for e in g["links"]]
|
|
flow += ["根附加保存属性 " + json.dumps(g["extra"], ensure_ascii=False)] + prose["steps"]
|
|
assert len(fields) == 118 and len(bindings) == 26 and len(comments) == 7 and len(empty) == 1
|
|
return dict(
|
|
source_path=PATHS[index],
|
|
source_sha1=hashlib.sha1(raw).hexdigest(),
|
|
source_sha256=hashlib.sha256(raw).hexdigest(),
|
|
canonical_sha256=hashlib.sha256(canonical(g)).hexdigest(),
|
|
notice="固定原件与准确声明版本的静态参考;23准确类/发布成员实例、3具体未匹配实例,schema/端口差异保留,目标与运行效果未核对。",
|
|
user_overview=prose["overview"],
|
|
versions=prose["versions"],
|
|
counts=dict(
|
|
saved_fields=len(fields),
|
|
root_saved_fields=len(fields),
|
|
internal_saved_fields=0,
|
|
linked_saved_fields=sum(f["role"] == "linked_override" for f in fields),
|
|
boundary_saved_fields=0,
|
|
frontend_only=sum(f["role"] == "frontend_only" for f in fields),
|
|
source_nodes=33,
|
|
root_nodes=33,
|
|
internal_nodes=0,
|
|
physical_edges=29,
|
|
source_notes=7,
|
|
saved_objects=1,
|
|
history_objects=1,
|
|
final_scalars=0,
|
|
final_prompt_constructed=False,
|
|
),
|
|
node_bindings=bindings,
|
|
fields=fields,
|
|
sources=sources,
|
|
comments=comments,
|
|
flow=flow,
|
|
flow_evidence=[],
|
|
zero_saved_nodes=empty,
|
|
boundaries=[],
|
|
steps=[prose["overview"]] + prose["steps"],
|
|
)
|