# HOWTO: Lora models with Stable Diffusion

### What is LoRA (Low-Rank Adaptation)?

**LoRA**, short for **Low-Rank Adaptation**, is a technique used to **fine-tune large AI models** (like language or vision models) **efficiently and with fewer resources**.

Instead of updating all the parameters in a massive pre-trained model—which is expensive and memory-intensive—LoRA freezes the original model and **adds small, trainable layers** (called *low-rank matrices*) to specific parts of the model (like attention layers). These additions learn the task-specific changes, allowing the core model to remain unchanged.

Using **LoRA models with Stable Diffusion** is a super popular way to customize the style, character, or theme of your image generations without retraining the whole model.

### How to Use LoRA in Apolo platform with Stable Diffusion

Prerequisites:

* Install Apolo cli using [this](https://docs.apolo.us/index/apolo-concepts-cli/installing) doc
* Clone [this](https://github.com/neuro-inc/sdnext) repo

#### Add secret value with personal Hugging Face Token&#x20;

```
apolo secret add HF_TOKEN <your_token>
```

**Run Stable Diffusion job, replacing the secret value, preset, and any other configuration**

```
apolo-flow run stablediffusion
```

**Download the model using SDnext interface**

Go to Models -> HuggingFace

<figure><img src="https://3047157843-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHrHaAllzFtm00AIJiO3p%2Fuploads%2FaAJJz30boIiTlalnZtFs%2Fimage.png?alt=media&#x26;token=113c1e4e-0608-419e-be74-6874dc9b56db" alt=""><figcaption><p>HuggingFace model download interface</p></figcaption></figure>

Generate the first image:

**Prompt:**

Ghibli style futuristic stormtrooper with glossy white armor and a sleek helmet, standing heroically on a lush alien planet, vibrant flowers blooming around, soft sunlight illuminating the scene, a gentle breeze rustling the leaves

<figure><img src="https://3047157843-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHrHaAllzFtm00AIJiO3p%2Fuploads%2Fbar2rCe78JSlHejtJrRu%2Fimage.png?alt=media&#x26;token=cbec17bd-6b47-4610-82d9-d60ff7a7dc51" alt=""><figcaption></figcaption></figure>

### Lora model

Let's find a trained model on Civit.ai, we need to filter model by our Stable Diffusion version.

<figure><img src="https://3047157843-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHrHaAllzFtm00AIJiO3p%2Fuploads%2FoUeo7ax4IkukEy7of91c%2Fimage.png?alt=media&#x26;token=1ecc24c7-1a29-4c20-a928-bd5dc3458d5d" alt=""><figcaption><p>Civit.AI search models interface</p></figcaption></figure>

Alternative can be HuggingFace search. (tags: Lora, Stable Diffusion, 3.5)

I will use "[studio-ghibli-style-lora](https://huggingface.co/alvarobartt/ghibli-characters-sd3.5-lora)" Lora model.

Now we need to copy our model into the /Lora directory of our storage volume

```
apolo cp -r studio-ghibli-style-lora.safetensors storage:sdnext/models/Lora/studio-ghibli-style-lora.safetensors
```

After Model Copying, and hitting the refresh button on the Lora tab, we should be able to see our model downloaded.

Click on your Networks -> Lora tab, hit refresh, and click on your Lora model, that will add Lora to youre prompt, and you will be able to generate images using it.

For example we generated ghibli-style stormtrooper.

<figure><img src="https://3047157843-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHrHaAllzFtm00AIJiO3p%2Fuploads%2FtOGdgljKIaCyWAaECigB%2Fimage.png?alt=media&#x26;token=1b3e9e79-0ea1-4820-97b2-e268e3668dd6" alt=""><figcaption><p>Ghibli style stormtrooper</p></figcaption></figure>

### References:

* [Apolo cli](https://docs.apolo.us/index/apolo-concepts-cli/installing)
* [SDnext repository](https://github.com/neuro-inc/sdnext)
* [Apolo secrets cli documentation](https://docs.apolo.us/index/apolo-cli/commands/secret)
* [Civit AI model storage](https://civitai.com/)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.apolo.us/index/examples-use-cases/image-and-video-processing/howto-lora-models-with-stable-diffusion.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
