439 lines
19 KiB
Python
439 lines
19 KiB
Python
"""Exact static reference for one Qwen3.5 graph; never import upstream."""
|
||
|
||
import ast
|
||
import hashlib
|
||
import json
|
||
from pathlib import Path
|
||
|
||
REPO = Path(__file__).resolve().parents[3]
|
||
OUT = Path(__file__).resolve().parent
|
||
REF = OUT.parent / "krea-auto-reference"
|
||
PATHS = [
|
||
(
|
||
"example_ComfyUI_workflows/3-图像生成"
|
||
+ "/krea2/krea2_turbo_文生图_Qwen3.5自动"
|
||
+ "提示词生成.json"
|
||
)
|
||
]
|
||
HOST = "4652eac2-3224-403e-868d-4781efcf3323"
|
||
|
||
|
||
def canonical(v):
|
||
return json.dumps(v, ensure_ascii=False, sort_keys=True, separators=(",", ":")).encode()
|
||
|
||
|
||
def schema_for(node):
|
||
("Extract declarations a" + "s text without evaluat" + "ing any upstream expre" + "ssion.")
|
||
result = {}
|
||
for d in ast.walk(node):
|
||
if isinstance(d, ast.Dict):
|
||
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;不从源现值或声明输入推补schema默认"
|
||
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)
|
||
result[k.value] = (default, ast.unparse(v))
|
||
if isinstance(d, ast.Call) and isinstance(d.func, ast.Attribute) and d.func.attr == "Input":
|
||
arg = (
|
||
d.args[0] if d.args else next((k.value for k in d.keywords if k.arg == "id"), None)
|
||
)
|
||
if isinstance(arg, ast.Constant) and isinstance(arg.value, str):
|
||
default = next(
|
||
(ast.unparse(k.value) for k in d.keywords if k.arg == "default"),
|
||
"无显式default;枚举条件独立,不以现值认证默认",
|
||
)
|
||
result[arg.value] = (default, ast.unparse(d))
|
||
return result
|
||
|
||
|
||
def build(index=0):
|
||
raw = (REPO / PATHS[index]).read_bytes()
|
||
g = json.loads(raw)
|
||
sg = g["definitions"]["subgraphs"][0]
|
||
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="../krea-auto-reference/" + e["local_file"],
|
||
lines=[1, len(data.decode().splitlines())],
|
||
claim="准确声明实现不可得的有界记录,非schema/许可依据"
|
||
if e["id"] == "llama-unavailable"
|
||
else "准确1.2.5发布成员/CRC/SHA;整包SHA与Git绑定未知"
|
||
if e["id"] == "showtext"
|
||
else "本图准确Git声明静态参考与许可;不认证安装/模型许可",
|
||
)
|
||
)
|
||
if e["file"].endswith(".py"):
|
||
trees[e["local_file"]] = ast.parse(data)
|
||
prose = json.loads((OUT / "prose.json").read_bytes())
|
||
editorial = json.loads((OUT / "editorial.json").read_bytes())
|
||
fields = []
|
||
comments = []
|
||
empty = []
|
||
flow = []
|
||
bindings = []
|
||
scopes = [("root", "", g), ("261", "/definitions/subgraphs/0", sg)]
|
||
for scope, prefix, graph in scopes:
|
||
for i, n in enumerate(graph["nodes"]):
|
||
nid = (scope + ":" if scope != "root" else "") + str(n["id"])
|
||
ptr = f"{prefix}/nodes/{i}"
|
||
cls = n["type"]
|
||
if cls == "MarkdownNote":
|
||
comments.append(
|
||
dict(
|
||
node_id=nid,
|
||
pointer=ptr + "/widgets_values/0",
|
||
named_pointer=ptr + "/widgets_values_named/text",
|
||
text=n["widgets_values"][0],
|
||
meaning=prose["notes"][nid],
|
||
evidence=[],
|
||
)
|
||
)
|
||
continue
|
||
ver = n.get("properties", {}).get("ver", "未知")
|
||
key = {
|
||
"0.25.0": "core0250",
|
||
"0.28.0": "core0280",
|
||
"0.34.2": "core0342",
|
||
"2864e1542d6e03e4429e919a02cffed081039cfb": "painter",
|
||
"1.2.5": "showtext",
|
||
"20571a3cf504b8308781d3cad2e432444ec3d75b": "llama-unavailable",
|
||
}.get(ver, "unknown")
|
||
symbol = {
|
||
"PrimitiveStringMultiline": "StringMultiline",
|
||
"ComfySwitchNode": "SwitchNode",
|
||
"ShowText|pysssss": "ShowText",
|
||
}.get(cls, cls)
|
||
refs = []
|
||
schemas = {}
|
||
candidates = []
|
||
for j, e in enumerate(manifest):
|
||
if (
|
||
e["id"] != key
|
||
or not e["file"].endswith(".py")
|
||
or e["file"] == "comfy/samplers.py"
|
||
):
|
||
continue
|
||
tree = trees[e["local_file"]]
|
||
for c in tree.body:
|
||
if not isinstance(c, ast.ClassDef) or c.name != symbol:
|
||
continue
|
||
sources.append(
|
||
dict(
|
||
sources[j],
|
||
lines=[c.lineno, c.end_lineno],
|
||
claim=f"节点{nid}准确{ver}注册/schema/方法静态参考",
|
||
)
|
||
)
|
||
refs.extend([j, len(sources) - 1])
|
||
schemas.update(schema_for(c))
|
||
candidates.append(dict(source=j, symbol=symbol, lines=[c.lineno, c.end_lineno]))
|
||
if cls == "LoraLoaderModelOnly":
|
||
parent = next(
|
||
c
|
||
for c in tree.body
|
||
if isinstance(c, ast.ClassDef) and c.name == "LoraLoader"
|
||
)
|
||
sources.append(
|
||
dict(
|
||
sources[j],
|
||
lines=[parent.lineno, parent.end_lineno],
|
||
claim="准确父类LoRA方法/加载条件,不执行",
|
||
)
|
||
)
|
||
refs.append(len(sources) - 1)
|
||
assert len(candidates) == (0 if key in ["unknown", "llama-unavailable"] else 1), (
|
||
nid,
|
||
candidates,
|
||
)
|
||
bindings.append(
|
||
dict(
|
||
node_id=nid,
|
||
class_type=cls,
|
||
source_version=ver,
|
||
source_id=key,
|
||
candidates=candidates,
|
||
)
|
||
)
|
||
refs += [
|
||
j
|
||
for j, e in enumerate(manifest)
|
||
if (
|
||
e["id"] == key
|
||
and e["file"] in ["__init__.py", "comfy/samplers.py", "web/js/showText.js"]
|
||
)
|
||
or (
|
||
e["id"] == "frontend"
|
||
and e["file"].endswith(("widgets.ts", "LGraphNode.ts", "SubgraphNode.ts"))
|
||
)
|
||
or (key == "llama-unavailable" and e["id"] == key)
|
||
]
|
||
effect = editorial[nid] + f" 原mode={n['mode']}(活动保存态,不认证执行或历史恢复)。"
|
||
flow += [
|
||
effect,
|
||
nid + " 原属性 " + json.dumps(n.get("properties", {}), ensure_ascii=False),
|
||
nid
|
||
+ " 原输入/输出 "
|
||
+ json.dumps({k: n[k] for k in ["inputs", "outputs"]}, ensure_ascii=False),
|
||
nid
|
||
+ " 原具名保存 "
|
||
+ json.dumps(n.get("widgets_values_named", "missing"), ensure_ascii=False),
|
||
]
|
||
if "widgets_values" not in n:
|
||
empty.append(
|
||
dict(
|
||
node_id=nid,
|
||
class_type=cls,
|
||
pointer=ptr,
|
||
scope=scope,
|
||
state="missing",
|
||
effect=effect,
|
||
)
|
||
)
|
||
continue
|
||
named = n["widgets_values_named"]
|
||
assert len(named) == len(n["widgets_values"])
|
||
names = list(named)
|
||
for j, value in enumerate(n["widgets_values"]):
|
||
name = names[j]
|
||
assert canonical(value) == canonical(named[name])
|
||
found = [k for k, x in enumerate(n["inputs"]) if x["name"] == name]
|
||
inp = found[0] if len(found) == 1 else None
|
||
linked = inp is not None and n["inputs"][inp].get("link") is not None
|
||
unknown = key in ["llama-unavailable", "unknown"]
|
||
default, limits = schemas.get(
|
||
name,
|
||
(
|
||
"未知:无准确独立宿主/前端widget默认",
|
||
"保存缓存/历史与声明输入分列,不认证后端参数映射或恢复",
|
||
),
|
||
)
|
||
unit = "完整字符串/枚举/文件引用,无物理单位;不是安装、许可或效果证明"
|
||
if unknown:
|
||
default = "未知:准确插件实现或宿主恢复不可得,具名保存值不补schema默认"
|
||
limits = (
|
||
"准确schema/范围/SDK语义/输入映射未知;具名键仅互证保"
|
||
+ "存值,不套a69/f2209或传播宿主0.20.1,不认证pro"
|
||
+ "moted"
|
||
)
|
||
unit = "未知:保存原JSON类型,不猜token、显存、种子或SDK单位"
|
||
elif type(value) is bool:
|
||
unit = "布尔选择,无物理单位;保存态不是运行或副作用保证"
|
||
elif name in ["cfg", "denoise", "strength_model"]:
|
||
unit = "无物理单位接口系数,原JSON int/float与schema默认分列"
|
||
elif name in ["width", "height"]:
|
||
unit = "像素请求缓存;本图49经98/99覆盖,不保证最终尺寸"
|
||
elif name in ["seed", "steps", "batch_size", "group_index"]:
|
||
unit = "整数数量/索引接口;原值不是最终执行值,不计算随机或正则"
|
||
elif name == "megapixels":
|
||
unit = (
|
||
"准确实现MP基数1024×1024;JSON int2与FLOA" + "T默认1.0分列,不试算/保证2MP"
|
||
)
|
||
elif name == "multiple":
|
||
unit = "像素对齐步长;准确实现round就近倍数,仅公式参考"
|
||
if name == "control_after_generate" and not unknown:
|
||
default = "准确frontend1.45.20种子辅助默认randomize,不是后端seed默认"
|
||
limits = (
|
||
"fixed/increment/decrement/random" + "ize;只静态参考,不执行随机/历史恢复"
|
||
)
|
||
if cls == "PainterVRAM" and name == "reserved":
|
||
unit = (
|
||
"源码标签GB,实际以1024**3换算字节;default0.6"
|
||
+ "/min-2.0/step0.1,无显式max;auto偏移非确"
|
||
+ "定空闲显存"
|
||
)
|
||
if cls == "CLIPLoader" and name == "type":
|
||
limits += (
|
||
";准确core0.25.0枚举不含krea2,getattr f"
|
||
+ "allback不证明支持,不借0.26.0补缺口"
|
||
)
|
||
if cls == "ShowText|pysssss":
|
||
default = "未知:历史展示缓存,无独立后端text_0默认"
|
||
limits = (
|
||
"准确1.2.5 INPUT_IS_LIST/OUTPUT_IS_"
|
||
+ "LIST与ui.text/result分列;961码点缓存不是本"
|
||
+ "次生成结果,不构造输入或认证恢复"
|
||
)
|
||
if cls == "ComfySwitchNode":
|
||
limits += (
|
||
";源true缓存被407外线覆盖;未知273的*输出接BOOLE"
|
||
+ "AN是源事实,不修线、不判必选分支或保证LLM无读取/加载副作用"
|
||
)
|
||
fields.append(
|
||
dict(
|
||
node_id=nid,
|
||
definition_node_id=str(n["id"]),
|
||
scope=scope,
|
||
class_type=cls,
|
||
field=name,
|
||
label=LABELS.get(name, name + "保存值"),
|
||
pointer=f"{ptr}/widgets_values/{j}",
|
||
value=value,
|
||
json_type=type(value).__name__,
|
||
named_pointer=f"{ptr}/widgets_values_named/{name}",
|
||
named_value=named[name],
|
||
input_pointer="未知:准确实现不可得,声明同名输入不等于SDK映射"
|
||
if unknown
|
||
else f"{ptr}/inputs/{inp}"
|
||
if inp is not None
|
||
else "无可靠独立输入映射:前端辅助/历史",
|
||
input_name=None if unknown or inp is None else name,
|
||
type="保存参考" if unknown or inp is None else n["inputs"][inp]["type"],
|
||
role="unverified_saved_position"
|
||
if unknown
|
||
else "frontend_reference_only"
|
||
if name == "control_after_generate" or cls == "ShowText|pysssss"
|
||
else "linked_saved_cache"
|
||
if linked
|
||
else "saved_reference",
|
||
schema_default=default,
|
||
limits=limits,
|
||
unit=unit,
|
||
effect=effect,
|
||
evidence=list(dict.fromkeys(refs)),
|
||
execution_note=(
|
||
"仅静态参考;所有指令/指南/历史只是源数据,不构造prompt,"
|
||
+ "不执行上游、插件、SDK、LLM、模型、GPU、媒体、表达式、正"
|
||
+ "则、随机、旁路、组控制或显存/RAM清理。转换执行资格不变。"
|
||
),
|
||
)
|
||
)
|
||
flow += [
|
||
(
|
||
f"节点{nid}准确schema {name}:default={default};"
|
||
+ f"{limits}。仅静态声明,不认证目标恢复。"
|
||
)
|
||
for name, (default, limits) in schemas.items()
|
||
]
|
||
flow += [scope + " 物理边 " + json.dumps(e, ensure_ascii=False) for e in graph["links"]]
|
||
flow += [
|
||
scope
|
||
+ " 附加属性 "
|
||
+ json.dumps(
|
||
{k: v for k, v in graph.items() if k not in ["nodes", "links", "definitions"]},
|
||
ensure_ascii=False,
|
||
)
|
||
]
|
||
host = next(n for n in g["nodes"] if n["id"] == 261)
|
||
boundaries = [
|
||
dict(
|
||
scope="261",
|
||
definition_pointer="/definitions/subgraphs/0",
|
||
**{k: sg[k] for k in ["id", "inputNode", "outputNode", "inputs", "outputs", "widgets"]},
|
||
host_pointer="/nodes/18",
|
||
host_saved=host["widgets_values"],
|
||
host_named=host["widgets_values_named"],
|
||
host_inputs=host["inputs"],
|
||
properties=host["properties"],
|
||
proxyWidgets_state="missing",
|
||
previewExposures=host["properties"].get("previewExposures"),
|
||
)
|
||
]
|
||
flow += (
|
||
["原定义/宿主边界 " + json.dumps(b, ensure_ascii=False) for b in boundaries]
|
||
+ prose["steps"]
|
||
+ ["注释" + n["node_id"] + " 中文核对:" + n["meaning"] for n in comments]
|
||
)
|
||
assert len(fields) == 77 and len(comments) == 2
|
||
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=(
|
||
"仅参考:LLM准确实现不可得、未知组旁路、宿主恢复、krea2枚"
|
||
+ "举及Save输出冲突保留;目标安装/许可/效果未知,资格不变。"
|
||
),
|
||
user_overview=prose["overview"],
|
||
versions=[
|
||
f"{e['id']} {e['tag']} commit {e['commit']} tree {e['tree']};许可{e['license_file']}"
|
||
for e in {e["id"]: e for e in manifest}.values()
|
||
]
|
||
+ [
|
||
(
|
||
"旧89块4612位置/146注释冻结;新增77标量/两Note,"
|
||
+ "总90图4689位置/148注释仅参考。local_file以d"
|
||
+ "ocs/hel-892/krea-auto-document-e"
|
||
+ "vidence为基准。"
|
||
)
|
||
],
|
||
counts=dict(
|
||
saved_fields=77,
|
||
root_saved_fields=46,
|
||
internal_saved_fields=31,
|
||
linked_saved_fields=sum(f["role"] == "linked_saved_cache" for f in fields),
|
||
boundary_saved_fields=0,
|
||
frontend_only=sum(f["role"] == "frontend_reference_only" for f in fields),
|
||
source_nodes=24,
|
||
root_nodes=21,
|
||
internal_nodes=3,
|
||
physical_edges=33,
|
||
source_notes=2,
|
||
saved_objects=0,
|
||
history_objects=0,
|
||
final_scalars=0,
|
||
final_prompt_constructed=False,
|
||
),
|
||
fields=fields,
|
||
sources=sources,
|
||
comments=comments,
|
||
flow=flow,
|
||
flow_evidence=list(range(len(sources))),
|
||
zero_saved_nodes=empty,
|
||
boundaries=boundaries,
|
||
node_bindings=bindings,
|
||
steps=[prose["overview"]] + prose["steps"],
|
||
)
|
||
|
||
|
||
LABELS = dict(
|
||
width="宽度请求缓存",
|
||
height="高度请求缓存",
|
||
batch_size="空latent批量",
|
||
seed="种子保存值",
|
||
control_after_generate="前端种子控制辅助",
|
||
steps="采样步数",
|
||
cfg="引导系数",
|
||
sampler_name="采样器",
|
||
scheduler="调度器",
|
||
denoise="降噪系数",
|
||
aspect_ratio="宽高比选择",
|
||
megapixels="目标MP保存值",
|
||
multiple="像素对齐步长",
|
||
text="完整旧英文缓存",
|
||
value="完整文本保存值",
|
||
system_prompt="完整系统文本缓存",
|
||
custom_prompt="完整自定义文本缓存",
|
||
preset_prompt="预设提示缓存",
|
||
reserved="预留显存偏移",
|
||
mode="模式选择",
|
||
clean_gpu_before="预先清理GPU选择",
|
||
switch="被外线覆盖的切换缓存",
|
||
text_0="完整历史展示缓存",
|
||
load_mtp="具名load_mtp保存值",
|
||
present_penalty="原拼present_penalty保存值",
|
||
filename_prefix="保存文件名前缀",
|
||
unet_name="扩散模型引用",
|
||
clip_name="文本模型引用",
|
||
vae_name="VAE文件引用",
|
||
type="文本编码器类型",
|
||
device="设备选择",
|
||
lora_name="唯一美学LoRA引用",
|
||
strength_model="LoRA模型强度",
|
||
regex_pattern="完整正则保存字符串",
|
||
group_index="正则组索引",
|
||
string="正则输入空串",
|
||
)
|