Skip to content

Replace CLIPType if with getattr #7589

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 18, 2025

Conversation

city96
Copy link
Contributor

@city96 city96 commented Apr 13, 2025

This is mostly a small change that replaces the long if statement with a getattr where the common name (e.g. "wan") gets mapped to the enum (CLIPType.WAN) in the clip loader nodes.

The main benefit of this is assuring that the common name actually matches the enum, so that downstream nodes don't need to keep their own mapping for custom clip loader nodes. (ref: city96/ComfyUI-GGUF#246 (comment))

Test for the current values in the single / dual clip loader node. Only odd one out is SDXL which doesn't have an enum and instead uses "stabe_diffusion". The logic in the single clip loader node already defaults to CLIPType.STABLE_DIFFUSION, so I just extended this to the dual clip loader as well.

test = lambda type: getattr(comfy.sd.CLIPType, type.upper(), comfy.sd.CLIPType.STABLE_DIFFUSION)

[test(x) for x in ["stable_diffusion", "stable_cascade", "sd3", "stable_audio", "mochi", "ltxv", "pixart", "cosmos", "lumina2", "wan"]]
# returns: [<CLIPType.STABLE_DIFFUSION: 1>, <CLIPType.STABLE_CASCADE: 2>, <CLIPType.SD3: 3>, <CLIPType.STABLE_AUDIO: 4>, <CLIPType.MOCHI: 7>, <CLIPType.LTXV: 8>, <CLIPType.PIXART: 10>, <CLIPType.COSMOS: 11>, <CLIPType.LUMINA2: 12>, <CLIPType.WAN: 13>]

[test(x) for x in ["sdxl", "sd3", "flux", "hunyuan_video"]]
# returns: [<CLIPType.STABLE_DIFFUSION: 1>, <CLIPType.SD3: 3>, <CLIPType.FLUX: 6>, <CLIPType.HUNYUAN_VIDEO: 9>]

@city96 city96 requested a review from comfyanonymous as a code owner April 13, 2025 20:33
@comfyanonymous comfyanonymous merged commit 2383a39 into comfyanonymous:master Apr 18, 2025
5 checks passed
@city96 city96 deleted the clip_name_getattr branch April 18, 2025 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants