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

v21.5.5 #652

Merged
merged 15 commits into from
Apr 23, 2023
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,23 @@ If you are using the interactive mode, our default values for the accelerate con
These are the same answers as the Windows install.

### Windows

- Install [Python 3.10](https://www.python.org/ftp/python/3.10.9/python-3.10.9-amd64.exe)
- make sure to tick the box to add Python to the 'PATH' environment variable
- Install [Git](https://git-scm.com/download/win)
- Install [Visual Studio 2015, 2017, 2019, and 2022 redistributable](https://aka.ms/vs/17/release/vc_redist.x64.exe)

In the terminal, run:

```
git clone https://github.com/bmaltais/kohya_ss.git
cd kohya_ss
setup.bat
.\setup.bat
```

If this is a 1st install answer No when asked `Do you want to uninstall previous versions of torch and associated files before installing`.


Then configure accelerate with the same answers as in the MacOS instructions when prompted.

### Optional: CUDNN 8.6
Expand Down Expand Up @@ -296,6 +305,13 @@ This will store a backup file with your current locally installed pip packages a

## Change History

* 2023/04/22 (v21.5.5)
- Update LoRA merge GUI to support SD checkpoint merge and up to 4 LoRA merging
- Fixed `lora_interrogator.py` not working. Please refer to [PR #392](https://github.com/kohya-ss/sd-scripts/pull/392) for details. Thank you A2va and heyalexchoi!
- Fixed the handling of tags containing `_` in `tag_images_by_wd14_tagger.py`.
- Add new Extract DyLoRA gui to the Utilities tab.
- Add new Merge LyCORIS models into checkpoint gui to the Utilities tab.
- Add new info on startup to help debug things
* 2023/04/17 (v21.5.4)
- Fixed a bug that caused an error when loading DyLoRA with the `--network_weight` option in `train_network.py`.
- Added the `--recursive` option to each script in the `finetune` folder to process folders recursively. Please refer to [PR #400](https://github.com/kohya-ss/sd-scripts/pull/400/) for details. Thanks to Linaqruf!
Expand Down
14 changes: 8 additions & 6 deletions finetune/tag_images_by_wd14_tagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,19 @@ def run_batch(path_imgs):
character_tag_text = ""
for i, p in enumerate(prob[4:]):
if i < len(general_tags) and p >= args.general_threshold:
tag_name = general_tags[i].replace("_", " ") if args.remove_underscore else general_tags[i]
tag_name = general_tags[i]
if args.remove_underscore and len(tag_name) > 3: # ignore emoji tags like >_< and ^_^
tag_name = tag_name.replace("_", " ")

if tag_name not in undesired_tags:
tag_freq[tag_name] = tag_freq.get(tag_name, 0) + 1
general_tag_text += ", " + tag_name
combined_tags.append(tag_name)
elif i >= len(general_tags) and p >= args.character_threshold:
tag_name = (
character_tags[i - len(general_tags)].replace("_", " ")
if args.remove_underscore
else character_tags[i - len(general_tags)]
)
tag_name = character_tags[i - len(general_tags)]
if args.remove_underscore and len(tag_name) > 3:
tag_name = tag_name.replace("_", " ")

if tag_name not in undesired_tags:
tag_freq[tag_name] = tag_freq.get(tag_name, 0) + 1
character_tag_text += ", " + tag_name
Expand Down
3 changes: 3 additions & 0 deletions gui.bat
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
call .\venv\Scripts\activate.bat
set PATH=%PATH%;%~dp0venv\Lib\site-packages\torch\lib

:: Debug info about system
python.exe .\tools\debug_info.py

:: Validate the requirements and store the exit code
python.exe .\tools\validate_requirements.py

Expand Down
3 changes: 3 additions & 0 deletions gui.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
& .\venv\Scripts\activate
$env:PATH += ";$($MyInvocation.MyCommand.Path)\venv\Lib\site-packages\torch\lib"

# Debug info about system
python.exe .\tools\debug_info.py

# Validate the requirements and store the exit code
python.exe .\tools\validate_requirements.py

Expand Down
4 changes: 4 additions & 0 deletions kohya_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from library.extract_lycoris_locon_gui import gradio_extract_lycoris_locon_tab
from library.merge_lora_gui import gradio_merge_lora_tab
from library.resize_lora_gui import gradio_resize_lora_tab
from library.extract_lora_from_dylora_gui import gradio_extract_dylora_tab
from library.merge_lycoris_gui import gradio_merge_lycoris_tab
from lora_gui import lora_tab


Expand Down Expand Up @@ -44,9 +46,11 @@ def UI(**kwargs):
logging_dir_input=logging_dir_input,
enable_copy_info_button=True,
)
gradio_extract_dylora_tab()
gradio_extract_lora_tab()
gradio_extract_lycoris_locon_tab()
gradio_merge_lora_tab()
gradio_merge_lycoris_tab()
gradio_resize_lora_tab()

# Show the interface
Expand Down
111 changes: 111 additions & 0 deletions library/extract_lora_from_dylora_gui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import gradio as gr
from easygui import msgbox
import subprocess
import os
from .common_gui import (
get_saveasfilename_path,
get_file_path,
)

folder_symbol = '\U0001f4c2' # 📂
refresh_symbol = '\U0001f504' # 🔄
save_style_symbol = '\U0001f4be' # 💾
document_symbol = '\U0001F4C4' # 📄
PYTHON = 'python3' if os.name == 'posix' else './venv/Scripts/python.exe'


def extract_dylora(
model,
save_to,
unit,
):
# Check for caption_text_input
if model == '':
msgbox('Invalid DyLoRA model file')
return

# Check if source model exist
if not os.path.isfile(model):
msgbox('The provided DyLoRA model is not a file')
return

run_cmd = (
f'{PYTHON} "{os.path.join("networks","extract_lora_from_dylora.py")}"'
)
run_cmd += f' --save_to "{save_to}"'
run_cmd += f' --model "{model}"'
run_cmd += f' --unit {unit}'

print(run_cmd)

# Run the command
if os.name == 'posix':
os.system(run_cmd)
else:
subprocess.run(run_cmd)

print('Done extracting DyLoRA...')

###
# Gradio UI
###


def gradio_extract_dylora_tab():
with gr.Tab('Extract DyLoRA'):
gr.Markdown(
'This utility can extract a LoRA network from a finetuned model.'
)
lora_ext = gr.Textbox(value='*.safetensors *.pt', visible=False)
lora_ext_name = gr.Textbox(value='LoRA model types', visible=False)

with gr.Row():
model = gr.Textbox(
label='DyLoRA model',
placeholder='Path to the DyLoRA model to extract from',
interactive=True,
)
button_model_file = gr.Button(
folder_symbol, elem_id='open_folder_small'
)
button_model_file.click(
get_file_path,
inputs=[model, lora_ext, lora_ext_name],
outputs=model,
show_progress=False,
)

save_to = gr.Textbox(
label='Save to',
placeholder='path where to save the extracted LoRA model...',
interactive=True,
)
button_save_to = gr.Button(
folder_symbol, elem_id='open_folder_small'
)
button_save_to.click(
get_saveasfilename_path,
inputs=[save_to, lora_ext, lora_ext_name],
outputs=save_to,
show_progress=False,
)
unit = gr.Slider(
minimum=1,
maximum=256,
label='Network Dimension (Rank)',
value=1,
step=1,
interactive=True,
)

extract_button = gr.Button('Extract LoRA model')

extract_button.click(
extract_dylora,
inputs=[
model,
save_to,
unit,
],
show_progress=False,
)
Loading