1031 lines
41 KiB
Python
1031 lines
41 KiB
Python
"""Source-bound Qwen subgraph editorial document. Never execute upstream or a model."""
|
||
|
||
from __future__ import annotations
|
||
|
||
import hashlib
|
||
import json
|
||
from pathlib import Path
|
||
|
||
REPO = Path(__file__).resolve().parents[3]
|
||
OUT = Path(__file__).resolve().parent
|
||
PATH = "example_ComfyUI_workflows/3-图像生成/Qwen-Image-2.1/Qwen_image2.1_文生图_提示词增强.json"
|
||
|
||
|
||
def canonical(value):
|
||
return json.dumps(value, ensure_ascii=False, sort_keys=True, separators=(",", ":")).encode()
|
||
|
||
|
||
def build():
|
||
from calliope.comfyui.serialization_reference import CASE04_PROFILE
|
||
from calliope.comfyui.ui2api import convert_reference
|
||
|
||
raw = (REPO / PATH).read_bytes()
|
||
s = json.loads(raw)
|
||
g = s["definitions"]["subgraphs"][0]
|
||
refs, fields = [], []
|
||
|
||
def ref(directory, filename, start, end, claim):
|
||
root = OUT.parent / directory
|
||
item = next(
|
||
x
|
||
for x in json.loads((root / "sources.json").read_bytes())["sources"]
|
||
if x["local_file"] == filename
|
||
)
|
||
data = (root / filename).read_bytes()
|
||
assert hashlib.sha256(data).hexdigest() == item["sha256"]
|
||
assert 1 <= start <= end <= len(data.decode().splitlines())
|
||
refs.append(
|
||
{
|
||
**{k: item[k] for k in ("id", "commit", "file", "sha256", "url")},
|
||
"license": item.get("license", "沿用来源manifest许可"),
|
||
"local_file": "../" + directory + "/" + filename,
|
||
"lines": [start, end],
|
||
"claim": claim,
|
||
}
|
||
)
|
||
return len(refs) - 1
|
||
|
||
def core(file, start, end, claim):
|
||
return ref("promoted-reference", "core-0.38.0__" + file, start, end, claim)
|
||
|
||
def case(file, start, end, claim):
|
||
return ref("case04-reference", file, start, end, claim)
|
||
|
||
schemas = {
|
||
"UNETLoader": core("nodes.py", 991, 1015, "UNET动态文件列表、精度枚举与加载选项"),
|
||
"CLIPLoader": core("nodes.py", 1016, 1041, "CLIP动态文件、type注册枚举、device与加载调用"),
|
||
"VAELoader": core("nodes.py", 775, 869, "VAE动态文件/近似模型列表、文件读取及校验"),
|
||
"EmptyLatentImage": core("nodes.py", 1254, 1274, "latent宽高/batch schema与张量创建"),
|
||
"KSampler": core(
|
||
"nodes.py", 1605, 1644, "seed/steps/cfg/算法/调度/denoise声明及common_ksampler调用"
|
||
),
|
||
"TextGenerate": core(
|
||
"comfy_extras__nodes_textgen.py",
|
||
4,
|
||
88,
|
||
"动态on采样、生成长度、模板与system条件、MTP和文本输出",
|
||
),
|
||
"TextEncodeQwenImage21": core(
|
||
"comfy_extras__nodes_qwen.py",
|
||
111,
|
||
182,
|
||
"正负文本、参考图像分辨率、三出口及未接参考图条件",
|
||
),
|
||
"QwenImage21Cache": core(
|
||
"comfy_extras__nodes_qwen.py",
|
||
185,
|
||
215,
|
||
"cache枚举、clone及transformer_options写入;不证明实际缓存效果",
|
||
),
|
||
"ComfySwitchNode": core(
|
||
"comfy_extras__nodes_logic.py", 86, 122, "switch为真取on_true、假取on_false及lazy请求"
|
||
),
|
||
"PrimitiveStringMultiline": core(
|
||
"comfy_extras__nodes_primitive.py", 25, 42, "多行字符串schema与原字符串返回"
|
||
),
|
||
"VAEDecode": core("nodes.py", 320, 345, "LATENT和VAE输入、IMAGE输出与解码调用"),
|
||
"PreviewAny": case(
|
||
"0.38.0__comfy_extras__nodes_preview_any.py",
|
||
9,
|
||
48,
|
||
"文本UI响应及原输入透传槽;本轮未执行",
|
||
),
|
||
"ResolutionSelector": case(
|
||
"0.38.0__comfy_extras__nodes_resolution.py",
|
||
7,
|
||
90,
|
||
"比例枚举、MP及倍数schema、1024平方和round对齐算法",
|
||
),
|
||
"SaveImageAdvanced": case(
|
||
"0.38.0__comfy_extras__nodes_images.py",
|
||
1769,
|
||
1928,
|
||
"png动态分支、前缀目录/计数器、可选元数据、ui.images描述",
|
||
),
|
||
}
|
||
encoding = case(
|
||
"0.38.0__comfy_extras__nodes_images.py",
|
||
1639,
|
||
1705,
|
||
"PNG整数化/颜色条件与编码;没有处理真实图像",
|
||
)
|
||
restore = ref(
|
||
"promoted-reference",
|
||
"1.53.6__src__lib__litegraph__src__LGraphNode.ts",
|
||
1072,
|
||
1225,
|
||
"控件位置与具名恢复/序列化;本图双存储互证",
|
||
)
|
||
host = ref(
|
||
"structure-reference",
|
||
"1.53.6__src__lib__litegraph__src__subgraph__SubgraphNode.ts",
|
||
415,
|
||
688,
|
||
"从定义边界逐跳构造控件,widgetId(rootGraph.id,host.id,input.name)与host恢复",
|
||
)
|
||
hostsave = ref(
|
||
"structure-reference",
|
||
"1.53.6__src__lib__litegraph__src__subgraph__SubgraphNode.ts",
|
||
986,
|
||
1025,
|
||
"host通过widgetId读取store并保存;字段名稳定,标签非字段",
|
||
)
|
||
wid = ref(
|
||
"promoted-reference",
|
||
"1.53.6__src__types__widgetId.ts",
|
||
1,
|
||
39,
|
||
"控件身份由图/节点/字段组成,不将标签或位置当绑定",
|
||
)
|
||
execution = ref(
|
||
"structure-reference",
|
||
"1.53.6__src__utils__executionUtil.ts",
|
||
76,
|
||
180,
|
||
"执行输入组装、具体边界解析和物理连线覆盖",
|
||
)
|
||
dyn = case(
|
||
"1.53.6__src__core__graph__widgets__dynamicWidgets.ts",
|
||
99,
|
||
297,
|
||
"动态分支构造限定名及状态恢复;sampling_mode.seed为限定名",
|
||
)
|
||
seed = ref(
|
||
"promoted-reference",
|
||
"1.53.6__src__renderer__extensions__vueNodes__widgets__composables__useIntWidget.ts",
|
||
30,
|
||
88,
|
||
"仅裸名seed/noise_seed或显式控制标记附加控制,不给限定名自动添控件",
|
||
)
|
||
control = case(
|
||
"1.53.6__src__scripts__valueControl.ts", 1, 140, "fixed控制不改变保存值;未模拟队列钩子"
|
||
)
|
||
filename = case(
|
||
"1.53.6__src__extensions__core__saveImageExtraOutput.ts",
|
||
1,
|
||
74,
|
||
"保存前缀serialize替换入口;本图固定字符串不含替换token",
|
||
)
|
||
ref(
|
||
"case04-reference",
|
||
"1.53.6__src__utils__searchAndReplace.ts",
|
||
5,
|
||
57,
|
||
"文件名前缀上下文替换,仅说明未调用",
|
||
) if (
|
||
OUT.parent / "case04-reference/1.53.6__src__utils__searchAndReplace.ts"
|
||
).exists() else None
|
||
limits_ref = core("nodes.py", 1, 58, "MAX_RESOLUTION常量16384")
|
||
sampler_ref = case("0.38.0__comfy__samplers.py", 971, 986, "固定KSAMPLER_NAMES枚举")
|
||
sampler_data = (
|
||
(OUT.parent / "case04-reference/0.38.0__comfy__samplers.py").read_text().splitlines()
|
||
)
|
||
for i, line in enumerate(sampler_data):
|
||
if line.startswith("SAMPLER_NAMES") or line.startswith("SCHEDULER_NAMES"):
|
||
ref(
|
||
"case04-reference",
|
||
"0.38.0__comfy__samplers.py",
|
||
i + 1,
|
||
min(i + 15, len(sampler_data)),
|
||
"算法/调度器静态名称;不等于目标可用列表",
|
||
)
|
||
|
||
ref(
|
||
"promoted-reference",
|
||
"1.53.6__src__lib__litegraph__src__LGraphNode.ts",
|
||
150,
|
||
205,
|
||
"双存储序列化与命名恢复状态",
|
||
)
|
||
ref(
|
||
"promoted-reference",
|
||
"1.53.6__src__lib__litegraph__src__LGraphNode.ts",
|
||
1227,
|
||
1288,
|
||
"常规节点serializeFromStoreState保存控件",
|
||
)
|
||
core("nodes.py", 2075, 2135, "精确内置节点注册映射")
|
||
core("nodes.py", 2470, 2535, "精确core扩展加载列表")
|
||
core("comfy_extras__nodes_qwen.py", 237, 250, "Qwen扩展注册列表")
|
||
int_ui = ref(
|
||
"promoted-reference",
|
||
"1.53.6__src__renderer__extensions__vueNodes__widgets__composables__useIntWidget.ts",
|
||
12,
|
||
90,
|
||
"整数UI step2/旧step十倍、编辑回调取整与默认步进1;不执行回调",
|
||
)
|
||
float_ui = ref(
|
||
"promoted-reference",
|
||
"1.53.6__src__renderer__extensions__vueNodes__widgets__composables__useFloatWidget.ts",
|
||
12,
|
||
82,
|
||
"浮点UI step2/旧step十倍、设置控制precision/round与条件clamp;不执行回调",
|
||
)
|
||
# Editorial specifications are explicit, not inferred from labels or widget positions.
|
||
spec = {}
|
||
|
||
def add(cls, name, label, typ, default, unit, limits, effect):
|
||
spec[cls, name] = dict(
|
||
field=name,
|
||
label=label,
|
||
type=typ,
|
||
schema_default=default,
|
||
unit=unit,
|
||
limits=limits,
|
||
effect=effect,
|
||
evidence=[schemas[cls]],
|
||
)
|
||
|
||
add(
|
||
"ResolutionSelector",
|
||
"aspect_ratio",
|
||
"画面比例",
|
||
"COMBO / STRING",
|
||
"1:1 (Square)",
|
||
"宽高比",
|
||
"固定8项比例枚举,源3:4。",
|
||
"决定宽高比例,和MP/倍数共同传给计算;不直接给实际产物尺寸。",
|
||
)
|
||
add(
|
||
"ResolutionSelector",
|
||
"megapixels",
|
||
"目标像素总量",
|
||
"FLOAT",
|
||
"1.0",
|
||
"MP(1024×1024像素尺度)",
|
||
"0.1..16.0,schema步进0.1。",
|
||
"total_pixels=MP×1024×1024,再按比例开方;本图1.5,不当作1024宽高或输出验证。",
|
||
)
|
||
add(
|
||
"ResolutionSelector",
|
||
"multiple",
|
||
"尺寸对齐倍数",
|
||
"INT",
|
||
"8",
|
||
"像素",
|
||
"8..128,schema步进4。",
|
||
"width/height分别按round(比例×scale/multiple)×multiple对齐;preview只前端显示,不额外保存或执行。",
|
||
)
|
||
for cls, name, label in [
|
||
("UNETLoader", "unet_name", "扩散模型文件"),
|
||
("CLIPLoader", "clip_name", "文本模型文件"),
|
||
("VAELoader", "vae_name", "VAE文件"),
|
||
]:
|
||
add(
|
||
cls,
|
||
name,
|
||
label,
|
||
"动态COMBO / STRING",
|
||
"动态列表首项,无固定默认文件名",
|
||
"不适用",
|
||
"文件列表依赖目标目录/注册;未检查。",
|
||
(
|
||
"保持源文件名与反斜杠;按对应diffusion_models/text_encoders/vae解析加载。名称中的int"
|
||
"8/bf16不证明实际精度、硬件支持或内存效果。内部保存名和宿主覆盖名分列,不能按注释替换。"
|
||
),
|
||
)
|
||
add(
|
||
"UNETLoader",
|
||
"weight_dtype",
|
||
"UNET加载精度选项",
|
||
"COMBO / STRING",
|
||
"首项default",
|
||
"不适用",
|
||
"default/fp8_e4m3fn/fp8_e4m3fn_fast/fp8_e5m2。",
|
||
"default不强设dtype;fp8选项设置模型dtype,fast另置fp8_optimizations。真实精度/性能依赖加载器和权重,未验证。",
|
||
)
|
||
add(
|
||
"CLIPLoader",
|
||
"type",
|
||
"文本编码器类别",
|
||
"COMBO / STRING",
|
||
"首项stable_diffusion;函数默认同名",
|
||
"不适用",
|
||
"固定core枚举含qwen_image和stable_diffusion,完整枚举见引用。",
|
||
"映射CLIPType再调load_clip;453保存qwen_image用于图像条件,473保存stable_diffusion用于PE文本生成,不能因模型名相似合并。",
|
||
)
|
||
add(
|
||
"CLIPLoader",
|
||
"device",
|
||
"文本模型设备选择",
|
||
"COMBO / STRING",
|
||
"default",
|
||
"不适用",
|
||
"default/cpu。",
|
||
"cpu显式设load/offload设备为CPU;default沿加载器策略,不承诺GPU常驻或设备可用。",
|
||
)
|
||
for name, label in [("width", "潜空间图像宽度"), ("height", "潜空间图像高度")]:
|
||
add(
|
||
"EmptyLatentImage",
|
||
name,
|
||
label,
|
||
"INT",
|
||
"1024",
|
||
"像素尺度",
|
||
"16..MAX_RESOLUTION=16384,schema步进8。",
|
||
"供空latent创建,按height//8、width//8形成空间维度;本图被外部ResolutionSelector覆盖,不用内部1024推断产物。",
|
||
)
|
||
add(
|
||
"EmptyLatentImage",
|
||
"batch_size",
|
||
"潜空间批量",
|
||
"INT",
|
||
"1",
|
||
"张/批",
|
||
"1..4096。",
|
||
"决定空latent批量维;本图1。实际显存/批量产出依赖模型执行,未验证。",
|
||
)
|
||
for name, label, typ, default, limits, effect in [
|
||
(
|
||
"seed",
|
||
"噪声种子",
|
||
"INT",
|
||
"0",
|
||
"0..18446744073709551615;参考候选另限制JS安全整数。",
|
||
"用于采样噪声。宿主同一seed还供文本生成,但两类含义各自独立;相同种子不保证目标推理可复现。",
|
||
),
|
||
(
|
||
"control_after_generate",
|
||
"生成后种子控制",
|
||
"前端COMBO",
|
||
"前端裸seed附加控件默认randomize;本图保存fixed",
|
||
"fixed/increment/decrement/randomize;本参考仅fixed。",
|
||
"附加前端控件,fixed保持值;不进入执行prompt,不模拟队列随机化。",
|
||
),
|
||
(
|
||
"steps",
|
||
"去噪步数",
|
||
"INT",
|
||
"20",
|
||
"1..10000。",
|
||
"传给common_ksampler的去噪步数;不承诺更多步提高质量或固定耗时。",
|
||
),
|
||
(
|
||
"cfg",
|
||
"条件引导强度",
|
||
"FLOAT",
|
||
"8.0",
|
||
"0..100,schema步进0.1/round0.01。",
|
||
"传入条件引导参数。源1不同于默认8;注释关于负向/质量仅源建议,不作模型质量保证。",
|
||
),
|
||
(
|
||
"sampler_name",
|
||
"采样算法",
|
||
"COMBO / STRING",
|
||
"SAMPLERS首项",
|
||
"固定KSampler.SAMPLERS枚举;源euler。",
|
||
"算法名称传给采样器;宿主字段名scheduler实际绑定此字段,不是调度器。",
|
||
),
|
||
(
|
||
"scheduler",
|
||
"噪声调度器",
|
||
"COMBO / STRING",
|
||
"SCHEDULERS首项",
|
||
"固定KSampler.SCHEDULERS枚举;源simple。",
|
||
"决定噪声序列调度;宿主scheduler_1才绑定此字段。",
|
||
),
|
||
(
|
||
"denoise",
|
||
"去噪比例",
|
||
"FLOAT",
|
||
"1.0",
|
||
"0..1,schema步进0.01。",
|
||
"传入采样denoise;本图空latent值1,不能保证质量或推断实际图像。",
|
||
),
|
||
]:
|
||
add(
|
||
"KSampler",
|
||
name,
|
||
label,
|
||
typ,
|
||
default,
|
||
"步" if name == "steps" else "无量纲",
|
||
limits,
|
||
effect,
|
||
)
|
||
spec["KSampler", name]["evidence"] += [control, seed, sampler_ref]
|
||
for name, label in [("prompt", "正向编码文本"), ("negative_prompt", "负向编码文本")]:
|
||
add(
|
||
"TextEncodeQwenImage21",
|
||
name,
|
||
label,
|
||
"STRING",
|
||
"未显式指定default",
|
||
"不适用",
|
||
"多行dynamic_prompts字符串;不执行文本。",
|
||
(
|
||
"分别编码正负条件;prompt实际接Switch经PreviewAny透传,negative_prompt接宿主空字符串"
|
||
"。未接images/vae,不把未使用latent出口当采样输入。"
|
||
),
|
||
)
|
||
add(
|
||
"TextEncodeQwenImage21",
|
||
"resolution",
|
||
"参考图像缩放尺度",
|
||
"INT",
|
||
"1024",
|
||
"像素尺度",
|
||
"0..4096,schema步进32;0保留参考尺寸后按32对齐。",
|
||
"仅参考图分支按约resolution平方像素保比例缩放;本图images未接、输出latent未用,不能当最终生成尺寸,采样尺寸来自EmptyLatentImage。",
|
||
)
|
||
text_specs = [
|
||
(
|
||
"prompt",
|
||
"文本生成原始提示",
|
||
"STRING",
|
||
"空字符串",
|
||
"多行dynamic_prompts;未声明长度界限。",
|
||
"通过clip.tokenize进入生成;本图root483经713覆盖宿主prompt再到471,不采用内部空串。",
|
||
),
|
||
(
|
||
"max_length",
|
||
"文本生成长度上限",
|
||
"INT",
|
||
"512",
|
||
"1..32768。",
|
||
"传给clip.generate的max_length;不是汉字数保证或实际输出长度。",
|
||
),
|
||
(
|
||
"sampling_mode",
|
||
"文本采样模式",
|
||
"动态COMBO / STRING",
|
||
"首分支on",
|
||
"on/off;本图on,off分支无子字段。",
|
||
"决定do_sample;on展开限定名采样参数,不能照数组长度推断其它分支。",
|
||
),
|
||
(
|
||
"sampling_mode.temperature",
|
||
"文本采样温度",
|
||
"FLOAT",
|
||
"0.7",
|
||
"0.01..2.0,schema步进0.000001。",
|
||
"on分支传temperature;实际随机性/文本效果未实跑。",
|
||
),
|
||
(
|
||
"sampling_mode.top_k",
|
||
"文本top-k",
|
||
"INT",
|
||
"64",
|
||
"0..1000。",
|
||
"on分支传top_k;不把schema默认与执行缺省50混同。",
|
||
),
|
||
(
|
||
"sampling_mode.top_p",
|
||
"文本top-p",
|
||
"FLOAT",
|
||
"0.95",
|
||
"0..1,schema步进0.01。",
|
||
"on分支传top_p;不承诺质量与效果。",
|
||
),
|
||
(
|
||
"sampling_mode.min_p",
|
||
"文本min-p",
|
||
"FLOAT",
|
||
"0.05",
|
||
"0..1,schema步进0.01。",
|
||
"on分支传min_p;本图0,不等于schema默认0.05。",
|
||
),
|
||
(
|
||
"sampling_mode.repetition_penalty",
|
||
"文本重复惩罚",
|
||
"FLOAT",
|
||
"1.05",
|
||
"0..5,schema步进0.01。",
|
||
"on分支传repetition_penalty;数值调整效果未验证。",
|
||
),
|
||
(
|
||
"sampling_mode.seed",
|
||
"文本采样种子",
|
||
"INT",
|
||
"0",
|
||
"0..18446744073709551615;参考JS安全域另限。",
|
||
"本图接同一宿主447606998181263;限定名不是裸seed,前端不自动附加control_after_generate。内部0被覆盖。",
|
||
),
|
||
(
|
||
"sampling_mode.presence_penalty",
|
||
"文本出现惩罚",
|
||
"FLOAT",
|
||
"0.0",
|
||
"可选,0..5,schema步进0.01。",
|
||
"on分支传presence_penalty;本图0,效果未验证。",
|
||
),
|
||
(
|
||
"thinking",
|
||
"思考模式开关",
|
||
"BOOLEAN",
|
||
"false",
|
||
"true/false;模型支持时才适用。",
|
||
"传给tokenize的thinking;宿主false覆盖内部false。第二thinking输出未接,不声称已生成思考内容。",
|
||
),
|
||
(
|
||
"use_default_template",
|
||
"使用模型默认模板",
|
||
"BOOLEAN",
|
||
"true",
|
||
"true/false。",
|
||
"本图false使skip_template=true,system_prompt条件传空字符串,虽连475指南也不采用;不是默认true。",
|
||
),
|
||
(
|
||
"mtp",
|
||
"多token预测策略",
|
||
"COMBO / STRING",
|
||
"auto",
|
||
"auto/off/2/3/4/5。",
|
||
"auto转True、off转False、数字转int交generate;无MTP权重时无效,效果/速度/同seed输出不保证。",
|
||
),
|
||
]
|
||
for name, label, typ, default, limits, effect in text_specs:
|
||
add(
|
||
"TextGenerate",
|
||
name,
|
||
label,
|
||
typ,
|
||
default,
|
||
"token上限(非实际长度)" if name == "max_length" else "无量纲",
|
||
limits,
|
||
effect,
|
||
)
|
||
spec["TextGenerate", name]["evidence"] += [dyn, seed]
|
||
add(
|
||
"ComfySwitchNode",
|
||
"switch",
|
||
"提示词支路开关",
|
||
"BOOLEAN",
|
||
"schema未显式指定default;不把内部保存false当默认",
|
||
"无量纲",
|
||
"true→on_true;false→on_false。",
|
||
"内部false被宿主true覆盖;本图true选择471生成文本,false才选483原文本。lazy仅请求选中支路,不按优化标签猜分支或保证增强效果。",
|
||
)
|
||
add(
|
||
"PrimitiveStringMultiline",
|
||
"value",
|
||
"不透明原始文本",
|
||
"STRING",
|
||
"空字符串",
|
||
"不适用",
|
||
"多行文本,未声明静态长度界限。",
|
||
(
|
||
"原样透传字符串;root483供原始提示,内部475供system指南。475虽经709连471.system_prom"
|
||
"pt,当前use_default_template=false使其不生效;未改写/求值/执行。"
|
||
),
|
||
)
|
||
add(
|
||
"QwenImage21Cache",
|
||
"device",
|
||
"KV缓存设备策略",
|
||
"COMBO / STRING",
|
||
"auto",
|
||
"不适用",
|
||
"auto/gpu/cpu/off。",
|
||
(
|
||
"clone模型并写qwen_image21_cache.device;源码tooltip说明auto先余显存后RAM、o"
|
||
"ff逐步重算。实际硬件/内存/缓存是否使用未知,不称已加速。"
|
||
),
|
||
)
|
||
add(
|
||
"QwenImage21Cache",
|
||
"dtype",
|
||
"KV缓存存储精度",
|
||
"COMBO / STRING",
|
||
"default",
|
||
"不适用",
|
||
"default/int8/int4。",
|
||
"写入cache.dtype,tooltip称default无损、int8/int4较低存储精度;实际误差/节省量未验证,不混同UNET权重精度。",
|
||
)
|
||
for name, label, default, limits, effect in [
|
||
(
|
||
"filename_prefix",
|
||
"输出文件前缀",
|
||
"ComfyUI",
|
||
"字符串;本图固定前缀不含上下文替换token。",
|
||
(
|
||
"images来自459槽0;固定前缀image/Qwen_image_2.1交输出目录路径解析,计数器形成文件名。元数据"
|
||
"受disable_metadata及hidden prompt/extra_pnginfo条件控制,未实际保存。"
|
||
),
|
||
),
|
||
(
|
||
"format",
|
||
"图像保存格式",
|
||
"首分支png",
|
||
"png/exr/avif;本图只解释png保存分支。",
|
||
"动态png选择决定下属bit_depth/input_color_space;schema其它分支不视为本图保存控件。",
|
||
),
|
||
(
|
||
"format.bit_depth",
|
||
"PNG位深",
|
||
"8-bit",
|
||
"png分支8-bit/16-bit。",
|
||
"本图8-bit整数化/clamp后编码,支持通道数1/3/4依编码表;不证明透明背景或实际色深。",
|
||
),
|
||
(
|
||
"format.input_color_space",
|
||
"PNG输入色彩空间",
|
||
"sRGB",
|
||
"png分支仅sRGB。",
|
||
"PNG路径色彩选择不修改像素;不套EXR的逆sRGB转换,实际输出色彩未验证。",
|
||
),
|
||
]:
|
||
add(
|
||
"SaveImageAdvanced",
|
||
name,
|
||
label,
|
||
"STRING / COMBO" if name != "filename_prefix" else "STRING",
|
||
default,
|
||
"不适用",
|
||
limits,
|
||
effect,
|
||
)
|
||
spec["SaveImageAdvanced", name]["evidence"] += [encoding, filename, dyn]
|
||
|
||
ui_steps = {
|
||
("ResolutionSelector", "megapixels"): "0.1",
|
||
("ResolutionSelector", "multiple"): "4",
|
||
("EmptyLatentImage", "width"): "8",
|
||
("EmptyLatentImage", "height"): "8",
|
||
("KSampler", "cfg"): "0.1",
|
||
("KSampler", "denoise"): "0.01",
|
||
("TextEncodeQwenImage21", "resolution"): "32",
|
||
("TextGenerate", "sampling_mode.temperature"): "0.000001",
|
||
**{
|
||
("TextGenerate", "sampling_mode." + name): "0.01"
|
||
for name in ("top_p", "min_p", "repetition_penalty", "presence_penalty")
|
||
},
|
||
}
|
||
for key, d in spec.items():
|
||
if d["type"] not in ("INT", "FLOAT"):
|
||
continue
|
||
step = ui_steps.get(key, "1" if d["type"] == "INT" else "0.5")
|
||
common_ui = f" UI编辑步进step2={step},旧step属性为其10倍,不是额外schema范围。"
|
||
detail_ui = (
|
||
"INT编辑回调按step2取整并考虑min余数偏移;未声明step时默认1。"
|
||
if d["type"] == "INT"
|
||
else "FLOAT precision/round受FloatRoundingPrecision、DisableFloatRounding设置影响;"
|
||
"启用round时按round取整并clamp,否则保留输入。实际用户设置未知。"
|
||
)
|
||
d["limits"] += common_ui + detail_ui + "仅说明UI编辑,未调用回调或改写保存值。"
|
||
d["evidence"] += [int_ui if d["type"] == "INT" else float_ui]
|
||
|
||
result = convert_reference(s, CASE04_PROFILE)
|
||
assert result.prompt is not None and result.reference_only
|
||
# Reuse proven boundary resolver to corroborate bindings, never infer from UI labels.
|
||
by_id = {n["id"]: n for n in g["nodes"]}
|
||
bindings = []
|
||
for slot, b in enumerate(g["inputs"]):
|
||
targets = []
|
||
for lid in b["linkIds"]:
|
||
ei = next(i for i, e in enumerate(g["links"]) if e["id"] == lid)
|
||
e = g["links"][ei]
|
||
n = by_id[e["target_id"]]
|
||
inp = n["inputs"][e["target_slot"]]
|
||
assert inp.get("widget") is None or inp["widget"] == {"name": inp["name"]}
|
||
targets.append(
|
||
dict(
|
||
node_id=f"459:{n['id']}",
|
||
definition_node_id=str(n["id"]),
|
||
field=inp["name"],
|
||
link_pointer=f"/definitions/subgraphs/0/links/{ei}",
|
||
target_pointer=f"/definitions/subgraphs/0/nodes/{g['nodes'].index(n)}/inputs/{e['target_slot']}",
|
||
)
|
||
)
|
||
binding = dict(
|
||
slot=slot,
|
||
name=b["name"],
|
||
boundary_id=b["id"],
|
||
boundary_pointer=f"/definitions/subgraphs/0/inputs/{slot}",
|
||
widget_id_rule=f"widgetId(rootGraph.id, 459, {b['name']!r})",
|
||
value_pointer=f"/nodes/1/widgets_values/{slot}",
|
||
named_pointer=f"/nodes/1/widgets_values_named/{b['name']}",
|
||
targets=targets,
|
||
)
|
||
bindings.append(binding)
|
||
target_host = {(t["node_id"], t["field"]): b for b in bindings for t in b["targets"]}
|
||
for scope, graph in [("root", s), ("definition", g)]:
|
||
for ni, n in enumerate(graph["nodes"]):
|
||
if n["type"] == "MarkdownNote":
|
||
continue
|
||
prefix = f"/nodes/{ni}" if scope == "root" else f"/definitions/subgraphs/0/nodes/{ni}"
|
||
nodeid = str(n["id"]) if scope == "root" else f"459:{n['id']}"
|
||
names = list(n.get("widgets_values_named", {}))
|
||
values = n.get("widgets_values", [])
|
||
if n["id"] == 458:
|
||
names = [
|
||
"seed",
|
||
"control_after_generate",
|
||
"steps",
|
||
"cfg",
|
||
"sampler_name",
|
||
"scheduler",
|
||
"denoise",
|
||
]
|
||
assert len(values) == len(names)
|
||
for offset, (name, v) in enumerate(zip(names, values)):
|
||
binding = None
|
||
if n["id"] == 459:
|
||
binding = next(b for b in bindings if b["name"] == name)
|
||
first = next(
|
||
t
|
||
for t in binding["targets"]
|
||
if (by_id[int(t["definition_node_id"])]["type"], t["field"]) in spec
|
||
)
|
||
tn = by_id[int(first["definition_node_id"])]
|
||
d = dict(spec[tn["type"], first["field"]])
|
||
d["field"] = name
|
||
d["label"] = "宿主暴露:" + d["label"]
|
||
note = "宿主保存值,经稳定边界送至" + ", ".join(
|
||
t["node_id"] + "." + t["field"] for t in binding["targets"]
|
||
)
|
||
else:
|
||
d = dict(spec[n["type"], name])
|
||
note = "固定参考采用此内部保存值;不等于目标执行已验证。"
|
||
role = "scalar"
|
||
if (nodeid, name) in target_host:
|
||
b = target_host[nodeid, name]
|
||
note = f"内部保存值保留,但被宿主{b['name']}({b['value_pointer']})覆盖。"
|
||
binding = b
|
||
role = "linked"
|
||
if n["id"] == 459 and name in ["prompt", "width", "height"]:
|
||
note += (
|
||
";进一步被根物理外线覆盖:"
|
||
+ {
|
||
"prompt": "483槽0,经link713",
|
||
"width": "13槽0,经link670",
|
||
"height": "13槽1,经link671",
|
||
}[name]
|
||
)
|
||
role = "linked"
|
||
if nodeid in ["459:456", "459:471", "459:474"] and name in [
|
||
"width",
|
||
"height",
|
||
"prompt",
|
||
"on_false",
|
||
]:
|
||
note += "宿主" + (
|
||
"prompt再被483槽0经713覆盖。"
|
||
if name in ["prompt", "on_false"]
|
||
else name + "再被ResolutionSelector13外线670/671覆盖。"
|
||
)
|
||
if (nodeid, name) == ("459:452", "prompt"):
|
||
note = (
|
||
"内部空文本被687覆盖:474槽0→472.source,"
|
||
"472槽0透传→452.prompt;当前宿主switch=true选471。"
|
||
)
|
||
role = "linked"
|
||
if name == "control_after_generate":
|
||
role = "frontend"
|
||
note = (
|
||
"前端附加控制fixed不改变seed;执行输入中剔除。"
|
||
"限定名sampling_mode.seed不新增此控件。"
|
||
)
|
||
if nodeid == "483":
|
||
note = (
|
||
"根483原字符串经713→459.prompt,分发到474.on_false与471.prompt,"
|
||
"优先宿主英文缓存。"
|
||
)
|
||
if nodeid == "459:475":
|
||
note = (
|
||
"原system指南经709→471.system_prompt;use_default_template=false条件"
|
||
"使传入tokenize的system_prompt为空,不采用此指南作为当前生效指令。"
|
||
)
|
||
d.update(
|
||
node_id=nodeid,
|
||
definition_node_id=str(n["id"]),
|
||
scope=scope,
|
||
class_type=n["type"],
|
||
value=v,
|
||
json_type=type(v).__name__,
|
||
pointer=prefix + f"/widgets_values/{offset}",
|
||
named_pointer=prefix + "/widgets_values_named/" + name,
|
||
role=role,
|
||
execution_note=note,
|
||
evidence=list(
|
||
dict.fromkeys(
|
||
[*d["evidence"], restore, host, hostsave, wid, execution, limits_ref]
|
||
)
|
||
),
|
||
)
|
||
if binding:
|
||
d["binding"] = binding
|
||
fields.append(d)
|
||
assert len(fields) == 64
|
||
comments = [
|
||
dict(
|
||
node_id=str(n["id"]),
|
||
pointer=f"/nodes/{i}/widgets_values/0",
|
||
text=n["widgets_values"][0],
|
||
)
|
||
for i, n in enumerate(s["nodes"])
|
||
if n["type"] == "MarkdownNote"
|
||
]
|
||
assert len(comments) == 2
|
||
api_raw = (OUT.parent / "supplied-api/04.api.json").read_bytes()
|
||
api = json.loads(api_raw)
|
||
diffs = []
|
||
scalars = endpoints = 0
|
||
for nid, a in result.prompt.items():
|
||
b = api[nid]
|
||
assert a["class_type"] == b["class_type"] and a["inputs"].keys() == b["inputs"].keys()
|
||
for name, v in a["inputs"].items():
|
||
w = b["inputs"][name]
|
||
assert type(v) is type(w)
|
||
if isinstance(v, list):
|
||
endpoints += 1
|
||
else:
|
||
scalars += 1
|
||
if v != w:
|
||
diffs.append(dict(node_id=nid, field=name, source_reference=v, supplied_api=w))
|
||
if a.get("_meta") != b.get("_meta"):
|
||
diffs.append(
|
||
dict(
|
||
node_id=nid,
|
||
field="_meta",
|
||
source_reference=a.get("_meta"),
|
||
supplied_api=b.get("_meta"),
|
||
)
|
||
)
|
||
assert len(result.prompt) == 16 and scalars == 42 and endpoints == 18
|
||
assert sum(d["field"] == "_meta" for d in diffs) == 14
|
||
assert len(diffs) == 16
|
||
flows = [
|
||
(
|
||
"本图用途:根提示词可选文本生成后编码图像条件,经空latent采样、VAE解码、SaveImageAdvanced保存。"
|
||
"源19节点(含宿主/两注释),根6节点4边,定义13节点33边,37源边与展开16实体/42最终标量/18端点分列。64"
|
||
"保存位置不是64最终执行参数。"
|
||
),
|
||
(
|
||
"作用域:根459实例引用definitions.subgraphs[0] c291ceec-b98f-4751-9d0b"
|
||
"-7bc288f27b30;内部ID写459:451等,同时保留原定义节点ID。-10/-20只是子图边界虚拟节点,非执"
|
||
"行算法。"
|
||
),
|
||
(
|
||
"优先链:实际物理外线→宿主暴露值→内部保存值。17控件由固定SubgraphNode逐边界/内部widget构造,wid"
|
||
"getId(rootGraph.id,459,input.name)寻址,具名/位置双存储一致;不按标签或端口数组猜。s"
|
||
"cheduler标签sampler实际到458.sampler_name,scheduler_1到458.schedul"
|
||
"er。"
|
||
),
|
||
(
|
||
"prompt:483槽0经713→459.prompt;定义边684到474.on_false、711到471.prom"
|
||
"pt,覆盖宿主英文缓存与内部空串。宿主switch=true经688覆盖474内部false,true取471槽0经71"
|
||
"2至on_true;false才直取483。474槽0经686→472文本预览,472槽0经687→452.prompt"
|
||
"。没有证明真实优化效果。"
|
||
),
|
||
(
|
||
"system指南:475原字符串经709至471.system_prompt;本图use_default_templat"
|
||
'e=false使tokenize(skip_template=true, system_prompt=""),所以指南虽'
|
||
"保存/连线却不采用。thinking=false也不表示模型真实支持;两个原prompt和指南均未改写/执行。"
|
||
),
|
||
(
|
||
"双seed:宿主/nodes/1/widgets_values/10=447606998181263经667→458.s"
|
||
"eed与697→471.sampling_mode.seed;两内部0均被覆盖。KSampler附加fixed为前端控制"
|
||
";限定名sampling_mode.seed不自动加控制,不声称队列随机化或目标可重复。"
|
||
),
|
||
(
|
||
"尺寸:宿主width/height保存1024/1024被13经670/671覆盖,再经660/661到456;13比例"
|
||
"3:4、1.5MP、multiple8,固定算法用MP×1024×1024开方并round到倍数。本轮未计算/生成产物,"
|
||
"不把1024或注释2048×2048当实际输出。452.resolution仅参考图像尺度,本图未接images,不决定"
|
||
"采样宽高。"
|
||
),
|
||
(
|
||
"模型链:451→480→458.model;453→452.clip;473→471.clip;454→457.vae。"
|
||
"宿主模型文件覆盖内部文件,反斜杠原样保留。动态列表/实际模型/设备/缓存/UE扩展安装未知,名称int8/bf16不证明"
|
||
"实际精度或内存效果。"
|
||
),
|
||
(
|
||
"条件和输出:452槽0/1分别→458.positive/negative;456→458.latent_image;4"
|
||
"58→457.samples;457槽0→子图-20→459槽0经672→461.images。452额外latent出"
|
||
"口未用。472仅文本预览/透传,不生成字幕文件。461固定png/8-bit/sRGB保存路径、元数据与ui.image"
|
||
"s是源码协议,实际history/文件/尺寸/色彩未验证。"
|
||
),
|
||
(
|
||
"两条MarkdownNote全文在下列原注释保留。模型链接/目录/原生2K、透明提示、建议步数/CFG均只是源注释,不是"
|
||
"已验证环境事实或下载授权;本轮没有加载权重、处理素材或访问目标目录。"
|
||
),
|
||
(
|
||
"case04历史配套:16实体42标量18端点逐项重核;除451.unet_name与473.clip_name两项反/"
|
||
"正斜杠路径字符串差异外其余输入及类型一致,14处标题差异保留。不推断路径等价/不等价;配套身份及目标安装未知,294配套"
|
||
"参数、空映射、companion_unverified/环境未检查/全停用不变。"
|
||
),
|
||
]
|
||
for b in bindings:
|
||
flows.append(
|
||
"暴露绑定:459."
|
||
+ b["name"]
|
||
+ ";"
|
||
+ b["widget_id_rule"]
|
||
+ ";"
|
||
+ b["value_pointer"]
|
||
+ ";边界"
|
||
+ b["boundary_pointer"]
|
||
+ " → "
|
||
+ json.dumps(b["targets"], ensure_ascii=False)
|
||
)
|
||
for scope, graph in [("root", s), ("definition", g)]:
|
||
for i, e in enumerate(graph["links"]):
|
||
flows.append("源边 " + scope + " " + str(i) + ":" + json.dumps(e, ensure_ascii=False))
|
||
restorations = json.loads((OUT.parent / "case04-evidence/field-pointers.json").read_bytes())
|
||
assert len(restorations) == 46
|
||
for row in restorations:
|
||
obj = s
|
||
for part in row["source_value_pointer"].strip("/").split("/"):
|
||
part = part.replace("~1", "/").replace("~0", "~")
|
||
obj = obj[int(part)] if isinstance(obj, list) else obj[part]
|
||
assert type(obj) is type(row["value"]) and obj == row["value"]
|
||
final_endpoints = [
|
||
dict(node_id=nid, field=name, endpoint=value)
|
||
for nid, node in result.prompt.items()
|
||
for name, value in node["inputs"].items()
|
||
if isinstance(value, list)
|
||
]
|
||
assert len(final_endpoints) == 18
|
||
# Current final graph evidence stays separate from saved UI positions.
|
||
(OUT / "reference-comparison.json").write_text(
|
||
json.dumps(
|
||
dict(
|
||
profile=CASE04_PROFILE,
|
||
serialization_stage=result.serialization_stage,
|
||
nodes=16,
|
||
scalars=42,
|
||
endpoints=18,
|
||
differences=diffs,
|
||
resolved_boundaries=result.resolved_boundaries,
|
||
saved_restorations=restorations,
|
||
final_endpoints=final_endpoints,
|
||
source_sha256=hashlib.sha256(raw).hexdigest(),
|
||
api_sha256=hashlib.sha256(api_raw).hexdigest(),
|
||
),
|
||
ensure_ascii=False,
|
||
indent=2,
|
||
)
|
||
+ "\n"
|
||
)
|
||
return dict(
|
||
notice="固定版本参考说明:声明frontend1.53.6/core0.38.0,UE7.8保存记录不证明实际扩展;目标模型/安装/设备/实跑未知",
|
||
source_path=PATH,
|
||
source_sha1=hashlib.sha1(raw).hexdigest(),
|
||
source_sha256=hashlib.sha256(raw).hexdigest(),
|
||
canonical_sha256=hashlib.sha256(canonical(s)).hexdigest(),
|
||
subgraph_sha256=hashlib.sha256(canonical(g)).hexdigest(),
|
||
versions=[
|
||
(
|
||
"frontend1.53.6=7d533a4cd4c4904ffdb0537f6b80ae9793dd62f1;仅固定保"
|
||
"存/恢复/serialize参考,实际队列设置未知。"
|
||
),
|
||
(
|
||
"全部可执行节点声明core0.38.0;精确提交6b747c0428c343e1417219641db93a4fb7cb"
|
||
"69ae沿promoted/case04来源清单,不套core0.33。"
|
||
),
|
||
"UE7.8记录/实际扩展影响、动态文件列表、模型素材可用性、目标安装和历史导出版本仍未知。",
|
||
],
|
||
counts=dict(
|
||
saved_fields=64,
|
||
root_saved=25,
|
||
definition_saved=39,
|
||
source_notes=2,
|
||
host_saved=17,
|
||
source_nodes=19,
|
||
physical_edges=37,
|
||
linked_saved_fields=sum(f["role"] == "linked" for f in fields),
|
||
frontend_only=1,
|
||
final_entities=16,
|
||
final_scalars=42,
|
||
final_endpoints=18,
|
||
),
|
||
fields=fields,
|
||
sources=refs,
|
||
flow=flows,
|
||
flow_evidence=list(range(len(refs))),
|
||
comments=comments,
|
||
bindings=bindings,
|
||
companion_difference=dict(
|
||
export_file="04.api.json",
|
||
export_sha256=hashlib.sha256(api_raw).hexdigest(),
|
||
differences=diffs,
|
||
source_export_equivalence_verified=False,
|
||
),
|
||
steps=[
|
||
"未来取得实跑授权后先核对真实前端/core/UE及动态模型列表;本轮不访问目标机、不运行插件或模型。",
|
||
"先在根图核对483原始提示及13比例/MP/倍数;宿主prompt/width/height缓存被外线覆盖,不把源注释当实际尺寸。",
|
||
"展开459逐项核对17宿主绑定和39内部保存值,保留作用域/JSON指针及覆盖说明,scheduler与scheduler_1不要互换。",
|
||
"核对提示开关true→471、false→原文本;本图默认模板关闭使475指南不采用,不能仅修改指南就承诺提示优化。",
|
||
"逐个核对UNET/两CLIP/VAE实际覆盖文件、cache和采样参数;双seed同源但含义不同。模型不存在/设备不支持须先处理真实环境,不依文件名宣称就绪。",
|
||
(
|
||
"核对452条件→458采样→457解码→461固定PNG链和472文本预览;真实history与产物经授权验证后再讨论保"
|
||
"存/质量。当前未定稿、未实跑、全停用,不增加执行资格。"
|
||
),
|
||
],
|
||
)
|
||
|
||
|
||
def main():
|
||
target = REPO / "calliope-backend/src/calliope/comfyui/source_reviews.json"
|
||
reviews = json.loads(target.read_bytes())
|
||
block = build()
|
||
assert reviews[PATH]["source_sha"] == block["source_sha1"]
|
||
reviews[PATH]["fixed_version_document"] = block
|
||
target.write_text(json.dumps(reviews, ensure_ascii=False, indent=2) + "\n")
|
||
(OUT / "definition.json").write_text(json.dumps(block, ensure_ascii=False, indent=2) + "\n")
|
||
print(hashlib.sha256(canonical(block)).hexdigest())
|
||
|
||
|
||
if __name__ == "__main__":
|
||
main()
|