(self, model, lora_name, strength_model)
| 166 | FUNCTION = "load_lora_model_only" |
| 167 | |
| 168 | def load_lora(self, model, lora_name, strength_model): |
| 169 | quant_fn = hadamard_transform |
| 170 | transformer = model.get_model_object("diffusion_model") |
| 171 | |
| 172 | is_patched_transformer = getattr(transformer, "is_q8_patched", False) |
| 173 | if not is_patched_transformer or not Q8_AVAILABLE: |
| 174 | raise ValueError( |
| 175 | "LTXV Q8 Patcher is not applied to the model. Please use LTXQ8Patch node before loading lora or install q8_kernels." |
| 176 | ) |
| 177 | |
| 178 | if strength_model == 0: |
| 179 | return model |
| 180 | quantize_self_attn, quantize_cross_attn, quantize_ffn = getattr( |
| 181 | transformer, "quantization_config" |
| 182 | ) |
| 183 | skip_list = [] |
| 184 | if not quantize_self_attn: |
| 185 | skip_list += ["attn1"] |
| 186 | if not quantize_cross_attn: |
| 187 | skip_list += ["attn2"] |
| 188 | if not quantize_ffn: |
| 189 | skip_list += ["ff"] |
| 190 | lora_path = folder_paths.get_full_path_or_raise("loras", lora_name) |
| 191 | lora = comfy.utils.load_torch_file(lora_path, safe_load=True) |
| 192 | new_lora = {} |
| 193 | for k in lora: |
| 194 | device = lora[k].device |
| 195 | if lora[k].ndim == 2: |
| 196 | if "lora_A" in k and not list_in_name(skip_list, k): |
| 197 | new_lora[k] = quant_fn( |
| 198 | lora[k].to(device="cuda", dtype=torch.bfloat16), |
| 199 | out_type=torch.bfloat16, |
| 200 | ).to(device) |
| 201 | else: |
| 202 | new_lora[k] = lora[k] |
| 203 | else: |
| 204 | new_lora[k] = lora[k] |
| 205 | self.loaded_lora = (lora_path, new_lora) |
| 206 | |
| 207 | model_lora, _ = comfy.sd.load_lora_for_models( |
| 208 | model, None, new_lora, strength_model, 0 |
| 209 | ) |
| 210 | return model_lora |
| 211 | |
| 212 | def load_lora_model_only(self, model, lora_name, strength_model): |
| 213 | return (self.load_lora(model, lora_name, strength_model),) |
no test coverage detected