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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: other
|
| 3 |
+
base_model: "stabilityai/stable-diffusion-3.5-medium"
|
| 4 |
+
tags:
|
| 5 |
+
- sd3
|
| 6 |
+
- sd3-diffusers
|
| 7 |
+
- text-to-image
|
| 8 |
+
- diffusers
|
| 9 |
+
- simpletuner
|
| 10 |
+
- not-for-all-audiences
|
| 11 |
+
- lora
|
| 12 |
+
- template:sd-lora
|
| 13 |
+
- lycoris
|
| 14 |
+
inference: true
|
| 15 |
+
widget:
|
| 16 |
+
- text: 'unconditional (blank prompt)'
|
| 17 |
+
parameters:
|
| 18 |
+
negative_prompt: 'blurry, cropped, ugly'
|
| 19 |
+
output:
|
| 20 |
+
url: ./assets/image_0_0.png
|
| 21 |
+
- text: 'a portrait of a nude emver1rev1 in a room sitting on a sofa with her legs spread wide.'
|
| 22 |
+
parameters:
|
| 23 |
+
negative_prompt: 'blurry, cropped, ugly'
|
| 24 |
+
output:
|
| 25 |
+
url: ./assets/image_1_0.png
|
| 26 |
+
---
|
| 27 |
+
|
| 28 |
+
# ematest
|
| 29 |
+
|
| 30 |
+
This is a LyCORIS adapter derived from [stabilityai/stable-diffusion-3.5-medium](https://huggingface.co/stabilityai/stable-diffusion-3.5-medium).
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
The main validation prompt used during training was:
|
| 34 |
+
```
|
| 35 |
+
a portrait of a nude emver1rev1 in a room sitting on a sofa with her legs spread wide.
|
| 36 |
+
```
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
## Validation settings
|
| 40 |
+
- CFG: `4.0`
|
| 41 |
+
- CFG Rescale: `0.0`
|
| 42 |
+
- Steps: `30`
|
| 43 |
+
- Sampler: `FlowMatchEulerDiscreteScheduler`
|
| 44 |
+
- Seed: `42`
|
| 45 |
+
- Resolution: `1024x1024`
|
| 46 |
+
- Skip-layer guidance:
|
| 47 |
+
skip_guidance_layers=[7, 8, 9],
|
| 48 |
+
|
| 49 |
+
Note: The validation settings are not necessarily the same as the [training settings](#training-settings).
|
| 50 |
+
|
| 51 |
+
You can find some example images in the following gallery:
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
<Gallery />
|
| 55 |
+
|
| 56 |
+
The text encoder **was not** trained.
|
| 57 |
+
You may reuse the base model text encoder for inference.
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
## Training settings
|
| 61 |
+
|
| 62 |
+
- Training epochs: 5
|
| 63 |
+
- Training steps: 100
|
| 64 |
+
- Learning rate: 1e-06
|
| 65 |
+
- Learning rate schedule: polynomial
|
| 66 |
+
- Warmup steps: 1084
|
| 67 |
+
- Max grad norm: 0.01
|
| 68 |
+
- Effective batch size: 6
|
| 69 |
+
- Micro-batch size: 6
|
| 70 |
+
- Gradient accumulation steps: 1
|
| 71 |
+
- Number of GPUs: 1
|
| 72 |
+
- Gradient checkpointing: True
|
| 73 |
+
- Prediction type: flow-matching (extra parameters=['flux_schedule_auto_shift', 'shift=0.0', 'flux_use_uniform_schedule'])
|
| 74 |
+
- Optimizer: adamw_bf16
|
| 75 |
+
- Trainable parameter precision: Pure BF16
|
| 76 |
+
- Caption dropout probability: 10.0%
|
| 77 |
+
|
| 78 |
+
### LyCORIS Config:
|
| 79 |
+
```json
|
| 80 |
+
{
|
| 81 |
+
"bypass_mode": true,
|
| 82 |
+
"algo": "lokr",
|
| 83 |
+
"multiplier": 1.0,
|
| 84 |
+
"full_matrix": true,
|
| 85 |
+
"linear_dim": 10000,
|
| 86 |
+
"linear_alpha": 1,
|
| 87 |
+
"factor": 4,
|
| 88 |
+
"apply_preset": {
|
| 89 |
+
"target_module": [
|
| 90 |
+
"Attention",
|
| 91 |
+
"FeedForward"
|
| 92 |
+
],
|
| 93 |
+
"module_algo_map": {
|
| 94 |
+
"FeedForward": {
|
| 95 |
+
"factor": 4
|
| 96 |
+
},
|
| 97 |
+
"Attention": {
|
| 98 |
+
"factor": 2
|
| 99 |
+
}
|
| 100 |
+
}
|
| 101 |
+
}
|
| 102 |
+
}
|
| 103 |
+
```
|
| 104 |
+
|
| 105 |
+
## Datasets
|
| 106 |
+
|
| 107 |
+
### emver1rev1
|
| 108 |
+
- Repeats: 0
|
| 109 |
+
- Total number of images: 102
|
| 110 |
+
- Total number of aspect buckets: 1
|
| 111 |
+
- Resolution: 1.0 megapixels
|
| 112 |
+
- Cropped: true
|
| 113 |
+
- Crop style: center
|
| 114 |
+
- Crop aspect: square
|
| 115 |
+
- Used for regularisation data: No
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
## Inference
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
```python
|
| 122 |
+
import torch
|
| 123 |
+
from diffusers import DiffusionPipeline
|
| 124 |
+
from lycoris import create_lycoris_from_weights
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
def download_adapter(repo_id: str):
|
| 128 |
+
import os
|
| 129 |
+
from huggingface_hub import hf_hub_download
|
| 130 |
+
adapter_filename = "pytorch_lora_weights.safetensors"
|
| 131 |
+
cache_dir = os.environ.get('HF_PATH', os.path.expanduser('~/.cache/huggingface/hub/models'))
|
| 132 |
+
cleaned_adapter_path = repo_id.replace("/", "_").replace("\\", "_").replace(":", "_")
|
| 133 |
+
path_to_adapter = os.path.join(cache_dir, cleaned_adapter_path)
|
| 134 |
+
path_to_adapter_file = os.path.join(path_to_adapter, adapter_filename)
|
| 135 |
+
os.makedirs(path_to_adapter, exist_ok=True)
|
| 136 |
+
hf_hub_download(
|
| 137 |
+
repo_id=repo_id, filename=adapter_filename, local_dir=path_to_adapter
|
| 138 |
+
)
|
| 139 |
+
|
| 140 |
+
return path_to_adapter_file
|
| 141 |
+
|
| 142 |
+
model_id = 'stabilityai/stable-diffusion-3.5-medium'
|
| 143 |
+
adapter_repo_id = 'alexnvo/ematest'
|
| 144 |
+
adapter_filename = 'pytorch_lora_weights.safetensors'
|
| 145 |
+
adapter_file_path = download_adapter(repo_id=adapter_repo_id)
|
| 146 |
+
pipeline = DiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.bfloat16) # loading directly in bf16
|
| 147 |
+
lora_scale = 1.0
|
| 148 |
+
wrapper, _ = create_lycoris_from_weights(lora_scale, adapter_file_path, pipeline.transformer)
|
| 149 |
+
wrapper.merge_to()
|
| 150 |
+
|
| 151 |
+
prompt = "a portrait of a nude emver1rev1 in a room sitting on a sofa with her legs spread wide."
|
| 152 |
+
negative_prompt = 'blurry, cropped, ugly'
|
| 153 |
+
|
| 154 |
+
## Optional: quantise the model to save on vram.
|
| 155 |
+
## Note: The model was quantised during training, and so it is recommended to do the same during inference time.
|
| 156 |
+
from optimum.quanto import quantize, freeze, qint8
|
| 157 |
+
quantize(pipeline.transformer, weights=qint8)
|
| 158 |
+
freeze(pipeline.transformer)
|
| 159 |
+
|
| 160 |
+
pipeline.to('cuda' if torch.cuda.is_available() else 'mps' if torch.backends.mps.is_available() else 'cpu') # the pipeline is already in its target precision level
|
| 161 |
+
image = pipeline(
|
| 162 |
+
prompt=prompt,
|
| 163 |
+
negative_prompt=negative_prompt,
|
| 164 |
+
num_inference_steps=30,
|
| 165 |
+
generator=torch.Generator(device='cuda' if torch.cuda.is_available() else 'mps' if torch.backends.mps.is_available() else 'cpu').manual_seed(42),
|
| 166 |
+
width=1024,
|
| 167 |
+
height=1024,
|
| 168 |
+
guidance_scale=4.0,
|
| 169 |
+
skip_guidance_layers=[7, 8, 9],
|
| 170 |
+
).images[0]
|
| 171 |
+
image.save("output.png", format="PNG")
|
| 172 |
+
```
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
## Exponential Moving Average (EMA)
|
| 177 |
+
|
| 178 |
+
SimpleTuner generates a safetensors variant of the EMA weights and a pt file.
|
| 179 |
+
|
| 180 |
+
The safetensors file is intended to be used for inference, and the pt file is for continuing finetuning.
|
| 181 |
+
|
| 182 |
+
The EMA model may provide a more well-rounded result, but typically will feel undertrained compared to the full model as it is a running decayed average of the model weights.
|
| 183 |
+
|