fix bugs that make some processes not work on linux

This commit is contained in:
devdn 2023-03-04 00:11:23 -05:00
parent 38bdcea3c5
commit bc45bd7e70
16 changed files with 42 additions and 52 deletions

View File

@ -456,7 +456,7 @@ def train_model(
print(run_cmd)
# Run the command
subprocess.run(run_cmd)
os.system(run_cmd)
# check if output_dir/last is a folder... therefore it is a diffuser model
last_dir = pathlib.Path(f'{output_dir}/{output_name}')

View File

@ -33,6 +33,7 @@ refresh_symbol = '\U0001f504' # 🔄
save_style_symbol = '\U0001f4be' # 💾
document_symbol = '\U0001F4C4' # 📄
PYTHON = "python3" if os.name == 'posix' else './venv/Scripts/python.exe'
def save_configuration(
save_as,
@ -296,7 +297,7 @@ def train_model(
os.mkdir(train_dir)
run_cmd = (
f'./venv/Scripts/python.exe finetune/merge_captions_to_metadata.py'
f'{PYTHON} finetune/merge_captions_to_metadata.py'
)
if caption_extension == '':
run_cmd += f' --caption_extension=".caption"'
@ -310,12 +311,12 @@ def train_model(
print(run_cmd)
# Run the command
subprocess.run(run_cmd)
os.system(run_cmd)
# create images buckets
if generate_image_buckets:
run_cmd = (
f'./venv/Scripts/python.exe finetune/prepare_buckets_latents.py'
f'{PYTHON} finetune/prepare_buckets_latents.py'
)
run_cmd += f' "{image_folder}"'
run_cmd += f' "{train_dir}/{caption_metadata_filename}"'
@ -334,7 +335,7 @@ def train_model(
print(run_cmd)
# Run the command
subprocess.run(run_cmd)
os.system(run_cmd)
image_num = len(
[
@ -444,7 +445,7 @@ def train_model(
print(run_cmd)
# Run the command
subprocess.run(run_cmd)
os.system(run_cmd)
# check if output_dir/last is a folder... therefore it is a diffuser model
last_dir = pathlib.Path(f'{output_dir}/{output_name}')

3
gui.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
source venv/bin/activate
python kohya_gui.py

View File

@ -2,7 +2,7 @@ import gradio as gr
from easygui import msgbox
import subprocess
from .common_gui import get_folder_path, add_pre_postfix, find_replace
import os
def caption_images(
caption_text_input,
@ -38,7 +38,7 @@ def caption_images(
print(run_cmd)
# Run the command
subprocess.run(run_cmd)
os.system(run_cmd)
if overwrite_input:
if not prefix == '' or not postfix == '':

View File

@ -3,7 +3,7 @@ from easygui import msgbox
import subprocess
import os
from .common_gui import get_folder_path, add_pre_postfix
PYTHON = "python3" if os.name == 'posix' else './venv/Scripts/python.exe'
def caption_images(
train_data_dir,
@ -32,7 +32,7 @@ def caption_images(
return
print(f'Captioning files in {train_data_dir}...')
run_cmd = f'.\\venv\\Scripts\\python.exe "finetune/make_captions.py"'
run_cmd = f'{PYTHON} "finetune/make_captions.py"'
run_cmd += f' --batch_size="{int(batch_size)}"'
run_cmd += f' --num_beams="{int(num_beams)}"'
run_cmd += f' --top_p="{top_p}"'
@ -48,7 +48,7 @@ def caption_images(
print(run_cmd)
# Run the command
subprocess.run(run_cmd)
os.system(run_cmd)
# Add prefix and postfix
add_pre_postfix(

View File

@ -9,7 +9,7 @@ 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 convert_model(
source_model_input,
@ -40,7 +40,7 @@ def convert_model(
msgbox('The provided target folder does not exist')
return
run_cmd = f'.\\venv\Scripts\python.exe "tools/convert_diffusers20_original_sd.py"'
run_cmd = f'{PYTHON} "tools/convert_diffusers20_original_sd.py"'
v1_models = [
'runwayml/stable-diffusion-v1-5',
@ -87,7 +87,7 @@ def convert_model(
print(run_cmd)
# Run the command
subprocess.run(run_cmd)
os.system(run_cmd)
if (
not target_model_type == 'diffuser'

View File

@ -12,7 +12,7 @@ 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_lora(
model_tuned,
@ -41,7 +41,7 @@ def extract_lora(
return
run_cmd = (
f'.\\venv\Scripts\python.exe "networks\extract_lora_from_models.py"'
f'{PYTHON} "{os.path.join("networks","extract_lora_from_models.py")}"'
)
run_cmd += f' --save_precision {save_precision}'
run_cmd += f' --save_to "{save_to}"'
@ -54,7 +54,7 @@ def extract_lora(
print(run_cmd)
# Run the command
subprocess.run(run_cmd)
os.system(run_cmd)
###

View File

@ -3,7 +3,7 @@ from easygui import msgbox
import subprocess
import os
from .common_gui import get_folder_path, add_pre_postfix
PYTHON = "python3" if os.name == 'posix' else './venv/Scripts/python.exe'
def caption_images(
train_data_dir,
@ -25,7 +25,7 @@ def caption_images(
return
print(f'GIT captioning files in {train_data_dir}...')
run_cmd = f'.\\venv\\Scripts\\python.exe "finetune/make_captions.py"'
run_cmd = f'{PYTHON} "finetune/make_captions.py"'
if not model_id == '':
run_cmd += f' --model_id="{model_id}"'
run_cmd += f' --batch_size="{int(batch_size)}"'

View File

@ -12,7 +12,7 @@ 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 merge_lora(
lora_a_model,
@ -43,7 +43,7 @@ def merge_lora(
ratio_a = ratio
ratio_b = 1 - ratio
run_cmd = f'.\\venv\Scripts\python.exe "networks\merge_lora.py"'
run_cmd = f'{PYTHON} "{os.path.join("networks","merge_lora.py")}"'
run_cmd += f' --save_precision {save_precision}'
run_cmd += f' --precision {precision}'
run_cmd += f' --save_to "{save_to}"'
@ -53,7 +53,7 @@ def merge_lora(
print(run_cmd)
# Run the command
subprocess.run(run_cmd)
os.system(run_cmd)
###

View File

@ -3,7 +3,7 @@ from easygui import msgbox
import subprocess
import os
from .common_gui import get_saveasfilename_path, get_file_path
PYTHON = "python3" if os.name == 'posix' else './venv/Scripts/python.exe'
folder_symbol = '\U0001f4c2' # 📂
refresh_symbol = '\U0001f504' # 🔄
save_style_symbol = '\U0001f4be' # 💾
@ -30,7 +30,7 @@ def resize_lora(
if device == '':
device = 'cuda'
run_cmd = f'.\\venv\Scripts\python.exe "networks\\resize_lora.py"'
run_cmd = f'{PYTHON} "{os.path.join("networks","resize_lora.py")}"'
run_cmd += f' --save_precision {save_precision}'
run_cmd += f' --save_to {save_to}'
run_cmd += f' --model {model}'
@ -40,7 +40,7 @@ def resize_lora(
print(run_cmd)
# Run the command
subprocess.run(run_cmd)
os.system(run_cmd)
###

View File

@ -5,7 +5,7 @@ import subprocess
import time
tensorboard_proc = None # I know... bad but heh
TENSORBOARD = "tensorboard" if os.name == 'posix' else 'tensorboard.exe'
def start_tensorboard(logging_dir):
global tensorboard_proc
@ -15,7 +15,7 @@ def start_tensorboard(logging_dir):
msgbox(msg='Error: log folder is empty')
return
run_cmd = f'tensorboard.exe --logdir "{logging_dir}"'
run_cmd = [f'{TENSORBOARD}', '--logdir', f'{logging_dir}']
print(run_cmd)
if tensorboard_proc is not None:

View File

@ -7,7 +7,7 @@ from .common_gui import (
get_any_file_path,
get_file_path,
)
PYTHON = "python3" if os.name == 'posix' else './venv/Scripts/python.exe'
folder_symbol = '\U0001f4c2' # 📂
refresh_symbol = '\U0001f504' # 🔄
save_style_symbol = '\U0001f4be' # 💾
@ -27,13 +27,15 @@ def verify_lora(
msgbox('The provided model A is not a file')
return
run_cmd = f'.\\venv\Scripts\python.exe "networks\check_lora_weights.py"'
run_cmd += f' {lora_model}'
run_cmd = [
PYTHON,
os.path.join("networks","check_lora_weights.py"),
f'{lora_model}'
]
print(run_cmd)
print(" ".join(run_cmd))
# Run the command
subprocess.run(run_cmd)
process = subprocess.Popen(
run_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE
)

View File

@ -2,6 +2,7 @@ import gradio as gr
from easygui import msgbox
import subprocess
from .common_gui import get_folder_path
import os
def caption_images(train_data_dir, caption_extension, batch_size, thresh):
@ -30,7 +31,7 @@ def caption_images(train_data_dir, caption_extension, batch_size, thresh):
print(run_cmd)
# Run the command
subprocess.run(run_cmd)
os.system(run_cmd)
print('...captioning done')

View File

@ -544,7 +544,7 @@ def train_model(
print(run_cmd)
# Run the command
subprocess.run(run_cmd)
os.system(run_cmd)
# check if output_dir/last is a folder... therefore it is a diffuser model
last_dir = pathlib.Path(f'{output_dir}/{output_name}')

View File

@ -498,7 +498,7 @@ def train_model(
print(run_cmd)
# Run the command
subprocess.run(run_cmd)
os.system(run_cmd)
# check if output_dir/last is a folder... therefore it is a diffuser model
last_dir = pathlib.Path(f'{output_dir}/{output_name}')

View File

@ -9,21 +9,4 @@ pip install -U -I --no-deps https://github.com/C43H66N12O12S2/stable-diffusion-w
accelerate config
rm *.bat
rm *.ps1
set +H
echo "#!/bin/bash" > gui.sh
echo "source venv/bin/activate" >> gui.sh
echo "python kohya_gui.py $@" >> gui.sh
chmod +x gui.sh
sources=$(find $(ls | grep -v venv) | egrep "\.py$")
for source in $sources
do
#fix accelerate commands
sed -i -r 's/(accelerate launch .*?)"(.+?\.py)"/\1\2/g' $source
sed -i -r 's/subprocess.run\(run_cmd\)/subprocess.run(run_cmd, shell=True)/g' $source
done
echo -e "setup finished! run \e[0;92m./gui.sh\e[0m to start"