Extensions/Model Resolution Selector (比例 → 模型 → 分辨率)
ComfyUI Extension

Model Resolution Selector (比例 → 模型 → 分辨率)

Resolution picker for ComfyUI with two layers: pick an aspect ratio first, then a size that is tagged with the model family it is official or in-budget for (SD1.5 / SDXL / Qwen-Image 1.0 / Qwen-Image 2.1 / Krea-2 / FLUX.2 / FLUX.3 / MOSS).

By Omg-ciTy·Created a day ago·Updated a day ago· 0
Omg-ciTy/Comfyui-model-resolution-selector-AAA
Nodes—
On cloudLocal install
Stars0
Updateda day ago
Readme

Model Resolution Selector · 分辨率选择器

tests license: MIT

Model Resolution Selector

Aspect ratio first, model family second, resolution third — and every resolution tells you which model officially recommends it.

A ComfyUI custom node whose only output is two plain INTs (width, height), so it drops into EmptyLatentImage, EmptySD3LatentImage, EmptyFluxLatentImage or anything else that asks for a size.

English: a ratio → model → resolution picker with 17 ratios and 436 documented sizes. 119 of those sizes are official buckets from the model cards (SDXL paper Table 1, Qwen-Image 1.0/2.1 READMEs, the official Krea-2 ComfyUI template, FLUX.2 / FLUX.3 API docs, MOSS-Image USERGUIDE); the rest are ladders confined to each family's own side/area budget, so you get more than one 2K choice without leaving the range the model was trained for.

Node type: ModelResolutionSelector — it deliberately avoids the core ResolutionSelector shipped since ComfyUI 0.25, so the two can live in the same workflow.

┌──────────────────────────────┐
│ 分辨率选择器                  │
│ ratio        [16:9 (Wide)]   │  ← layer 1: aspect ratio
│ model_filter [全部 (All)]    │  ← layer 2: model family (defaults to all)
│ resolution   [2752x1536 …]   │  ← layer 3: sizes for this ratio × this model
│ swap_w_h     [false]         │  ← optional: swap width/height
│                     width ●  │  INT
│                    height ●  │  INT
└──────────────────────────────┘

界面

三个下拉就是三层选择。第三层的下拉里,每一条都带 比例 · 像素 · 面积 · 支持该尺寸的模型,官方桶还会额外标 官方:

节点 + 分辨率列表

第一层:17 个比例(前 8 个与内置 ResolutionSelector 同名,新版前端会显示成中文):

比例列表

第二层:模型家族,选完第三层立刻只剩这个家族认可的尺寸:

模型列表

安装

方式一:ComfyUI Registry(推荐,可在 Manager 里升级)

comfy node install model-resolution-selector

或在 ComfyUI-Manager 里搜索 Model Resolution Selector。Registry 页面: https://registry.comfy.org/nodes/model-resolution-selector

方式二:git clone(可 git pull 更新)

cd <ComfyUI>/custom_nodes
git clone https://github.com/Omg-ciTy/Comfyui-model-resolution-selector-AAA

方式三:手动拷贝 —— 把整个 comfyui-resolution-selector 文件夹放进 custom_nodes:

<ComfyUI>/custom_nodes/comfyui-resolution-selector/
    __init__.py
    nodes.py
    resolutions.py
    web/model_resolution_selector.js

然后重启 ComfyUI,在画布空白处双击搜 “分辨率选择器” / “Model Resolution Selector”。 没有第三方依赖,不需要 pip install。

改完插件要两步才生效:① 重启 ComfyUI(nodes.py / resolutions.py 改了输入顺序或枚举时必须重启); ② 浏览器 Ctrl+F5 硬刷新(web/*.js 是按 URL 缓存的)。只重启不刷新,第三层还是旧列表。

使用

  1. 第一层选比例(17 个,前 8 个与内置 ResolutionSelector 的写法完全一致);
  2. 第二层选模型家族——选 全部 (All models) 就列出该比例下所有模型都能跑的尺寸;
  3. 第三层选分辨率,标签里写着它属于哪个模型:
16:9 (Widescreen) · 2752x1536 · 4.03MP · Qwen-Image 2.1 官方
16:9 (Widescreen) · 2720x1536 · 3.98MP · FLUX.3 2k | FLUX.2 4MP
16:9 (Widescreen) · 912x512    · 0.45MP · SD1.5

官方 后缀 = 模型文档里点名的桶;带档位名的(FLUX.3 4k、MOSS 1.5M、Krea-2 模板)= 按官方档位面积现算; 只写模型名 = 阶梯尺寸,落在该模型的边长/面积预算内。一条尺寸能被多个模型跑时,标签会并列写出来。

为什么是这两个过滤顺序

三层是联动的:改比例或改模型,第三层立刻换成新列表;当前值不在新列表里就落到新列表第一条。 反过来说,如果在工作流里加载到一条属于别的比例/模型的值,前两层会自动跟着走。 空列表不会出现——若某个模型对某比例没有任何桶,就退回显示该比例的全部尺寸。

各模型的预算与官方桶

| 模型 | 官方口径 | 官方桶 | 阶梯预算(短边/长边/面积) | | --- | --- | --- | --- | | SD1.5 | 512² 训练,非方形靠短边 512 | 无固定桶 | 短边 ≤ 1536、面积 ≤ 1.2MP | | SDXL | 论文 Table 1 的 9 个 1MP 桶 | 1024², 1152×896, 896×1152, 1216×832, 832×1216, 1536×640, 640×1536, 1344×768, 768×1344 | 边长 ≤ 2560、面积 ≤ 4MP | | Qwen-Image 1.0 | ~1.76MP,7 个比例桶 | 1328², 1472×1140, 1140×1472, 1584×1056, 1056×1584, 1664×928, 928×1664 | 边长 ≤ 2560、面积 ≤ 4MP | | Qwen-Image 2.1 | README 的 Supported Aspect Ratios(约 4MP,边长 32 对齐) | 2048², 2400×1792, 1792×2400, 2528×1696, 1696×2528, 2752×1536, 1536×2752 | 边长 ≤ 2752、面积 ≤ 4MP | | Krea-2 | 官方 ComfyUI 模板用 1MP(ResolutionSelector megapixels=1) | 每个比例一条 ≈1MP,标 Krea-2 模板 | 边长 ≤ 2752、面积 ≤ 4MP | | FLUX.2 | “up to 4MP output”,只有 width/height(min 64),无固定桶 | 1MP / 4MP 两档 | 边长 ≤ 4096、面积 ≤ 4MP | | FLUX.3 | resolution 档位 768sq / 1k / 1.5k / 2k / 4k,边长 256–6256,面积 ≤ 16,822,272 | 1k / 2k / 4k 三档 | 边长 ≤ 6256、面积 ≤ 16.8MP | | MOSS-Image | 推荐 1M / 1.5M / 2M,宽高必须是 16 的整数倍 | 1M / 1.5M / 2M 三档 | 边长 ≤ 4096、面积 ≤ 4MP |

共 17 个比例 / 436 条尺寸(每比例 19–29 条):1:1、4:3、3:4、3:2、2:3、16:9、9:16、5:4、4:5、 7:5、5:7、7:4 (SDXL Wide)、4:7 (SDXL Tall)、21:9、9:21、2:1、1:2。 完整清单见 docs/resolution-table.txt,也可以直接在节点第三层翻。

阶梯只是“把官方面积档位按比例铺开”:短边取 512 / 640 / 768 / 896 / 1024 / 1280 / 1536 / 1792 / 2048 / 2560, 长边取 1024 / 1280 / 1536 / 1792 / 1920 / 2048 / 2160 / 2560 / 2880 / 3072 / 3440 / 3840 / 4096, 两个方向都按比例换算并 16 对齐,再用各家族自己的预算裁掉。所以同一个 2:3, Qwen-Image 2.1 有 13 档(0.38MP → 4.09MP),SD1.5 只有 5 档(≤1.04MP),FLUX.3 有 25 档(到 3344×5008)。

数据来源

  • SDXL:论文 SDXL: Improving Latent Diffusion Models for High-Resolution Image Synthesis,Table 1
  • Qwen-Image 1.0 / 2.1:huggingface.co/Qwen/Qwen-Image、huggingface.co/Qwen/Qwen-Image-2.1 的 README
  • Krea-2:huggingface.co/Comfy-Org/Krea-2 与官方模板 image_krea2_turbo_t2i.json
  • FLUX.2 / FLUX.3:docs.bfl.ai 的 API 文档(宽高范围、面积上限、resolution 档位)
  • MOSS-Image:huggingface.co/OpenMOSS-Team/MOSS-Image-SFT 与 github.com/OpenMOSS/MOSS-Image 的 USERGUIDE

模型文档改了就改 resolutions.py,重启即可,不用动前端。

修改分辨率表

所有数据都在 resolutions.py 顶部:

  • RATIOS:比例标签 → (w_ratio, h_ratio);
  • SDXL_OFFICIAL / QWEN_IMAGE_10_OFFICIAL / QWEN_IMAGE_21_OFFICIAL:官方固定桶;
  • SHORT_EDGE_LADDER / LONG_EDGE_LADDER:阶梯取值;
  • FAMILIES:每个模型一个 Family(tag, official, tiers, min_side, max_side, max_area, stride)—— tiers 是 ((megapixels, 档位名), ...),None 预算表示不限。新增同类型模型加一行即可;
  • MODEL_FILTERS:model_filter 下拉里的顺序。

标签格式是前后端约定,改的时候两边都要改:

"<ratio> · <w>x<h> · <mp>MP · <tag> | <tag>"

前端只做三件事:按 " · " 第一段取比例过滤、按最后一段拆标签做模型过滤、列表变了就用 widget.options = { ...widget.options, values } 整体替换(新版 Vue 节点渲染器只读响应式 store 里的 options, 原地 options.values = [...] 不会被跟踪,下拉就不会刷新——这是 1.0.x 里“选了比例第三层不动”的根因)。 后端 resolve() 先查标签索引,查不到再用正则 (\d+)\s*[x×*]\s*(\d+) 从标签里抠像素, 所以表变了、旧工作流里的老标签也不会炸,最差也会回落到该比例最小的一档。

自检

# 纯 Python:表结构、各家族预算、比例误差、节点往返(无需 ComfyUI、无需 pytest)
python tests/test_plugin.py

# 走一遍 ComfyUI 自己的加载器(注册节点 + 注册 web 目录),要用 ComfyUI 的解释器
python tools/load_in_comfyui.py "X:\ComfyUI"

# 重新生成 docs/resolution-table.txt
python tools/dump_table.py

已验证

  • ComfyUI 0.46.4 / 前端 1.59.6,新旧两套节点渲染器都测过(旧版 canvas 走 options.values,新版 Vue 走 store);
  • 1:1 列表 20 条 → 切到 2:3 变 26 条 → 模型选 Qwen-Image 2.1 收窄到 13 条,Vue 下拉 DOM 里同样只有 13 项;
  • 2:3 · 848x1280 送进 EmptyLatentImage 得到 latent (1, 4, 160, 106) = 848×1280;勾上 swap_w_h 得到 1280×848。

与内置 ResolutionSelector 的区别

| | 内置 ResolutionSelector | 本插件 ModelResolutionSelector | | --- | --- | --- | | 第二层 | 连续 megapixels 滑杆 + multiple 对齐 | 离散枚举,每条都带模型官方来源 | | 比例 | 8 个 | 17 个(含 SDXL Wide/Tall、5:4、7:5、2:1 等) | | 模型过滤 | 无 | 有(8 个家族) | | 输出 | width / height + RESOLUTION_PREVIEW | 只有 width / height 两个 INT |

内置节点适合“我要 1.5MP 随便多少像素”,本插件适合“我要 Qwen-Image 2.1 官方那个 2752×1536”。 两者可以在同一个工作流里共存。

发布到 ComfyUI Registry

元数据在 pyproject.toml,打包范围由 .comfyignore 决定(只发节点本体,不带 tests/、docs/、tools/)。

# 预览:打印请求体和归档文件清单,不联网
python tools/publish_registry.py --dry-run

# 发布(API key 在 registry.comfy.org → 你的 publisher → Create API key 生成)
set COMFY_REGISTRY_TOKEN=...      # PowerShell: $env:COMFY_REGISTRY_TOKEN='...'
python tools/publish_registry.py --publisher <publisher-id> --changelog "..."

也可以装 comfy-cli 后用官方命令:comfy node publish。两者走的是同一套 registry 接口 (POST /publishers/<publisher>/nodes/<node-id>/versions 拿签名 URL,再 PUT 上传 zip)。

License

MIT