Skip to content

Commit 37e544c

Browse files
Extend docstring with an example
1 parent 62769f3 commit 37e544c

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/diffusers/loaders/lora_base.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,23 @@ def set_lora_device(self, adapter_names: List[str], device: Union[torch.device,
938938
can no longer be used for inference, as that would cause a device mismatch. Remember to set the device back to
939939
GPU before using those LoRA adapters for inference.
940940
941+
```python
942+
>>> pipe.load_lora_weights(<path-1>, adapter_name="adapter-1")
943+
>>> pipe.load_lora_weights(<path-1>, adapter_name="adapter-2")
944+
>>> pipe.set_adapters("adapter-1")
945+
>>> image_1 = pipe(**kwargs)
946+
>>> # switch to adapter-2, offload adapter-1
947+
>>> pipeline.set_lora_device(adapter_names=["adapter-1"], device="cpu")
948+
>>> pipeline.set_lora_device(adapter_names=["adapter-2"], device="cuda:0")
949+
>>> pipe.set_adapters("adapter-2")
950+
>>> image_2 = pipe(**kwargs)
951+
>>> # switch back to adapter-1, offload adapter-2
952+
>>> pipeline.set_lora_device(adapter_names=["adapter-2"], device="cpu")
953+
>>> pipeline.set_lora_device(adapter_names=["adapter-1"], device="cuda:0")
954+
>>> pipe.set_adapters("adapter-1")
955+
>>> ...
956+
```
957+
941958
Args:
942959
adapter_names (`List[str]`):
943960
List of adapters to send device to.

0 commit comments

Comments
 (0)