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

Add setup script for ubuntu users #288

Merged
merged 16 commits into from
Mar 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README-ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ PowerShellを使う場合、venvを使えるようにするためには以下の
- 「Set-ExecutionPolicy Unrestricted」と入力し、Yと答えます。
- 管理者のPowerShellを閉じます。

## Ubuntu環境でのインストール

```
git clone https://github.com/kohya-ss/sd-scripts.git
cd sd-scripts
bash ubuntu_setup.sh
```

をコマンドプロンプトで実行し、tkをインストールし、accelerateの質問をWindowsと同じように答えます。

`./gui.sh`でGUIを実行します。

## Windows環境でのインストール

以下の例ではPyTorchは1.12.1/CUDA 11.6版をインストールします。CUDA 11.3版やPyTorch 1.13を使う場合は適宜書き換えください。
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ If you run on Linux and would like to use the GUI, there is now a port of it as

## Installation

### Ubuntu
In the terminal, run

```
git clone https://github.com/bmaltais/kohya_ss.git
cd kohya_ss
bash ubuntu_setup.sh
```

then configure accelerate with the same answers as in the Windows instructions when prompted.

### Windows

Give unrestricted script access to powershell so venv can work:

- Run PowerShell as an administrator
Expand Down
2 changes: 1 addition & 1 deletion dreambooth_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}')
Expand Down
11 changes: 6 additions & 5 deletions finetune_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
save_style_symbol = '\U0001f4be' # 💾
document_symbol = '\U0001F4C4' # 📄

PYTHON = "python3" if os.name == 'posix' else './venv/Scripts/python.exe'

def save_configuration(
save_as,
Expand Down Expand Up @@ -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"'
Expand All @@ -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}"'
Expand All @@ -334,7 +335,7 @@ def train_model(
print(run_cmd)

# Run the command
subprocess.run(run_cmd)
os.system(run_cmd)

image_num = len(
[
Expand Down Expand Up @@ -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}')
Expand Down
3 changes: 3 additions & 0 deletions gui.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
source venv/bin/activate
python kohya_gui.py
4 changes: 2 additions & 2 deletions library/basic_caption_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
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,
Expand Down Expand Up @@ -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 == '':
Expand Down
6 changes: 3 additions & 3 deletions library/blip_caption_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
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,
Expand Down Expand Up @@ -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}"'
Expand All @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions library/convert_model_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
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,
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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'
Expand Down
6 changes: 3 additions & 3 deletions library/extract_lora_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
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,
Expand Down Expand Up @@ -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}"'
Expand All @@ -54,7 +54,7 @@ def extract_lora(
print(run_cmd)

# Run the command
subprocess.run(run_cmd)
os.system(run_cmd)


###
Expand Down
4 changes: 2 additions & 2 deletions library/git_caption_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
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,
Expand All @@ -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_by_git.py"'
run_cmd = f'{PYTHON} "finetune/make_captions_by_git.py"'
if not model_id == '':
run_cmd += f' --model_id="{model_id}"'
run_cmd += f' --batch_size="{int(batch_size)}"'
Expand Down
6 changes: 3 additions & 3 deletions library/merge_lora_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
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,
Expand Down Expand Up @@ -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}"'
Expand All @@ -53,7 +53,7 @@ def merge_lora(
print(run_cmd)

# Run the command
subprocess.run(run_cmd)
os.system(run_cmd)


###
Expand Down
6 changes: 3 additions & 3 deletions library/resize_lora_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
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' # 💾
Expand All @@ -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}'
Expand All @@ -40,7 +40,7 @@ def resize_lora(
print(run_cmd)

# Run the command
subprocess.run(run_cmd)
os.system(run_cmd)


###
Expand Down
4 changes: 2 additions & 2 deletions library/tensorboard_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
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
Expand All @@ -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:
Expand Down
12 changes: 7 additions & 5 deletions library/verify_lora_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
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' # 💾
Expand All @@ -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
)
Expand Down
3 changes: 2 additions & 1 deletion library/wd14_caption_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
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):
Expand Down Expand Up @@ -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')

Expand Down
2 changes: 1 addition & 1 deletion lora_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}')
Expand Down
2 changes: 1 addition & 1 deletion textual_inversion_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}')
Expand Down
12 changes: 12 additions & 0 deletions ubuntu_setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
echo installing tk
sudo apt install python3-tk
python3 -m venv venv
source venv/bin/activate
pip install torch==1.12.1+cu116 torchvision==0.13.1+cu116 --extra-index-url https://download.pytorch.org/whl/cu116
pip install --use-pep517 --upgrade -r requirements.txt
pip install -U -I --no-deps https://github.com/C43H66N12O12S2/stable-diffusion-webui/releases/download/linux/xformers-0.0.14.dev0-cp310-cp310-linux_x86_64.whl

accelerate config

echo -e "setup finished! run \e[0;92m./gui.sh\e[0m to start"