Upload folder using huggingface_hub
Browse files- .gitattributes +2 -0
- README.md +91 -0
- README_from_modelscope.md +119 -0
- assets/image_1.jpg +0 -0
- assets/image_1_origin.jpg +3 -0
- assets/image_2.jpg +0 -0
- assets/image_2_origin.jpg +3 -0
- assets/image_3.jpg +0 -0
- assets/image_3_scale.jpg +0 -0
- configuration.json +1 -0
- model.safetensors +3 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
assets/image_1_origin.jpg filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
assets/image_2_origin.jpg filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
---
|
| 4 |
+
# LoRA Encoder (FLUX.1-Dev)
|
| 5 |
+
|
| 6 |
+
This model encodes LoRA models for FLUX into embedding vectors, unlocking the capabilities of the LoRA models.
|
| 7 |
+
|
| 8 |
+
Taking the LoRA model [VoidOc/F.1_Animal_Forest_LoRA](https://www.modelscope.cn/models/VoidOc/flux_animal_forest1) as an example, the LoRA encoder can be used in the following ways.
|
| 9 |
+
|
| 10 |
+
## Method 1: LoRA Usage Inference
|
| 11 |
+
|
| 12 |
+
Given a LoRA model, with no additional information and using an empty prompt, the LoRA encoder can directly activate the LoRA's capabilities, allowing inference of its intended use.
|
| 13 |
+
|
| 14 |
+
Prompt: `""`
|
| 15 |
+
|
| 16 |
+
|Without LoRA Encoder|With LoRA Encoder|
|
| 17 |
+
|-|-|
|
| 18 |
+
|||
|
| 19 |
+
|
| 20 |
+
## Method 2: Trigger-Free Activation of LoRA Capabilities
|
| 21 |
+
|
| 22 |
+
Activate the LoRA's capabilities automatically without needing to specify any trigger words.
|
| 23 |
+
|
| 24 |
+
Prompt: `"a car"`
|
| 25 |
+
|
| 26 |
+
|Without LoRA Encoder|With LoRA Encoder|
|
| 27 |
+
|-|-|
|
| 28 |
+
|||
|
| 29 |
+
|
| 30 |
+
## Method 3: LoRA Strength Control
|
| 31 |
+
|
| 32 |
+
An additional parameter `scale` is provided to control the influence of the LoRA on the generated image.
|
| 33 |
+
|
| 34 |
+
In the example below, the prompt is `"a cat"`. When `scale=1`, the LoRA exerts maximum influence, resulting in an image showing both a character from Animal Crossing and a cat. When `scale=0.5`, the LoRA's influence is reduced, producing an image of a cat character from Animal Crossing. The optimal `scale` value depends on the specific LoRA model; we recommend using larger values for character-based LoRAs and smaller values for style-based LoRAs.
|
| 35 |
+
|
| 36 |
+
Prompt: `"a cat"`
|
| 37 |
+
|
| 38 |
+
|`scale=1`|`scale=0.5`|
|
| 39 |
+
|-|-|
|
| 40 |
+
|||
|
| 41 |
+
|
| 42 |
+
## Inference Code
|
| 43 |
+
|
| 44 |
+
```
|
| 45 |
+
git clone https://github.com/modelscope/DiffSynth-Studio.git
|
| 46 |
+
cd DiffSynth-Studio
|
| 47 |
+
pip install -e .
|
| 48 |
+
```
|
| 49 |
+
|
| 50 |
+
```python
|
| 51 |
+
import torch
|
| 52 |
+
from diffsynth.pipelines.flux_image_new import FluxImagePipeline, ModelConfig
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
pipe = FluxImagePipeline.from_pretrained(
|
| 56 |
+
torch_dtype=torch.bfloat16,
|
| 57 |
+
device="cuda",
|
| 58 |
+
model_configs=[
|
| 59 |
+
ModelConfig(model_id="black-forest-labs/FLUX.1-dev", origin_file_pattern="flux1-dev.safetensors"),
|
| 60 |
+
ModelConfig(model_id="black-forest-labs/FLUX.1-dev", origin_file_pattern="text_encoder/model.safetensors"),
|
| 61 |
+
ModelConfig(model_id="black-forest-labs/FLUX.1-dev", origin_file_pattern="text_encoder_2/"),
|
| 62 |
+
ModelConfig(model_id="black-forest-labs/FLUX.1-dev", origin_file_pattern="ae.safetensors"),
|
| 63 |
+
ModelConfig(model_id="DiffSynth-Studio/LoRA-Encoder-FLUX.1-Dev", origin_file_pattern="model.safetensors"),
|
| 64 |
+
],
|
| 65 |
+
)
|
| 66 |
+
pipe.enable_lora_magic()
|
| 67 |
+
|
| 68 |
+
lora = ModelConfig(model_id="VoidOc/flux_animal_forest1", origin_file_pattern="20.safetensors")
|
| 69 |
+
pipe.load_lora(pipe.dit, lora, hotload=True) # Use `pipe.clear_lora()` to drop the loaded LoRA.
|
| 70 |
+
|
| 71 |
+
# Empty prompt can automatically activate LoRA capabilities.
|
| 72 |
+
image = pipe(prompt="", seed=0, lora_encoder_inputs=lora)
|
| 73 |
+
image.save("image_1.jpg")
|
| 74 |
+
|
| 75 |
+
image = pipe(prompt="", seed=0)
|
| 76 |
+
image.save("image_1_origin.jpg")
|
| 77 |
+
|
| 78 |
+
# Prompt without trigger words can also activate LoRA capabilities.
|
| 79 |
+
image = pipe(prompt="a car", seed=0, lora_encoder_inputs=lora)
|
| 80 |
+
image.save("image_2.jpg")
|
| 81 |
+
|
| 82 |
+
image = pipe(prompt="a car", seed=0)
|
| 83 |
+
image.save("image_2_origin.jpg")
|
| 84 |
+
|
| 85 |
+
# Adjust the activation intensity through the scale parameter.
|
| 86 |
+
image = pipe(prompt="a cat", seed=0, lora_encoder_inputs=lora, lora_encoder_scale=1.0)
|
| 87 |
+
image.save("image_3.jpg")
|
| 88 |
+
|
| 89 |
+
image = pipe(prompt="a cat", seed=0, lora_encoder_inputs=lora, lora_encoder_scale=0.5)
|
| 90 |
+
image.save("image_3_scale.jpg")
|
| 91 |
+
```
|
README_from_modelscope.md
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
frameworks:
|
| 3 |
+
- Pytorch
|
| 4 |
+
license: Apache License 2.0
|
| 5 |
+
tasks:
|
| 6 |
+
- text-to-image-synthesis
|
| 7 |
+
|
| 8 |
+
#model-type:
|
| 9 |
+
##如 gpt、phi、llama、chatglm、baichuan 等
|
| 10 |
+
#- gpt
|
| 11 |
+
|
| 12 |
+
#domain:
|
| 13 |
+
##如 nlp、cv、audio、multi-modal
|
| 14 |
+
#- nlp
|
| 15 |
+
|
| 16 |
+
#language:
|
| 17 |
+
##语言代码列表 https://help.aliyun.com/document_detail/215387.html?spm=a2c4g.11186623.0.0.9f8d7467kni6Aa
|
| 18 |
+
#- cn
|
| 19 |
+
|
| 20 |
+
#metrics:
|
| 21 |
+
##如 CIDEr、Blue、ROUGE 等
|
| 22 |
+
#- CIDEr
|
| 23 |
+
|
| 24 |
+
#tags:
|
| 25 |
+
##各种自定义,包括 pretrained、fine-tuned、instruction-tuned、RL-tuned 等训练方法和其他
|
| 26 |
+
#- pretrained
|
| 27 |
+
|
| 28 |
+
#tools:
|
| 29 |
+
##如 vllm、fastchat、llamacpp、AdaSeq 等
|
| 30 |
+
#- vllm
|
| 31 |
+
---
|
| 32 |
+
# LoRA 编码器(FLUX.1-Dev)
|
| 33 |
+
|
| 34 |
+
本模型可以将 FLUX 模型的 LoRA 模型编码为 Embedding 向量,激发出 LoRA 模型的能力。
|
| 35 |
+
|
| 36 |
+
以 LoRA 模型 [VoidOc/F.1_动物森友会LoRA](https://www.modelscope.cn/models/VoidOc/flux_animal_forest1) 为例,LoRA 编码器有以下几种使用方法。
|
| 37 |
+
|
| 38 |
+
## 使用方法1:LoRA 用途推断
|
| 39 |
+
|
| 40 |
+
给定一个 LoRA 模型,在没有任何额外信息的条件下,使用空提示词可以直接激发 LoRA 模型的能力,进而推断出 LoRA 的用途。
|
| 41 |
+
|
| 42 |
+
提示词:`""`
|
| 43 |
+
|
| 44 |
+
|不使用 LoRA 编码器|使用 LoRA 编码器|
|
| 45 |
+
|-|-|
|
| 46 |
+
|||
|
| 47 |
+
|
| 48 |
+
## 使用方法2:免触发词激发 LoRA 能力
|
| 49 |
+
|
| 50 |
+
无需填写触发词,即可自动激发 LoRA 的能力。
|
| 51 |
+
|
| 52 |
+
提示词:`"a car"`
|
| 53 |
+
|
| 54 |
+
|不使用 LoRA 编码器|使用 LoRA 编码器|
|
| 55 |
+
|-|-|
|
| 56 |
+
|||
|
| 57 |
+
|
| 58 |
+
## 使用方法3:LoRA 强度控制
|
| 59 |
+
|
| 60 |
+
我们预留了一个额外的参数 `scale`,控制 LoRA 对模型生成图像的影响大小。
|
| 61 |
+
|
| 62 |
+
在下面的例子中,提示词为“a cat”,当 `scale=1` 时,LoRA 强度为最大,画面中生成了动物森友会中的角色和一只猫;当 `scale=0.5` 时,LoRA 强度被减弱,画面中生成了动物森友会中的猫猫角色。`scale` 的最优数值与 LoRA 模型本身有关,我们建议在角色 LoRA 上使用较大的数值,在风格 LoRA 上使用较小的数值。
|
| 63 |
+
|
| 64 |
+
提示词:`"a cat"`
|
| 65 |
+
|
| 66 |
+
|`scale=1`|`scale=0.5`|
|
| 67 |
+
|-|-|
|
| 68 |
+
|||
|
| 69 |
+
|
| 70 |
+
## 推理代码
|
| 71 |
+
|
| 72 |
+
```
|
| 73 |
+
git clone https://github.com/modelscope/DiffSynth-Studio.git
|
| 74 |
+
cd DiffSynth-Studio
|
| 75 |
+
pip install -e .
|
| 76 |
+
```
|
| 77 |
+
|
| 78 |
+
```python
|
| 79 |
+
import torch
|
| 80 |
+
from diffsynth.pipelines.flux_image_new import FluxImagePipeline, ModelConfig
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
pipe = FluxImagePipeline.from_pretrained(
|
| 84 |
+
torch_dtype=torch.bfloat16,
|
| 85 |
+
device="cuda",
|
| 86 |
+
model_configs=[
|
| 87 |
+
ModelConfig(model_id="black-forest-labs/FLUX.1-dev", origin_file_pattern="flux1-dev.safetensors"),
|
| 88 |
+
ModelConfig(model_id="black-forest-labs/FLUX.1-dev", origin_file_pattern="text_encoder/model.safetensors"),
|
| 89 |
+
ModelConfig(model_id="black-forest-labs/FLUX.1-dev", origin_file_pattern="text_encoder_2/"),
|
| 90 |
+
ModelConfig(model_id="black-forest-labs/FLUX.1-dev", origin_file_pattern="ae.safetensors"),
|
| 91 |
+
ModelConfig(model_id="DiffSynth-Studio/LoRA-Encoder-FLUX.1-Dev", origin_file_pattern="model.safetensors"),
|
| 92 |
+
],
|
| 93 |
+
)
|
| 94 |
+
pipe.enable_lora_magic()
|
| 95 |
+
|
| 96 |
+
lora = ModelConfig(model_id="VoidOc/flux_animal_forest1", origin_file_pattern="20.safetensors")
|
| 97 |
+
pipe.load_lora(pipe.dit, lora, hotload=True) # Use `pipe.clear_lora()` to drop the loaded LoRA.
|
| 98 |
+
|
| 99 |
+
# Empty prompt can automatically activate LoRA capabilities.
|
| 100 |
+
image = pipe(prompt="", seed=0, lora_encoder_inputs=lora)
|
| 101 |
+
image.save("image_1.jpg")
|
| 102 |
+
|
| 103 |
+
image = pipe(prompt="", seed=0)
|
| 104 |
+
image.save("image_1_origin.jpg")
|
| 105 |
+
|
| 106 |
+
# Prompt without trigger words can also activate LoRA capabilities.
|
| 107 |
+
image = pipe(prompt="a car", seed=0, lora_encoder_inputs=lora)
|
| 108 |
+
image.save("image_2.jpg")
|
| 109 |
+
|
| 110 |
+
image = pipe(prompt="a car", seed=0,)
|
| 111 |
+
image.save("image_2_origin.jpg")
|
| 112 |
+
|
| 113 |
+
# Adjust the activation intensity through the scale parameter.
|
| 114 |
+
image = pipe(prompt="a cat", seed=0, lora_encoder_inputs=lora, lora_encoder_scale=1.0)
|
| 115 |
+
image.save("image_3.jpg")
|
| 116 |
+
|
| 117 |
+
image = pipe(prompt="a cat", seed=0, lora_encoder_inputs=lora, lora_encoder_scale=0.5)
|
| 118 |
+
image.save("image_3_scale.jpg")
|
| 119 |
+
```
|
assets/image_1.jpg
ADDED
|
assets/image_1_origin.jpg
ADDED
|
Git LFS Details
|
assets/image_2.jpg
ADDED
|
assets/image_2_origin.jpg
ADDED
|
Git LFS Details
|
assets/image_3.jpg
ADDED
|
assets/image_3_scale.jpg
ADDED
|
configuration.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"framework":"Pytorch","task":"text-to-image-synthesis"}
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a123efe19d4edcc50c38508148bd0e6af154d8358daeb33669e764730984b9f6
|
| 3 |
+
size 1402316728
|