Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/cogkit/api/services/image_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,17 @@ def generate(
if model not in self._models:
raise ValueError(f"Model {model} not loaded")
width, height = list(map(int, size.split("x")))

# TODO: Refactor this to switch by LoRA endpoint API
if lora_path != self._current_lora[model]:
if lora_path is not None:
adapter_name = os.path.basename(lora_path)
_logger.info(f"Loading LORA weights from {adapter_name}")
_logger.info(
f"Loading LORA weights from {adapter_name} and unload previous weights {self._current_lora[model]}"
)
unload_lora_checkpoint(self._models[model])
load_lora_checkpoint(self._models[model], lora_path, lora_scale)
else:
_logger.info("Unloading LORA weights")
_logger.info(f"Unloading LORA weights {self._current_lora[model]}")
unload_lora_checkpoint(self._models[model])

self._current_lora[model] = lora_path
Expand Down
4 changes: 2 additions & 2 deletions src/cogkit/utils/lora.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ def load_lora_checkpoint(
lora_model_id_or_path: str,
lora_scale: float = 1.0,
) -> None:
pipeline.load_lora_weights(lora_model_id_or_path)
pipeline.fuse_lora(components=["transformer"], lora_scale=lora_scale)
pipeline.load_lora_weights(lora_model_id_or_path, lora_scale=lora_scale)
# pipeline.fuse_lora(components=["transformer"], lora_scale=lora_scale)


def unload_lora_checkpoint(
Expand Down