| 198 | TITLE = "Unet Loader (GGUF/Advanced)" |
| 199 | |
| 200 | class CLIPLoaderGGUF: |
| 201 | @classmethod |
| 202 | def INPUT_TYPES(s): |
| 203 | base = nodes.CLIPLoader.INPUT_TYPES() |
| 204 | return { |
| 205 | "required": { |
| 206 | "clip_name": (s.get_filename_list(),), |
| 207 | "type": base["required"]["type"], |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | RETURN_TYPES = ("CLIP",) |
| 212 | FUNCTION = "load_clip" |
| 213 | CATEGORY = "bootleg" |
| 214 | TITLE = "CLIPLoader (GGUF)" |
| 215 | |
| 216 | @classmethod |
| 217 | def get_filename_list(s): |
| 218 | files = [] |
| 219 | files += folder_paths.get_filename_list("clip") |
| 220 | files += folder_paths.get_filename_list("clip_gguf") |
| 221 | return sorted(files) |
| 222 | |
| 223 | def load_data(self, ckpt_paths): |
| 224 | clip_data = [] |
| 225 | for p in ckpt_paths: |
| 226 | if p.endswith(".gguf"): |
| 227 | sd = gguf_clip_loader(p) |
| 228 | else: |
| 229 | sd = comfy.utils.load_torch_file(p, safe_load=True) |
| 230 | if "scaled_fp8" in sd: # NOTE: Scaled FP8 would require different custom ops, but only one can be active |
| 231 | raise NotImplementedError(f"Mixing scaled FP8 with GGUF is not supported! Use regular CLIP loader or switch model(s)\n({p})") |
| 232 | clip_data.append(sd) |
| 233 | return clip_data |
| 234 | |
| 235 | def load_patcher(self, clip_paths, clip_type, clip_data): |
| 236 | clip = comfy.sd.load_text_encoder_state_dicts( |
| 237 | clip_type = clip_type, |
| 238 | state_dicts = clip_data, |
| 239 | model_options = { |
| 240 | "custom_operations": GGMLOps, |
| 241 | "initial_device": comfy.model_management.text_encoder_offload_device() |
| 242 | }, |
| 243 | embedding_directory = folder_paths.get_folder_paths("embeddings"), |
| 244 | ) |
| 245 | clip.patcher = GGUFModelPatcher.clone(clip.patcher) |
| 246 | return clip |
| 247 | |
| 248 | def load_clip(self, clip_name, type="stable_diffusion"): |
| 249 | clip_path = folder_paths.get_full_path("clip", clip_name) |
| 250 | clip_type = getattr(comfy.sd.CLIPType, type.upper(), comfy.sd.CLIPType.STABLE_DIFFUSION) |
| 251 | return (self.load_patcher([clip_path], clip_type, self.load_data([clip_path])),) |
| 252 | |
| 253 | class DualCLIPLoaderGGUF(CLIPLoaderGGUF): |
| 254 | @classmethod |
nothing calls this directly
no outgoing calls
no test coverage detected