A simple solution for Integrating Loras with the Standard Diffusion Automatic 1111 API
NOTE: If you're just getting familiar with Loras for Stable Diffusion, you might want to check out this post first: A Beginners Guide to Loras with Stable Diffusion. It covers the basic concepts, key features, and info to get started with using Loras effectively.
In a recent video tutorial, we showed how to get up and running quickly with an A1111 powered API, allowing you to use the A1111 UI to configure Stable Diffusion, but use RunPod's serverless infrastructure for delivering the API.
Tutorial here:
The Problem
A persistent issue occurred when developers attempted to load Lora in API mode. An unexpected message, "Skipping unknown extra network: lora," would appear when the server received HTTP requests.
It indicated that Lora wasn't properly registered, despite the fact that developers were using proper payloads and parameters to initiate the Lora model.
To replicate this issue, you would follow these steps:
Follow the steps in the above video
Download the Lora checkpoint files.
Place the Loras in /workspace/sd/stable-difffusion-webui/models/Lora
Verify the Loras work through A1111 Web UI
Verify the Loras did not work through the A1111 API
The error you'll see, "Skipping unknown extra network: lora", "Couldn't find Lora with name [name]"
The solution
The solution is to make as small modification to the webui.py file. If you're following along in the above video, follow all the steps, but once you're logged into the Pod while configuring A1111, just open the the webui.py file (located here: /workspace/sd/stable-diffusion-webui/webui.py)..
You'll need to copy the line modules.script_callbacks.before_ui_callback() into the api_only() method, specifically at line 190, as shown in this screenshot:
Implementing this minor modification ensures that Lora loads successfully when running the API mode.
Conclusion
In conclusion, yes, it's possible to get Loras working with A1111 API. The small modification outlined in this post ensures Lora's proper registration and smooth operation, making it possible for developers to leverage its functionalities seamlessly in their applications. 🙌
Comments