[diffusion] feat: support multiple LoRA adapters loading and application (#16667)

Co-authored-by: niehen6174 <niehen.6174@gmail.com>
Co-authored-by: Mick <mickjagger19@icloud.com>
This commit is contained in:
WenhaoZhang
2026-01-10 23:32:45 +08:00
committed by GitHub
parent 76d4881794
commit 5c72be1e51
10 changed files with 578 additions and 180 deletions

View File

@@ -4,7 +4,7 @@
import multiprocessing as mp
import os
import time
from typing import List
from typing import List, Union
import torch
from setproctitle import setproctitle
@@ -206,19 +206,20 @@ class GPUWorker:
def set_lora(
self,
lora_nickname: str,
lora_path: str | None = None,
target: str = "all",
strength: float = 1.0,
lora_nickname: Union[str, List[str]],
lora_path: Union[str, None, List[Union[str, None]]] = None,
target: Union[str, List[str]] = "all",
strength: Union[float, List[float]] = 1.0,
) -> OutputBatch:
"""
Set the LoRA adapter for the pipeline.
Set the LoRA adapter(s) for the pipeline.
Supports both single LoRA (backward compatible) and multiple LoRA adapters.
Args:
lora_nickname: The nickname of the adapter.
lora_path: Path to the LoRA adapter.
target: Which transformer(s) to apply the LoRA to.
strength: LoRA strength for merge, default 1.0.
lora_nickname: The nickname(s) of the adapter(s). Can be a string or a list of strings.
lora_path: Path(s) to the LoRA adapter(s). Can be a string, None, or a list of strings/None.
target: Which transformer(s) to apply the LoRA to. Can be a string or a list of strings.
strength: LoRA strength(s) for merge, default 1.0. Can be a float or a list of floats.
"""
if not isinstance(self.pipeline, LoRAPipeline):
return OutputBatch(error="Lora is not enabled")