Repository navigation
Studio: recognise ComfyUI checkpoints by name and header, and list ComfyUI model folders - #12878
Conversation
…em per file - Family names match separator-insensitively (_ - . and spaces), so ComfyUI spellings such as wan2.2_ti2v_5B, flux-2-klein, flux2_dev, lumina_2 and qwen_image_2.1 resolve. Every previously detected name keeps its family. - New header-only classifier (safetensors JSON header / GGUF tensor table, no torch) recognises each supported DiT in ComfyUI and diffusers layouts and identifies text encoders, VAEs, LoRAs and ControlNets. A local pick resolves its family from content when the name is missing or wrong; the name still picks between same-architecture variants. Non-DiT files are refused with a message naming what they are, before any weight is read. - Library: a folder lists every DiT-like .safetensors / .gguf individually and one file of many can be picked. A ComfyUI root or models/ folder (and its extra_model_paths.yaml) is scanned for diffusion_models/, unet/ and checkpoints/; text encoder and VAE folders are recorded for later use.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
…nd from keys FLUX.1 companions come from the ungated schnell repo, so a flux1-dev or flux1-krea-dev file that no defaults key named fell through to schnell's 4 steps / no guidance (and Krea-dev names matched Krea-2's row). Add the ComfyUI/BFL flux1-* spellings, and let a local file's keys break the tie when the name cannot: schnell is the only FLUX.1 without guidance_in.
|
The red
|
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ab72aa5a05
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| comfy_roots = tuple( | ||
| root for root in comfy_dit_scan_roots(folder_path) if root not in nested_roots | ||
| ) | ||
| if comfy_roots: | ||
| nested_roots = (*nested_roots, *comfy_roots) |
There was a problem hiding this comment.
Filter Comfy container directories from the Hub inventory
When the registered path is the ComfyUI models/ directory, the initial _scan_models_dir(folder_path) classifies role directories such as diffusion_models/, unet/, and their plain subfolders as loadable safetensors models because they contain immediate weights. Adding those same directories as nested roots then lists the actual checkpoint files without removing the container rows, so the Hub catalog contains duplicate, unloadable folder entries. The compatibility scanner explicitly removes these rows with comfy_role_dirs; the primary inventory needs equivalent filtering before returning generic.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not reproduced: registering the ComfyUI root or its models/ folder (sub-folder scan on and off, with diffusion_models/, unet/wan/ and checkpoints/ holding weights) lists only the checkpoint files on the Hub inventory, no container rows.
| for key, entry in payload.items(): | ||
| shape = entry.get("shape") if isinstance(entry, dict) else None | ||
| shapes[str(key)] = [int(d) for d in shape] if isinstance(shape, list) else [] |
There was a problem hiding this comment.
Handle malformed safetensors shapes without raising
For a corrupted or user-supplied safetensors header whose shape array contains a non-integer value such as null, int(d) raises TypeError. inspect_checkpoint() does not catch TypeError, despite its never raises contract, so download-plan/load validation can return a 500 instead of treating the checkpoint as unreadable. Validate each dimension or include TypeError in the parsing failure path.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 8caac96: TypeError joins the header parse failures, so a null dimension reads as unreadable.
| if not override: | ||
| fam = _family_from_content(fam, repo_id, gguf_filename) |
There was a problem hiding this comment.
Preserve the detected FLUX variant in quantized GGUF routing
For a locally renamed FLUX.1 dev GGUF whose path contains no variant token, this new content fallback accepts it as FLUX.1 and content_variant_hint() correctly identifies it as dev, but the dense/prequant routing guards still call transformer_variant_differs_from_base() using only the opaque filename/path. With the family's default schnell base and automatic or explicit transformer quantization, those guards therefore see no mismatch and can substitute the schnell transformer from the base/prequant repo, silently generating with different weights than the selected checkpoint. Pass the content-derived variant into both variant-mismatch checks before enabling the replacement path.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 8caac96: FLUX.1 now declares its schnell / dev / Krea-dev checkpoint variants (compared on a canonical spelling) and both guards also get the header's variant, so a dev GGUF on the schnell fallback base stays on its own weights while a dev GGUF on the dev base keeps the fast path.
| info = diffusion_content.inspect_checkpoint(str(path)) | ||
| if info.role == diffusion_content.ROLE_DIT: | ||
| return bool(info.family) |
There was a problem hiding this comment.
Exclude video checkpoints that single-file loading rejects
Returning every recognized DiT family here advertises checkpoints that the video validator categorically refuses: each Wan2.2 A14B expert is listed separately even though validate_load_request() rejects every single-file MoE pick because one file contains only one transformer, and a renamed MiniMax-H3 checkpoint is listed even though modular single-file loading requires is_h3_comfy_name() to infer its supported format and partition. These rows appear as text-to-video models and then fail whenever selected, so loose-file offering needs to apply the same family-specific single-file eligibility rules as the loader.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 8caac96: the listing applies the loaders' single-file rules (pipeline-only image families, dual-expert video families, MiniMax-H3 only when its ComfyUI name parses).
| _register( | ||
| index, | ||
| keys, | ||
| MediaModelPick(keys[0], str(load_dir.parent), load_dir.name, "single_file"), | ||
| ) |
There was a problem hiding this comment.
Compare single-file filenames before reusing a resident model
When two safetensors checkpoints from the same Comfy folder are indexed, both picks use the parent directory as model_path and differ only in gguf_filename. resident_is_pick() treats every non-GGUF pick with that same path as resident without comparing the filename, so after checkpoint A is loaded an API request naming checkpoint B skips the auto-switch and generates with A. The status already publishes gguf_filename; single-file residency and replacement identities need to include it just as GGUF residency distinguishes builds.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 8caac96: a single_file pick is resident only when the published gguf_filename matches too.
| default_steps, _ = default_generation_params( | ||
| gguf_filename, repo_id, base, fam.name | ||
| gguf_filename, | ||
| content_variant_hint(repo_id, gguf_filename), | ||
| repo_id, |
There was a problem hiding this comment.
Apply checkpoint-derived defaults to OpenAI image requests
The content hint is used for internal cache and flow-shift decisions only, while /v1/images/generations still computes defaults from status.repo_id and status.base_repo. A newly listed local FLUX.1 dev checkpoint is loaded with its parent directory as the repo id and the schnell companion base, so an API request that omits steps/guidance receives schnell's 4-step, zero-guidance recipe instead of the dev checkpoint's 20/3.5 recipe—even when its filename clearly says dev, because the filename is absent from that lookup. Persist the selected filename/content variant in the default lookup used by the API route.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 8caac96: the images route looks defaults up by file name, the header's variant, repo, then base, the same order as the load.
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8caac96849
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if info.role != ROLE_DIT or not info.family: | ||
| return name_family, False |
There was a problem hiding this comment.
Reject DiTs recognized as unsupported
When a header positively identifies an unsupported DiT and therefore returns ROLE_DIT with no family—such as FLUX Fill/Depth/Canny—the fallback here restores any family inferred from the filename. Thus a local flux1-fill-dev.safetensors passes validation as ordinary FLUX.1 and proceeds into an incompatible loader instead of being refused before model eviction; reserve name fallback for ROLE_UNKNOWN and return no family for recognized family-less DiTs.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 37bc026: a header-recognised unsupported DiT (FLUX Fill/Depth/Canny, SD3, ...) is refused on both pages with what it is, and the name no longer revives it.
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…yUI merges (#12958) Each of these PRs was green on its own; the repo-wide guards they now trip landed or tightened alongside them. The risky-loader baseline and the parallel-isolation entry for the same merges are in #12954. - test_source_read_encoding: pass encoding="utf-8" in test_decision_gguf_real.py (#12939) and test_comfy_file_detection.py (#12878). - test_every_long_lived_spawner_consults_the_shutdown_latch: native_worker.py (#12939) gates before the spawn and rereads the latch in _wait_ready after adopt_pid, so it belongs in the guarded set. Add a test that pins the race it closes: a latch set during the spawn kills the new server and removes its key file. - test_export_owner_single_mode_preserves_operation_and_status_bytes: #12939 added the optional decision field to the export status response, null for any other model. The byte-for-byte expectation from #10588 now includes it.
Summary
ComfyUI model files now load natively in Studio. Studio used to detect a model family from the file name alone, and only when the name used hyphens. Because of that, many ComfyUI files were never recognised. Text encoders and VAEs whose names contain a family word were accepted as the model, and a ComfyUI
diffusion_modelsfolder showed only its GGUF files.1. Family names ignore separators
_,-,.and spaces as the same separator. This applies on both the image and video pages, tofamily_overrideand to the default steps/guidance tables.wan2.2_ti2v_5B_*andWan2_2-TI2V-5B_*wan2.2_t2v_*_14B_*flux-2-klein-*flux2_dev_fp8mixedlumina_2*qwen_image_2.1_*now detects as Qwen-Image-2.1. Before, it was detected as plain Qwen-Image, which is the wrong model.qwen_image_2.1_*, which was the intended fixSome of these name matches are text encoders and VAEs. The header check in section 2 refuses them.
2. Detection from the file header
core/inference/diffusion_content.pyreads only the safetensors JSON header or the GGUF tensor table. It does not import torch and does not read any weight bytes. Results are cached by path, size and mtime.model.diffusion_model., which covers all-in-one checkpoints....-inpaint) stays refused.family_overrideare unchanged.Results on all 216 sampled files: 120 DiTs, all with the expected family or an unsupported architecture; 50 text encoders; 25 VAEs; 20 LoRAs; 1 ControlNet; 0 unknown. All 14 supported diffusers transformer layouts are recognised as well.
FLUX.1 dev, Krea-dev and schnell defaults
The FLUX.1 family takes its companion files from the ungated schnell repo. Because of that, a
flux1-dev*orflux1-krea-dev*file that no defaults key matched got schnell's 4 steps and no guidance. Krea-dev names also matched Krea-2's row.flux1-*file names used by ComfyUI and BFL.guidance_in. That result goes to the defaults and flow-shift lookups, after the file name and before the folder path and the base repo.3. Library listing and ComfyUI folders
.safetensorsand.ggufas its own entry.models/folder, scansdiffusion_models/,unet/andcheckpoints/.extra_model_paths.yamlexists, it is read too:base_path, multi-line path lists and relative paths are supported, and system folders are refused.text_encoders/,clip/andvae/folders are found as well, ready for split-layout loading in a follow-up.Testing
tests/test_comfy_file_detection.pyuses a compact fixture of real tensor names and shapes from 216 files, plus the diffusers layouts. It covers:tests/test_comfy_scan_folders.pycovers multi-file listing on both listing routes, picking one file of many, ComfyUI root andmodels/discovery, andextra_model_paths.yaml.I ran 106 related backend suites on both base and head. Both fail the same 15 test IDs, which already fail on this host. Nothing new fails.
GPU smoke test:
opaque_dit_v3.safetensorsresolves toz-imagefrom its header, loads in 69 s and renders a correct image. On base it is refused as an unsupported model.qwen_image_vae.safetensorspicked as the model is refused as a VAE, and no weights are opened. On base it passes validation as Qwen-Image.Review follow-ups: a FLUX.1 dev GGUF on the schnell fallback base keeps its own weights; the OpenAI-compatible images endpoint takes defaults from the file name and header too; two files in one folder are told apart when deciding whether the loaded model already serves a request; the listing skips files the loader refuses (a Wan2.2 A14B single expert, a renamed MiniMax-H3 file, a symlink resolving outside its folder) and DiTs the header recognises as unsupported (FLUX Fill) are refused whatever their name.
Not covered
models/. A single file under a plain nested scan folder is not listed.extra_model_paths.yamlwere not tested.Screenshots
Base
e4911f5c2(left) vs this PR (right), each from its own fresh Studio install. The same ComfyUI root is registered as a scan folder on both sides; itsdiffusion_models/holds two DiTs, one DiT renamed tomy_renamed_model, and a text encoder, with a VAE invae/.On device list: nothing is listed before. After, exactly the three DiTs are listed (the renamed one too, from its header), and the text encoder and VAE are not.
Add folder dialog: the new hint line about ComfyUI folders and
extra_model_paths.yaml.