Skip to content

Studio: recognise ComfyUI checkpoints by name and header, and list ComfyUI model folders - #12878

Merged
danielhanchen merged 11 commits into
mainfrom
studio/comfy-file-detect
Oct 7, 2026
Merged

danielhanchen merged 11 commits into
mainfrom
studio/comfy-file-detect

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

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_models folder showed only its GGUF files.

1. Family names ignore separators

  • Family names and aliases now match after lowercasing and treating _, -, . and spaces as the same separator. This applies on both the image and video pages, to family_override and to the default steps/guidance tables.
  • These ComfyUI spellings now resolve:
    • wan2.2_ti2v_5B_* and Wan2_2-TI2V-5B_*
    • wan2.2_t2v_*_14B_*
    • flux-2-klein-*
    • flux2_dev_fp8mixed
    • lumina_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.
  • Regression check: every family name and alias, plus the 216 sampled ComfyUI-ecosystem file names, keeps the family it had before. The only change is the Qwen-Image-2.1 fix above. The test compares against a copy of the old matcher.
216 audit file names before after
name matches a family (image or video) 120 151
changed to a different family - 5, all qwen_image_2.1_*, which was the intended fix
lost detection - 0

Some 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.py reads 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.

  • It recognises each supported DiT by its key and shape signature, in both the ComfyUI layout and the diffusers layout. This works with the file at the top level or under a container prefix such as model.diffusion_model., which covers all-in-one checkpoints.
  • It also identifies text encoders (CLIP, T5, LLM/VLM, GGUF LLMs), VAEs (including audio VAEs and vocoders), LoRAs and ControlNets.
  • When a local file is picked, its family comes from the header if the name is missing or wrong. A text encoder, VAE, LoRA or ControlNet is refused before any load with a message saying what the file is. A DiT picked on the wrong page is refused and the message names the right page.
  • The name still decides between variants that share an architecture. Keys cannot tell these apart:
    • FLUX.1 dev, Krea and Kontext
    • Qwen-Image, 2512, Edit and Edit-2509 (ComfyUI's Edit-2511 repack has a marker key, so it is recognised)
    • FLUX.2-klein distilled and base
    • Z-Image base and Turbo
    • HiDream full, dev and fast
    • LTX-2 and LTX-2.3
    • HunyuanVideo-1.5 at 480p and 720p
    • Wan2.2 A14B high-noise and low-noise experts (also Wan2.1 T2V-14B)
  • If the header shows no supported family, the name decides as before.
  • A name the variant guard refuses (for example ...-inpaint) stays refused.
  • Remote picks and family_override are unchanged.
  • Some architectures are recognised but not supported, for example Wan I2V, FLUX Fill and SD3. These count as DiTs without a family, so they are not listed and not loaded.

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* or flux1-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.

  • The default-settings table now has rows for the flux1-* file names used by ComfyUI and BFL.
  • For a renamed local file, the header decides: schnell is the only FLUX.1 without 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.
  • Dev, Krea-dev and Kontext have identical keys, so only the name can tell them apart. Their defaults and flow shift are the same anyway, except Kontext, which is matched by name.

3. Library listing and ComfyUI folders

  • A scanned folder lists every DiT-like .safetensors and .gguf as its own entry.
    • Text encoder, VAE, LoRA and ControlNet files are not offered.
    • A file whose header is not recognised is listed only if its name matches a family.
    • A folder holding exactly one checkpoint still lists as before.
  • Picking one file in a folder with many files loads that file.
  • Adding a ComfyUI root, or its models/ folder, scans diffusion_models/, unet/ and checkpoints/.
    • If extra_model_paths.yaml exists, it is read too: base_path, multi-line path lists and relative paths are supported, and system folders are refused.
    • The text_encoders/, clip/ and vae/ folders are found as well, ready for split-layout loading in a follow-up.
  • UI: the On-device locations dialog has one new hint line.

Testing

  • tests/test_comfy_file_detection.py uses a compact fixture of real tensor names and shapes from 216 files, plus the diffusers layouts. It covers:

    • name normalisation and the before/after regression;
    • classification of every file;
    • a renamed DiT resolving from its header;
    • a misnamed DiT following its header;
    • the name choosing between same-architecture variants;
    • text encoder, VAE, LoRA and ControlNet refusal;
    • GGUF files;
    • wrong-page refusal;
    • unreadable or unknown headers;
    • remote and override picks;
    • the header size limit and cache;
    • that the classifier does not import torch.
  • tests/test_comfy_scan_folders.py covers multi-file listing on both listing routes, picking one file of many, ComfyUI root and models/ discovery, and extra_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:

    • A ComfyUI Z-Image-Turbo int8_convrot DiT renamed to opaque_dit_v3.safetensors resolves to z-image from its header, loads in 69 s and renders a correct image. On base it is refused as an unsupported model.
    • qwen_image_vae.safetensors picked 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

  • HunyuanVideo-1.5 is listed as supporting single-file loads, but main has no single-file converter for it. That is handled separately and not changed here. The Krea-2 and HunyuanImage-2.1 single-file converters are also out of scope.
  • Loading text encoders and VAEs from a split ComfyUI layout. This PR only finds those folders.
  • Folders are discovered only for a registered scan folder that is a ComfyUI root or models/. A single file under a plain nested scan folder is not listed.
  • No end-to-end UI test of the new listing rows. No frontend unit tests cover this dialog.
  • Windows paths in extra_model_paths.yaml were 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; its diffusion_models/ holds two DiTs, one DiT renamed to my_renamed_model, and a text encoder, with a VAE in vae/.

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.

On device list, before and after

Add folder dialog: the new hint line about ComfyUI folders and extra_model_paths.yaml.

On-device locations dialog, before and after

…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.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-07T10:47:23.660846Z 131e2cd New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

danielhanchen and others added 2 commits October 6, 2026 10:45
…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.
@danielhanchen

Copy link
Copy Markdown
Member Author

The red Repo tests (CPU, rest) is from this PR: the test-tree encoding lint flags studio/backend/tests/test_comfy_file_detection.py:26, a read_text() on a checked-in file without encoding = "utf-8". Passing it clears the check.

Frontend build + bundle sanity (strict i18n check, fixed on main by #12881) and the Core zoo lanes (fixed by unslothai/unsloth-zoo#1598 and #1599) predate those fixes; a rebase or re-run clears them.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 7, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +1208 to +1212
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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +94 to +96
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 []

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 8caac96: TypeError joins the header parse failures, so a null dimension reads as unreadable.

Comment on lines +974 to +975
if not override:
fam = _family_from_content(fam, repo_id, gguf_filename)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +294 to +296
info = diffusion_content.inspect_checkpoint(str(path))
if info.role == diffusion_content.ROLE_DIT:
return bool(info.family)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Comment on lines +284 to +288
_register(
index,
keys,
MediaModelPick(keys[0], str(load_dir.parent), load_dir.name, "single_file"),
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 8caac96: a single_file pick is resident only when the published gguf_filename matches too.

Comment on lines 7162 to +7165
default_steps, _ = default_generation_params(
gguf_filename, repo_id, base, fam.name
gguf_filename,
content_variant_hint(repo_id, gguf_filename),
repo_id,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +621 to +622
if info.role != ROLE_DIT or not info.family:
return name_family, False

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 37bc0269a1

ℹ️ 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".

danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 7, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 7, 2026
@danielhanchen
danielhanchen merged commit d1a88d2 into main Oct 7, 2026
@danielhanchen
danielhanchen deleted the studio/comfy-file-detect branch October 7, 2026 11:55
danielhanchen added a commit that referenced this pull request Oct 7, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant