MCPcopy Index your code
hub / github.com/NVIDIA/Stable-Diffusion-WebUI-TensorRT / get_loras

Method get_loras

scripts/trt.py:198–240  ·  view source on GitHub ↗
(self, p)

Source from the content-addressed store, hash-verified

196 return best, best_hr
197
198 def get_loras(self, p):
199 lora_pathes = []
200 lora_scales = []
201
202 # get lora from prompt
203 _prompt = p.prompt
204 extra_networks = re.findall("\<(.*?)\>", _prompt)
205 loras = [net for net in extra_networks if net.startswith("lora")]
206
207 # Avoid that extra networks will be loaded
208 for lora in loras:
209 _prompt = _prompt.replace(f"<{lora}>", "")
210 p.prompt = _prompt
211
212 # check if lora config has changes
213 if self.lora_hash != "".join(loras):
214 self.lora_hash = "".join(loras)
215 self.update_lora = True
216 if self.lora_hash == "":
217 self.lora_refit_dict = {}
218 return
219 else:
220 return
221
222 # Get pathes
223 print("Apllying LoRAs: " + str(loras))
224 available = modelmanager.available_loras()
225 for lora in loras:
226 lora_name, lora_scale = lora.split(":")[1:]
227 lora_scales.append(float(lora_scale))
228 if lora_name not in available:
229 raise Exception(
230 f"Please export the LoRA checkpoint {lora_name} first from the TensorRT LoRA tab"
231 )
232 lora_pathes.append(
233 available[lora_name]
234 )
235
236 # Merge lora refit dicts
237 base_name, base_path = modelmanager.get_onnx_path(p.sd_model_name)
238 refit_dict = apply_loras(base_path, lora_pathes, lora_scales)
239
240 self.lora_refit_dict = refit_dict
241
242 def process(self, p, *args):
243 # before unet_init

Callers 1

processMethod · 0.95

Calls 3

apply_lorasFunction · 0.90
available_lorasMethod · 0.80
get_onnx_pathMethod · 0.80

Tested by

no test coverage detected