"""Source-bound Chinese editorial reference, no upstream evaluation.""" import hashlib import json from pathlib import Path REPO = Path(__file__).resolve().parents[3] OUT = Path(__file__).resolve().parent REF = OUT.parent / "flux2-reference" PATHS = ["example_ComfyUI_workflows/3-图像生成/Flux/1_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) manifest = json.loads((REF / "sources.json").read_bytes())["sources"] sources = [] def cite(key, file, claim, first=1, last=None): 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-reference/" + e["local_file"], lines=[first, last or len(data.decode().splitlines())], claim=claim, ) ) return len(sources) - 1 nodes = cite( "core", "nodes.py", ("准确0.8.2注册、MAX_RESOLUTION、加载器、编码/解码和SaveImage") ) cfg = cite( "core", "comfy_extras/nodes_custom_sampler.py", "CFGGuider schema与设置条件", 801, 825 ) noise = cite( "core", "comfy_extras/nodes_custom_sampler.py", "RandomNoise种子与辅助声明", 898, 913 ) sampler = cite("core", "comfy_extras/nodes_custom_sampler.py", "采样器枚举/构造", 376, 395) cite( "core", ("comfy_extras/nodes_custom_sampler.py"), "双LATENT出口、噪声及x0条件分支", 915, 969 ) flux = cite( "core", ("comfy_extras/nodes_flux.py"), ("空latent尺寸声明和分配源码;只阅读不试算"), 36, 57 ) scheduler = cite( "core", ("comfy_extras/nodes_flux.py"), ("Flux2尺寸/序列长度/调度helper及准确注册"), 182, 249, ) prim = cite( "primitive", "comfy_extras/nodes_primitive.py", "准确0.9.1多行字符串schema/原值返回/注册", 25, 109, ) primio = cite( "primitive", "comfy_api/latest/_io.py", "准确0.9.1 STRING输入默认None,类未显式空串默认", 310, 328, ) tt = cite( "tt", ("nodes/resolution_selector.py"), ("准确固定提交预设、真假分支、自定义范围及原值返回") ) cite("tt", "__init__.py", "TT准确类注册;完整树无LICENSE文件,不推定许可") widgets = cite( "frontend", "src/scripts/widgets.ts", "准确1.36.14种子辅助、序列化和队列钩子;不执行" ) front = cite( "frontend", "src/lib/litegraph/src/LGraphNode.ts", "准确位置恢复/保存;不证明UE/tab附加钩子恢复", ) reroute = cite( "frontend", "src/extensions/core/rerouteNode.ts", "准确Reroute前端虚拟构造与注册、连接事件;不构造API", ) for e in manifest: if (e["id"], e["file"]) not in { (sources[i]["id"], sources[i]["file"]) for i in range(len(sources)) }: cite(e["id"], e["file"], "准确同树必要helper/类型、依赖或许可;只阅读原字节") labels = { "sampler_name": "采样器选择", "cfg": "条件引导强度", "noise_seed": "噪声种子缓存", "control_after_generate": "种子辅助控制", "filename_prefix": "PNG保存前缀", "width": "宽度缓存", "height": "高度缓存", "batch_size": "批量意图", "vae_name": "VAE文件引用", "use_custom_resolution": "自定义尺寸开关", "resolution": "尺寸预设", "custom_width": "自定义宽度", "custom_height": "自定义高度", "unet_name": "扩散模型文件", "weight_dtype": "加载精度选择", "steps": "调度步数", "clip_name": "文本编码器文件", "type": "编码器类别", "device": "编码器设备", "text": "编码文本缓存", "value": "中文画面描述", } names = { 79: ["sampler_name"], 81: ["cfg"], 86: ["noise_seed", "control_after_generate"], 9: ["filename_prefix"], 84: ["width", "height", "batch_size"], 87: ["vae_name"], 93: ["use_custom_resolution", "resolution", "custom_width", "custom_height"], 89: ["unet_name", "weight_dtype"], 80: ["steps", "width", "height"], 90: ["clip_name", "type", "device"], 88: ["text"], 97: ["text"], 76: ["value"], } # Each tuple states reference default, unit, conditions, actual purpose and exact evidence. details = { (79, "sampler_name"): ( "schema未显式default;动态枚举", "采样器名称", "comfy.samplers.SAMPLER_NAMES", "保存euler,由KSamplerSelect构造采样器→82.sampler;不运行采样,不保证质量/耗时。", [sampler], ), (81, "cfg"): ( "8.0", "无量纲", "FLOAT 0.0~100.0,step0.1,round0.01", ( "保存JSON int5,对照准确FLOAT schema,类型事" "实不改写。89模型及88/97正负条件进入CFGGuider后→" "82.guider;不能以数值保证引导效果。" ), [cfg], ), (86, "noise_seed"): ( "0", "INT种子", "0~0xffffffffffffffff;control_after_generate=True", ( "保存390513795427213,Ra" "ndomNoise→82.noise。整" "数是噪声缓存,randomize辅助另存" ",实际最终种子未知;不运行RNG。" ), [noise, widgets], ), (86, "control_after_generate"): ( "后端control_after_generate=True;准确前端辅助默认randomize", "前端辅助字符串", "fixed/increment/decrement/randomize;UE恢复次序未知", ( "保存randomize。准确前端辅助se" "rialize=false,不是独立后端" "输入;队列钩子可更新关联种子,不能据缓存" "预测最终执行种子,不执行钩子。" ), [noise, widgets, front], ), (9, "filename_prefix"): ( "ComfyUI", "文件名前缀字符串", "正式output PNG;目录权限/实际history未知", ( "保存Flux2-Klein。准确SaveImage直接定义RET" "URN_TYPES=()、OUTPUT_NODE=True,无I" "MAGE出口;PreviewImage才继承SaveImage并" "改临时目录。get_save_image_path处理子目录、尺" "寸替换与计数;逐批%batch_num%替换并追加五位count" "er及_.png,compress_level4。未disabl" "e_metadata且prompt/extra_pnginfo存" "在才写PNG文本;返回ui.images的filename/su" "bfolder/type=output描述符,不声称真实产物。" ), [nodes], ), (93, "use_custom_resolution"): ( "false", "BOOLEAN", "true返回自定义;false查预设,未命中回退(1024,1024)", ( "保存false,只表示预设分支意图。准确" "TT函数不做对齐、限幅或额外校正,sch" "ema范围不等于运行夹紧;目标恢复未知。" ), [tt], ), (93, "resolution"): ( "1024x1024 (1:1) (方形)", "宽高像素预设", "准确RESOLUTIONS字典枚举;false分支才使用", ( "保存1024x1024 (1:1) (方" "形)。准确字典对应宽/高整数;经94/9" "5分别扇出到84与80,不以保存预设保证" "最终分辨率。" ), [tt, reroute], ), (93, "custom_width"): ( "1024", "像素INT", "64~8192 step1;只在true分支返回", ( "保存1024;当前false分支不使用自" "定义宽度,不能冒充当前有效宽或与84/8" "0缓存合并。函数不对齐/限幅。" ), [tt], ), (93, "custom_height"): ( "1024", "像素INT", "64~8192 step1;只在true分支返回", "保存1024;当前false分支不使用自定义高度,不能冒充当前有效高。函数不对齐/限幅。", [tt], ), (84, "batch_size"): ( "1", "批量INT", "1~4096", ( "保存1,传空latent分配的批量维度;准确源码torch.ze" "ros([batch_size,128,height // 16" ",width // 16]),不试算或分配,不保证批量成功或显存" "。" ), [flux], ), (80, "steps"): ( "20", "调度步数INT", "1~4096", ( "保存20;准确Flux2Scheduler以尺寸得到序列长度,g" "et_schedule建立steps+1个timesteps并作" "SNR变换;不试算sigmas/表达式或承诺20步效果。" ), [scheduler], ), (89, "weight_dtype"): ( "schema无显式default;枚举首项default", "加载选项", "default/fp8_e4m3fn/fp8_e4m3fn_fast/fp8_e5m2", "保存default,不显式加入dtype覆盖;文件名fp8不证明实际dtype、设备或兼容性。", [nodes], ), (90, "type"): ( "schema无显式default;方法stable_diffusion", "类别枚举", "准确0.8.2枚举含flux2", "保存flux2,经CLIPType大写类别查找;这不是模型已安装或8B与4B兼容的证据。", [nodes], ), (90, "device"): ( "方法default;schema枚举default/cpu", "设备选项", "仅cpu分支显式设置加载/卸载CPU", "保存default,不能据此推断实际GPU、显存、精度或卸载行为。", [nodes], ), (88, "text"): ( "INPUT_TYPES无显式default", "字符串", "multiline=True/dynamicPrompts=True;clip不得为None", ( "保存空串被76.value外线覆盖;90.CLIP→88.cli" "p,编码条件→81.positive。完整中文源文在76保留,不" "运行tokenize/encode。" ), [nodes, prim], ), (97, "text"): ( "INPUT_TYPES无显式default", "字符串", "无text外线;clip由90输入", ( "保存空串仍进入CLIPTextEncod" "e→81.negative;不是Zero" "Out,也不等于没有负向条件。不运行编码" "或推算条件。" ), [nodes], ), (76, "value"): ( "类未显式default;String.Input默认None", "多行字符串", "准确0.9.1 StringMultiline;不套0.8.2默认", ( "完整摩托车/餐厅/夕阳复古中文描述原样→" "88.text覆盖空串。实现仅返回val" "ue;不生成改写文本或保证风格遵循。" ), [prim, primio], ), } fields = [] empty = [] for i, n in enumerate(g["nodes"]): ptr = f"/nodes/{i}" nid = n["id"] if not n.get("widgets_values"): state = ( "missing" if "widgets_values" not in n else ("null" if n["widgets_values"] is None else "empty_list") ) empty.append( dict( node_id=str(nid), class_type=n["type"], pointer=ptr, scope="root", state=state, effect=( "明确widgets_values=[],不是缺键或null。" if state == "empty_list" else "缺widgets_values键,不补[]或null。" ) + ( ( "82槽0 output→83,槽1 denoised_outpu" "t的links=[];准确实现有x0时构造去噪出口,否则两出口同" "引用;本图槽1未接。" ) if nid == 82 else ( "前端虚拟Reroute,只据准确1.36" ".14构造/保存/转接作有限参考,UE7" ".8组合未知。" ) if nid in [94, 95] else "83输入samples来自82槽0,vae来自87,输出IMAGE→9。" ), ) ) continue assert len(names[nid]) == len(n["widgets_values"]) for k, (name, v) in enumerate(zip(names[nid], n["widgets_values"], strict=True)): inp = next((j for j, x in enumerate(n["inputs"]) if x["name"] == name), None) if (nid, name) in details: default, unit, limits, effect, evidence = details[nid, name] elif name in ["width", "height"]: default, unit = "1024", "像素INT" limits = ("16~16384;空latent step16") if nid == 84 else "16~16384;调度器step1" effect = ( f"保存1024被{94 if name == 'width' else 95}.Reroute外线覆盖;" "93的宽高分别同时送84和80,四处缓存分列。" + ( "空latent的128通道与整除16维度只阅读源码,不试算。" if nid == 84 else ( "准确调度器seq_len=width*height/(16*16" "),round后送get_schedule;mu按image_s" "eq_len>4300分支和步数经验插值,torch.linsp" "ace再SNR变换,只静态描述不试算。" ) ) ) evidence = [flux if nid == 84 else scheduler, tt, reroute, nodes] elif name in ["unet_name", "clip_name", "vae_name"]: default, unit, limits = ( "动态文件列表,无固定文件默认", "模型文件引用", "安装/文件存在/许可/设备/兼容未知", ) effect = { "unet_name": ( "保存Flux\\flux-2-klein-base-9b-fp8." "safetensors,而properties推荐flux-2-" "klein-base-4b.safetensors及4B URL" "/diffusion_models目录。9B与4B及子目录差异保" "留,不归一。89→81.model。" ), "clip_name": ( "保存qwen_3_8b_fp8mixed.safetensors" ",而properties推荐qwen_3_4b.safetens" "ors及4B URL/text_encoders目录。8B与4B" "引用分开;90.CLIP同时→88和97。" ), "vae_name": ( "保存flux2-vae.safetensors,87.VAE→8" "3。properties同名引用与vae目录仅作者推荐文本。" ), }[name] + ( "准确加载器按对应目录动态列表和路径hel" "per取文件;不下载URL或由文件名推断" "精度/兼容。" ) evidence = [nodes] else: raise AssertionError((nid, name)) role = ( "frontend_reference_only" if inp is None else "linked_saved_cache" if n["inputs"][inp].get("link") is not None else "saved_layout_reference" ) fields.append( dict( node_id=str(nid), definition_node_id=str(nid), scope="root", class_type=n["type"], field=name, label=labels[name], pointer=f"{ptr}/widgets_values/{k}", 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=role, schema_default=default, unit=unit, limits=limits, effect=effect, evidence=evidence, execution_note=( "源保存值与参考默认分列;UE/附加tab" "恢复、模型/设备/实际效果未知。停用、转" "换关闭、未实跑。" ), ) ) assert len(fields) == 24 and len(empty) == 4 overview = ( "这张图计划把中文画面描述交给Flux2 Klein生成图片,分别" "准备正向和空串负向条件,选择尺寸后采样、解码并保存PNG。保存模" "型与推荐型号有差异,目前只提供阅读核对参考,模型安装、恢复行为和" "实际出图效果尚未确认。" ) flow = [ ( "独立原字节盘点:根17节点/20物理边、全mode0,无子图/N" "ote;24非注释保存位置,无widgets_values_na" "med。83/82明确[],94/95缺widgets_valu" "es,与null区分。" ), ( "主链89.UNET→81.model;90.CLIP同时→88正" "向与97负向编码;88→81.positive、97→81.ne" "gative。76完整中文描述→88.text覆盖空串,97.t" "ext空串无外线,不套ZeroOut或当无负向条件。" ), ( "86.RandomNoise→82.noise,81→82.gu" "ider,79.euler→82.sampler,80→82.s" "igmas,84→82.latent_image。82槽0 ou" "tput→83.samples,87→83.vae,83→9.S" "aveImage。82槽1 denoised_output li" "nks=[]未接;准确实现有x0/无x0分支分列,不执行噪声、采" "样或缓存操作。" ), ( "93.width槽0经94转接→84.width及80.widt" "h;93.height槽1经95→80.height及84.he" "ight。四处1024缓存分别被外线覆盖;TT false选预设" "、true返回自定义,未知预设回退1024对,无对齐/夹紧实现。" "源保存不保证最终分辨率。" ), ( "准确core0.8.2 FluxExtension注册Empty" "Flux2LatentImage和Flux2Scheduler。" "空latent源码分配batch/128通道/height //" " 16/width // 16;调度器尺寸乘积除16*16后ro" "und,get_schedule用经验mu及steps+1线性t" "imesteps再SNR变换。公式仅静态说明,不试算latent" "尺寸、表达式或sigmas。" ), ( "保存9B扩散与8B编码器,properties却推荐4B文件/U" "RL;目录及大小写/反斜杠原样保留。VAE引用不证明安装、许可或" "匹配,default不证明实际dtype或设备;不下载任何链接。" ), ( "准确SaveImage直接定义、RETURN_TYPES=()无" "IMAGE出口;PreviewImage继承后改temp。正式o" "utput PNG、批次/计数文件名、可选元数据与ui.imag" "es文件描述符按准确0.8.2区分;真实目录权限/history" "/产物未知。" ), ( "frontendVersion=1.36.14与同树LiteGr" "aph/锁文件独立固定。Reroute构造addInput/ad" "dOutput并标isVirtualNode,连接事件传播类型," "LGraphNode保存/恢复只作有限静态参考。不可继承旧pro" "file或构造API;UE7.5.2/7.7/7.8与tab附加" "属性分列,钩子恢复顺序未知。" ), ( "TT aux_id准确AICoderTudou/ComfyUI-" "TT-Resolution_selector-Node@b69c" "f75c2ce5f864e3db5301dba46a6b5eea" "a8fb;准确完整树无LICENSE文件,许可未知,不套新版或推" "定再许可。core/primitive GPL及frontend" "/同树LiteGraph许可只覆盖其自身,不覆盖模型或UE。" ), ( "常见问题:空串负向不是无条件;randomize与缓存种子不保证" "复现;1024缓存不是最终尺寸;模型推荐与保存不一致不是已兼容;" "20步/批1/PNG前缀不能保证质量、耗时、显存或产物。无真实h" "istory便不虚构。" ), ] flow += ["原物理边 " + json.dumps(e, ensure_ascii=False) for e in g["links"]] flow += [ "原模型声明 " + json.dumps(n["properties"]["models"], ensure_ascii=False) for n in g["nodes"] if "models" in n.get("properties", {}) ] flow += [ "节点" + str(n["id"]) + "独立UE/tab属性 " + json.dumps(n.get("properties", {}), ensure_ascii=False) for n in g["nodes"] ] versions = [ f"{e['id']} {e['tag']} 完整commit {e['commit']};tree {e['tree']}" for e in manifest if e["file"] in ["nodes.py", "__init__.py", "package.json"] ] versions += [ ( "PrimitiveStringMulti" "line独立core0.9.1,不继承多" "数节点0.8.2;UE7.5.2/7.7" "/7.8与宿主/附加tab钩子未知。" ), ( "local_file以docs/hel-892/flux2-do" "cument-evidence为基准;sources.json相" "对flux2-reference。获取时间与复核时间分列;源SH" "A256 " ) + hashlib.sha256(raw).hexdigest(), ] 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=24, root_saved_fields=24, internal_saved_fields=0, linked_saved_fields=5, frontend_only=1, source_nodes=17, root_nodes=17, internal_nodes=0, physical_edges=20, source_notes=0, history_objects=0, final_scalars=0, final_prompt_constructed=False, ), fields=fields, sources=sources, comments=[], flow=flow, flow_evidence=list(range(len(sources))), zero_saved_nodes=empty, boundaries=[], steps=[ overview, ( "操作1:先阅读完整中文画面描述、空串负向" "和三模型引用,比较保存9B/8B与推荐4" "B,不打开权重链接。" ), ( "操作2:核对TT尺寸分支、四缓存覆盖、独" "立版本与输出条件;先完成模型/节点/恢复" "及权限确认,不能凭参考说明启用。" ), ( "操作3:155全量完成审核后才发布。当前" "保持停用,不连接目标、不执行上游/模型/" "GPU/媒体/种子或队列钩子,不构造pr" "ompt、不下载素材。" ), ], )