Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework LoRA section, fix incongruent package versions required by different samples #567

Merged
merged 19 commits into from
Jul 8, 2024

Conversation

yatarkan
Copy link
Contributor

@yatarkan yatarkan commented Jul 1, 2024

No description provided.

@yatarkan yatarkan changed the title Fix incongruent package versions required by different samples Rework LoRA section, fix incongruent package versions required by different samples Jul 2, 2024
@yatarkan yatarkan requested a review from Wovchena July 2, 2024 16:50
@@ -32,7 +32,7 @@ conda env config vars set LD_LIBRARY_PATH=$CONDA_PREFIX/lib:$LD_LIBRARY_PATH
git submodule update --init
# Reactivate Conda environment after installing dependencies and setting env vars
conda activate openvino_sd_cpp
python -m pip install -r requirements.txt
python -m pip install -r ../../requirements.txt
python -m pip install ../../../thirdparty/openvino_tokenizers/[transformers]
```
2. Download a huggingface SD v1.5 model like:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optimum-cli export openvino below is in [dreamlike-anime-1.0](https://huggingface.co/dreamlike-art/dreamlike-anime-1.0) section even though it they aren't related. Please rework this. I think you can move down as an example of

There are various LoRA models on https://civitai.com/tag/lora

[dreamlike-anime-1.0](https://huggingface.co/dreamlike-art/dreamlike-anime-1.0) section because it's described later.

Copy link
Contributor Author

@yatarkan yatarkan Jul 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

runwayml/stable-diffusion-v1-5 and dreamlike-art/dreamlike-anime-1.0 are Stable Diffusion models exported with optimum-cli, not the LoRA models. I suppose it is might be useful to show the user which example SD models he can download and export.
Reworked this section and made the messaging more clear


Refer to [python pipeline blog](https://blog.openvino.ai/blog-posts/enable-lora-weights-with-stable-diffusion-controlnet-pipeline).
The safetensor model is loaded via [safetensors.h](https://github.com/hsnyder/safetensors.h). The layer name and weight are modified with `Eigen` library and inserted into the SD models with `ov::pass::MatcherPass` in the file [common/diffusers/src/lora.cpp](https://github.com/openvinotoolkit/openvino.genai/blob/master/image_generation/common/diffusers/src/lora.cpp).
Low-Rank Adaptation(LoRA) is a novel technique introduced to deal with the problem of fine-tuning Diffusers and Large Language Models (LLMs). In the case of Stable Diffusion fine-tuning, LoRA can be applied to the cross-attention layers for the image representations with the latent described.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Low-Rank Adaptation(LoRA) is a novel technique introduced to deal with the problem of fine-tuning Diffusers and Large Language Models (LLMs). In the case of Stable Diffusion fine-tuning, LoRA can be applied to the cross-attention layers for the image representations with the latent described.
Low-Rank Adaptation(LoRA) is technique introduced to deal with the problem of fine-tuning Diffusers and Large Language Models (LLMs). In the case of Stable Diffusion fine-tuning, LoRA can be applied to the cross-attention layers for the image representations with the latent described.

it won't be novel after some time. Or maybe it's already not novel :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed


SD model [dreamlike-anime-1.0](https://huggingface.co/dreamlike-art/dreamlike-anime-1.0) and LoRA [soulcard model](https://civitai.com/models/67927?modelVersionId=72591) are tested in this pipeline.

There are various LoRA models on https://civitai.com/tag/lora and on HuggingFace, you can consider to choose your own LoRA model in safetensor format.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move that line to the LoRA Weights Format section. It's a natural question to ask to see examples of the weights with the described format. That would leave Using LoRA Weights section with just two sentences. And

SD model dreamlike-anime-1.0 and LoRA soulcard model are tested in this pipeline.

isn't informative. I suggest merging them and naming the merged section LoRA Weights

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, sections are merged

@@ -0,0 +1,5 @@
--extra-index-url https://download.pytorch.org/whl/cpu
torch==2.2.2+cpu; sys_platform != 'darwin'
torch==2.2.2; sys_platform == 'darwin'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, add a comment explaining the diff

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed


* Generate image without lora `./build/stable_diffusion -r`

![](./without_lora.bmp)

* Generate image with soulcard lora `./build/stable_diffusion -r`
* Generate image with soulcard lora `./build/stable_diffusion -r -l path/to/soulcard.safetensors`

![](./soulcard_lora.bmp)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While you are nearby, please replace is differ to differ below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed for both SD and LCM

@@ -2,3 +2,4 @@
optimum[openvino]==1.20.0
einops==0.8.0 # For Qwen
transformers_stream_generator==0.0.5 # For Qwen
-r ../image_generation/requirements.txt
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminder to inverse the dependency or introduce a common requirements.txt

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@yatarkan yatarkan requested a review from Wovchena July 5, 2024 09:38
@Wovchena Wovchena marked this pull request as ready for review July 8, 2024 07:44
@Wovchena Wovchena enabled auto-merge July 8, 2024 07:44
@Wovchena Wovchena disabled auto-merge July 8, 2024 07:45
torch==2.2.2+cpu; sys_platform != 'darwin'
torch==2.2.2; sys_platform == 'darwin' # Torch wheel for 2.2.2+cpu does not exist for macOS, using 2.2.2 instead
diffusers==0.27.2
optimum-intel[openvino]==1.18.0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
optimum-intel[openvino]==1.18.0

samples already have optimum[openvino]==1.20.0. That's strange that pip didn't detect a conflict

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From samples optimum-intel is installed with version >=1.16.0, so there is no conflict.
But I removed duplicated dependencies from image generation

@@ -0,0 +1,6 @@
--extra-index-url https://download.pytorch.org/whl/cpu
torch==2.2.2+cpu; sys_platform != 'darwin'
torch==2.2.2; sys_platform == 'darwin' # Torch wheel for 2.2.2+cpu does not exist for macOS, using 2.2.2 instead
Copy link
Collaborator

@Wovchena Wovchena Jul 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized. I'd expect torch to come with optimum. Can torch be removed? Maybe the same is applicable to diffusers

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicated dependencies removed keeping only diffusers in requirements

@yatarkan yatarkan requested a review from Wovchena July 8, 2024 11:42
@Wovchena Wovchena added this pull request to the merge queue Jul 8, 2024
github-merge-queue bot pushed a commit that referenced this pull request Jul 8, 2024
Merged via the queue into openvinotoolkit:master with commit a21ffbd Jul 8, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants