Files
aigc-home/docs/hel-892/flux2-dual-document-evidence/build_definition.py
T

537 lines
22 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.
"""Bind only this original graph to independently checked, exact-version text."""
import copy
import hashlib
import json
import runpy
from pathlib import Path
REPO = Path(__file__).resolve().parents[3]
OUT = Path(__file__).resolve().parent
REF = OUT.parent / "flux2-dual-reference"
PATHS = ["example_ComfyUI_workflows/3-图像生成/Flux/8_flux2_klein_双图编辑.json"]
def canonical(v):
return json.dumps(v, ensure_ascii=False, sort_keys=True, separators=(",", ":")).encode()
def build(index=0):
raw = (REPO / PATHS[index]).read_bytes()
g = json.loads(raw)
# Reuse only checked common core schema prose; all identities, values and edges
# below belong to this graph. Old graph prose and version lists are not inherited.
old = runpy.run_path(str(OUT.parent / "flux2-real-document-evidence/build_definition.py"))[
"build"
]()
common = {(f["class_type"], f["field"]): f for f in old["fields"]}
manifest = json.loads((REF / "sources.json").read_bytes())["sources"]
sources = []
def cite(key, file, first, last, claim):
e = next(e for e in manifest if e["id"] == key and e["file"] == file)
data = (REF / e["local_file"]).read_bytes()
assert hashlib.sha256(data).hexdigest() == e["sha256"]
sources.append(
dict(
e,
local_file="../flux2-dual-reference/" + e["local_file"],
lines=[first, last],
claim=claim,
)
)
return len(sources) - 1
nodes = cite("core", "nodes.py", 57, 81, "准确0.8.2文本编码与STRING输入")
loadnode = cite(
"core",
"nodes.py",
1647,
1723,
"准确0.8.2 LoadImage后端image输入、alpha反向MASK与无alpha默认",
)
savenode = cite(
"core",
"nodes.py",
1578,
1646,
"准确0.8.2正式output PNG、temp Preview继承、无IMAGE返回",
)
vaenode = cite("core", "nodes.py", 701, 768, "准确0.8.2 VAELoader文件枚举与加载条件")
modelnode = cite("core", "nodes.py", 920, 992, "准确0.8.2 UNET/CLIP加载、类型及设备枚举")
cite("core", "nodes.py", 281, 353, "准确0.8.2 VAE编码解码")
cite("core", "nodes.py", 2010, 2170, "准确0.8.2核心类注册")
sampler = cite(
"core",
"comfy_extras/nodes_custom_sampler.py",
376,
395,
"KSamplerSelect准确枚举",
)
cfg = cite(
"core",
"comfy_extras/nodes_custom_sampler.py",
801,
825,
"CFGGuider正负条件与FLOAT声明",
)
noise = cite(
"core",
"comfy_extras/nodes_custom_sampler.py",
898,
913,
"RandomNoise种子及辅助声明",
)
cite(
"core",
"comfy_extras/nodes_custom_sampler.py",
915,
969,
"SamplerCustomAdvanced双LATENT出口与x0条件",
)
flux = cite(
"core",
"comfy_extras/nodes_flux.py",
36,
57,
"空Flux2 latent宽高/batch及128通道",
)
scheduler = cite(
"core",
"comfy_extras/nodes_flux.py",
182,
249,
"Flux2Scheduler准确尺寸/步数/注册",
)
scale = cite(
"core",
"comfy_extras/nodes_post_processing.py",
215,
246,
"准确0.8.2三缩放控件、FLOAT与INT、面积和对齐公式",
)
cite(
"core",
"comfy_extras/nodes_post_processing.py",
595,
612,
"PostProcessingExtension注册",
)
size = cite(
"core",
"comfy_extras/nodes_images.py",
494,
524,
"GetImageSize宽0/高1/batch2,schema说明与实际返回分开",
)
cite(
"core",
"comfy_extras/nodes_images.py",
619,
647,
"ImagesExtension注册GetImageSize",
)
reference = cite(
"core",
"comfy_extras/nodes_edit_model.py",
1,
38,
"ReferenceLatent追加reference_latents,不是采样起点",
)
negative = cite(
"negative",
"nodes.py",
57,
81,
"136独立准确core0.9.1 CLIPTextEncode输入、空串仍tokenize/encode",
)
cite("negative", "nodes.py", 1960, 1985, "准确0.9.1 CLIPTextEncode注册")
front = cite(
"frontend",
"src/lib/litegraph/src/LGraphNode.ts",
876,
950,
"准确1.40.0同树位置恢复和基础序列化;组合恢复未证",
)
widgets = cite(
"frontend", "src/scripts/widgets.ts", 80, 298, "准确1.40.0生成后种子控制,只静态阅读"
)
upload = cite(
"frontend", "src/extensions/core/uploadImage.ts", 1, 53, "准确1.40.0上传扩展保存边界"
)
for e in manifest:
if not any(s["id"] == e["id"] and s["file"] == e["file"] for s in sources):
data = (REF / e["local_file"]).read_bytes()
cite(
e["id"],
e["file"],
1,
len(data.decode().splitlines()),
"本图准确同树必要helper/许可/锁依赖文本;不执行",
)
names = {
122: ["sampler_name"],
125: ["noise_seed", "control_after_generate"],
127: ["vae_name"],
133: ["clip_name", "type", "device"],
136: ["text"],
137: ["cfg"],
138: ["steps", "width", "height"],
135: ["text"],
129: ["width", "height", "batch_size"],
130: ["upscale_method", "megapixels", "resolution_steps"],
131: ["upscale_method", "megapixels", "resolution_steps"],
94: ["filename_prefix"],
76: ["image", "upload"],
81: ["image", "upload"],
126: ["unet_name", "weight_dtype"],
}
scaling = (
"保存nearest-exact/JSON int1/JS"
"ON int1三控件,准确core0.8.2面积tota"
"l=megapixels*1024*1024,scale"
"_by=sqrt(total/(原宽*原高));宽高各r"
"ound(原尺寸*scale_by/resolution"
"_steps)*resolution_steps再int"
",common_upscale(crop=disable"
"d)。megapixels的FLOAT default1"
".0与源int1分列;resolution_steps是"
"INT default1/min1/max256。只静态"
"说明,不读取图片或计算尺寸,不保证精确十进制100万像素"
"、最终长宽比或两图同尺寸。"
)
meaning = {
122: (
"保存euler,122→123.sampler;准确枚举来自comfy.samplers,不运行采样,不保证质量或耗时。"
),
125: (
"保存1062632423628472/randomize"
",125→123.noise。噪声种子缓存、前端生成后辅"
"助与实际执行种子未知分列,不运行RNG、状态或队列钩子,"
"不保证复现。"
),
127: (
"保存flux2-vae.safetensors,127."
"VAE同时供140/143两参考编码及124最终解码。模"
"型引用与properties.models下载/目录元数"
"据原样保留;实际文件、目录、许可、设备和兼容未知,不加载"
"。"
),
133: (
"保存qwen_3_8b_fp8mixed.safeten"
"sors/flux2/default,CLIP分别供13"
"5正向及136空串负向。default是设备选项,不保证"
"实际设备、dtype、兼容或效果,不加载。"
),
136: (
"保存空字符串,133.CLIP→136→139加第一参考"
"→142加第二参考→137.negative。136独立"
"声明core0.9.1,不继承135的0.8.2身份;准"
"确代码仍对空串tokenize并encode_from_"
"tokens_scheduled,不是Condition"
"ingZeroOut或省略负向。STRING无显式def"
"ault,multiline/dynamicPrompt"
"s;不编码或改写。"
),
137: (
"保存JSON int5,schema FLOAT def"
"ault8.0/min0/max100/step0.1另"
"列。126.MODEL直接→137.model,没有Lo"
"RA;144正向、142负向→137→123.guide"
"r。不保证标志准确、身份、质量、精度或耗时。"
),
138: (
"保存20步与1024/1024缓存;128.GetIma"
"geSize宽槽0/高槽1分别覆盖138.width/h"
"eight。准确调度器按宽高估计序列长度和mu再变换时间"
"步;步骤默认20另列,不计算sigmas或保证效果。"
),
135: (
"完整保存英文指令,作者想把黄色“C”标志放到方向盘中心并"
"改为皇家蓝、保留内饰/光照/机位和其余元素。133.CL"
"IP→135→141加第一参考→144加第二参考→137"
".positive。文字是作者意图,未验证图片内容或编辑"
"结果,不保证局部像素不变、logo/文字准确;不编码或改"
"写。"
),
129: (
"保存1024/1024/1;128宽0/高1分别覆盖12"
"9.width/height,与138共四处1024缓存"
"。129空latent→123.latent_image"
"才是采样起点;140/143参考latent只进条件。准"
"确空latent按width//16、height//1"
"6分配128通道;未知图片尺寸,不分配张量或保证最终尺寸"
"。"
),
130: scaling + " 第一图76→130,130分别→128.GetImageSize及140.VAEEncode,控制输出画布宽高。",
131: scaling
+ (
" 第二图81→131→143.VAEEncode;独立缩放不进入128,"
"不控制输出画布尺寸,不能据两项megapixels=1断言两图同宽高。"
),
94: (
"保存前缀Flux2-Klein-4b-base,与126"
"实际9B模型引用分列,不能从前缀证明模型家族。123槽0"
"→124解码→94正式output PNG;源94.ou"
"tputs=[]与准确core0.8.2 RETURN_"
"TYPES=()一致,本图没有IMAGE输出口冲突,不补"
"线删口。隐藏元数据、目录/计数和真实history未知,"
"不写文件或构造prompt。"
),
76: (
"保存Flux2-Klein-4b-base_00010_"
".png/image,IMAGE→130第一图缩放,MA"
"SK未接(源links=null)。文件名仅作者线索,未"
"读取图像内容;image是上传控件保存状态,不证明素材存"
"在或已上传。"
),
81: (
"保存comfy_logo_blue.png/image,"
"IMAGE→131第二图独立缩放,MASK未接(源lin"
"ks=null)。文件名与提示词不能证明实际图片是log"
"o或其颜色,未读取素材;image为前端上传保存状态。"
),
126: (
"保存Flux\\flux-2-klein-base-9b-"
"fp8.safetensors/default,MODE"
"L直接→137.model,没有LoRA节点。反斜杠/实"
"际9B路径与94的4b前缀分列;不保证文件存在、兼容、许"
"可、精度、质量或耗时,不加载。"
),
}
evidence = {
122: [sampler],
125: [noise, widgets],
127: [vaenode],
133: [modelnode],
136: [negative, reference],
137: [cfg],
138: [scheduler, size],
135: [nodes, reference],
129: [flux, size],
130: [scale],
131: [scale],
94: [savenode],
76: [loadnode, upload],
81: [loadnode, upload],
126: [modelnode],
}
append = (
"准确0.8.2 ReferenceLatent仅在lat"
'ent is not None时,将[latent["s'
'amples"]]经conditioning_set_v'
"alues(..., append=True)追加ref"
"erence_latents;helper逐条件复制已有"
"元数据,已有非None值时旧列表+新列表,缺键或None"
"时设置新列表。仅静态阅读,不运行helper;若已有列表"
"其内容在前,本图追加第一参考再第二参考,不保证模型支持。"
)
empty_effect = {
123: (
"125.noise/137.guider/122.sam"
"pler/138.sigmas/129.latent_i"
"mage五输入;槽0→124,第二LATENT槽1 li"
"nks=[]未接。x0条件只静态解释。"
),
144: "141正向已含第一参考,加入143的第二参考LATENT→137.positive,追加顺序第一再第二。"
+ append,
142: "139负向已含第一参考,加入143的第二参考LATENT→137.negative,不能省略负向重复引用。"
+ append,
140: "130第一图+127.VAE编码LATENT,同时→141正向和139负向;不是129空latent采样起点。",
139: "136空串编码+140第一参考LATENT→142,再加第二参考。" + append,
143: "131第二图+127.VAE编码LATENT,同时→144正向和142负向;不控制输出宽高或替代129。",
128: (
"准确core0.8.2唯一IMAGE输入,返回width"
"槽0/height槽1/batch_size槽2;实际s"
"hape[2]/[1]/[0]。描述虽称passes i"
"t through,实际无IMAGE返回,描述冲突保留。"
"宽0覆盖138/129.width,高1覆盖138/12"
"9.height,共四处1024;batch槽2 lin"
"ks=[]未接。"
),
124: "123槽0+127.VAE解码,IMAGE→94正式保存;本图无比较器、Preview或历史展示列表。",
141: "135完整英文正向编码+140第一参考LATENT→144,再加第二参考。" + append,
}
fields, empty, comments = [], [], []
for i, n in enumerate(g["nodes"]):
nid = n["id"]
ptr = f"/nodes/{i}"
if n["type"] == "MarkdownNote":
comments.append(
dict(
node_id=str(nid),
pointer=ptr + "/widgets_values/0",
text=n["widgets_values"][0],
meaning=(
"完整模型/协议/下载/目录/更新/报错指南仅作者文本;不"
"代接受BFL协议、不下载或更新,不当本次操作事实。目录示"
"意不证明模型已安装;文本全文保留。"
),
evidence=[front],
)
)
continue
if n["widgets_values"] == []:
empty.append(
dict(
node_id=str(nid),
class_type=n["type"],
pointer=ptr,
scope="root",
state="empty_list",
effect="明确widgets_values=[],零保存位置,不是缺键或null。"
+ empty_effect[nid],
)
)
continue
for j, (name, v) in enumerate(zip(names[nid], n["widgets_values"], strict=True)):
f = copy.deepcopy(common[n["type"], name])
inp = next((k for k, x in enumerate(n["inputs"]) if x["name"] == name), None)
f.update(
node_id=str(nid),
definition_node_id=str(nid),
scope="root",
class_type=n["type"],
field=name,
pointer=f"{ptr}/widgets_values/{j}",
value=v,
json_type=type(v).__name__,
named_pointer="源无widgets_values_named,不构造具名保存指针",
input_pointer=f"{ptr}/inputs/{inp}"
if inp is not None
else "无独立后端输入:前端辅助",
input_name=name if inp is not None else None,
type=n["inputs"][inp]["type"] if inp is not None else "前端辅助",
role="frontend_reference_only"
if inp is None or (nid in [76, 81] and name == "upload")
else "linked_saved_cache"
if n["inputs"][inp].get("link") is not None
else "saved_layout_reference",
effect=meaning[nid],
evidence=evidence[nid],
execution_note="源现值与准确默认分列;目标安装/素材/模型/UE恢复/实际效果未知;停用、未实跑、转换资格不变。",
)
if name in ("width", "height"):
f["effect"] += f" 本位置{name}由128槽{0 if name == 'width' else 1}外线覆盖。"
if name in ("control_after_generate", "upload"):
f["schema_default"] = "前端辅助保存状态,不是后端输入默认"
f["limits"] = "准确frontend1.40.0基础静态参考;UE/tab组合恢复未知"
if nid in [135, 136]:
f["schema_default"] = "无显式default;STRING multiline/dynamicPrompts"
f["limits"] = "准确core" + (
"0.9.1独立负向空串仍编码,不是ZeroOut"
if nid == 136
else "0.8.2;作者意图,不保证效果"
)
f["label"] = "负向空串编码" if nid == 136 else "双图编辑英文指令"
f["unit"] = "编码文本"
fields.append(f)
assert len(fields) == 29 and len(empty) == 9 and len(comments) == 1
assert len(comments[0]["text"]) == 1407
overview = (
"这张图希望结合两张参考图片完成编辑:作者文字要求调整方向"
"盘中心标志与颜色。两图独立缩放后分别编码,并按第一图、第"
"二图顺序同时加入正负条件;从空latent采样后保存PN"
"G。未读取图片或实跑,图片内容、模型兼容和编辑效果均未验"
"证,目前仅供参考。"
)
flow = [
overview,
(
"原字节独立盘点:25节点/32边,全mode0,无子图/"
"具名保存;29非注释位置均标量,另1完整Markdown"
"Note97(1407字符)。九[]为123/144/1"
"42/140/139/143/128/124/141,逐"
"项零保存位置;无缺键/null,不混计。"
),
]
flow += [
meaning[k] for k in (76, 81, 130, 131, 133, 135, 136, 126, 127, 137, 125, 138, 129, 94)
]
flow += [empty_effect[k] for k in (128, 140, 143, 141, 144, 139, 142, 123, 124)]
flow += [
(
"本图无LoRA、比较器、Preview、历史展示列表或局"
"部遮罩链;两MASK未接,参考latent是条件而非像素"
"拼接或遮罩复合。题名“编辑”不保证未编辑区域像素不变或l"
"ogo/文字准确。"
),
(
"多数core0.8.2,136负向独立core0.9.1"
",图级frontend1.40.0及同树LiteGrap"
"h/锁依赖逐图绑定;没有TT/KJ/Impact/Lay"
"erUtility/Painter/llama/rgth"
"ree/LoRA适用身份,不套旧图版本。UE属性原件本图"
"均7.7,其他图7.5.2/7.8不能推定适用;tab及"
"宿主组合恢复未知。"
),
(
"Note97全文为作者模型/协议/下载/更新指南;不代接"
"受或执行。常见问题:文件名不是已读内容;两项megapi"
"xels=1不证明同宽高或精确百万像素;第二图不控制输出"
"画布;空串负向仍编码;第一和第二参考顺序分别用于正负条件"
";4b前缀不证明实际9B模型。155定稿0/实跑0/新增"
"转换0。"
),
]
flow += ["原物理边 " + json.dumps(e, ensure_ascii=False) for e in g["links"]]
flow += [
"节点"
+ str(n["id"])
+ "独立属性 "
+ json.dumps(n.get("properties", {}), ensure_ascii=False)
for n in g["nodes"]
]
versions = []
for key in ("core", "negative", "frontend"):
e = next(s for s in sources if s["id"] == key)
versions.append(
f"{key} {e['tag']} commit {e['commit']};tree {e['tree']};许可见{e['license_file']}"
)
versions += [
"local_file以docs/hel-892/flux2-dual-document-evidence为基准;原字节SHA256 "
+ hashlib.sha256(raw).hexdigest(),
"同字节必要文本逐图重绑Git对象和精确行号;静态参考,不执行上游/插件/表达式。旧53块2044位置+59注释逐对象冻结。",
]
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="仅参考:目标素材/模型、UE恢复和实际效果未核;转换关闭、未实跑。",
user_overview=overview,
versions=versions,
counts=dict(
saved_fields=29,
root_saved_fields=29,
internal_saved_fields=0,
linked_saved_fields=4,
frontend_only=3,
source_nodes=25,
root_nodes=25,
internal_nodes=0,
physical_edges=32,
source_notes=1,
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=[],
steps=[
overview,
"阅读1:核对完整英文/空串负向、两图文件名、模型及Note97,链接仅文本;不打开素材或下载。",
"阅读2:核对两图独立缩放与第一图控制四处尺寸缓存、双参考正负条件顺序、129空latent采样起点、124→94正式PNG。",
(
"阅读3:保持停用,155全量完成审核后才发布;目标安装/"
"许可/素材/恢复/效果未知,不连接目标或构造prompt"
",不执行模型/GPU/媒体/种子/状态/缓存。"
),
],
)