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

v23.0.6 #2074

Merged
merged 3 commits into from
Mar 12, 2024
Merged

v23.0.6 #2074

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
2 changes: 1 addition & 1 deletion .release
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v23.0.5
v23.0.6
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ The GUI allows you to set the training parameters and generate and run the requi
- [No module called tkinter](#no-module-called-tkinter)
- [SDXL training](#sdxl-training)
- [Change History](#change-history)
- [2024/03/11 (v23.0.6)](#20240311-v2306)
- [2024/03/11 (v23.0.5)](#20240311-v2305)
- [2024/03/10 (v23.0.4)](#20240310-v2304)
- [2024/03/10 (v23.0.3)](#20240310-v2303)
- [2024/03/10 (v23.0.2)](#20240310-v2302)
Expand Down Expand Up @@ -363,6 +365,10 @@ The documentation in this section will be moved to a separate document later.

## Change History

### 2024/03/11 (v23.0.6)

- Fix issue with PYTHON path that have "spaces" in them

### 2024/03/11 (v23.0.5)

- Update python module verification
Expand Down
2 changes: 1 addition & 1 deletion kohya_gui/basic_caption_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def caption_images(
log.info(f'Captioning files in {images_dir} with {caption_text}...')

# Build the command to run caption.py
run_cmd = fr'{PYTHON} "{scriptdir}/tools/caption.py"'
run_cmd = fr'"{PYTHON}" "{scriptdir}/tools/caption.py"'
run_cmd += f' --caption_text="{caption_text}"'

# Add optional flags to the command
Expand Down
2 changes: 1 addition & 1 deletion kohya_gui/blip_caption_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def caption_images(
log.info(f"Captioning files in {train_data_dir}...")

# Construct the command to run
run_cmd = rf'{PYTHON} "{scriptdir}/sd-scripts/finetune/make_captions.py"'
run_cmd = rf'"{PYTHON}" "{scriptdir}/sd-scripts/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 Down
2 changes: 1 addition & 1 deletion kohya_gui/convert_lcm_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def convert_lcm(
lora_scale,
model_type
):
run_cmd = fr'{PYTHON} "{scriptdir}/tools/lcm_convert.py"'
run_cmd = fr'"{PYTHON}" "{scriptdir}/tools/lcm_convert.py"'

# Check if source model exist
if not os.path.isfile(model_path):
Expand Down
2 changes: 1 addition & 1 deletion kohya_gui/convert_model_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def convert_model(
msgbox('The provided target folder does not exist')
return

run_cmd = fr'{PYTHON} "{scriptdir}/sd-scripts/tools/convert_diffusers20_original_sd.py"'
run_cmd = fr'"{PYTHON}" "{scriptdir}/sd-scripts/tools/convert_diffusers20_original_sd.py"'

v1_models = [
'runwayml/stable-diffusion-v1-5',
Expand Down
2 changes: 1 addition & 1 deletion kohya_gui/extract_lora_from_dylora_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def extract_dylora(
save_to = f"{path}_tmp{ext}"

run_cmd = (
fr'{PYTHON} "{scriptdir}/sd-scripts/networks/extract_lora_from_dylora.py"'
fr'"{PYTHON}" "{scriptdir}/sd-scripts/networks/extract_lora_from_dylora.py"'
)
run_cmd += fr' --save_to "{save_to}"'
run_cmd += fr' --model "{model}"'
Expand Down
2 changes: 1 addition & 1 deletion kohya_gui/extract_lora_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def extract_lora(
return

run_cmd = (
fr'{PYTHON} "{scriptdir}/sd-scripts/networks/extract_lora_from_models.py"'
fr'"{PYTHON}" "{scriptdir}/sd-scripts/networks/extract_lora_from_models.py"'
)
run_cmd += f' --load_precision {load_precision}'
run_cmd += f' --save_precision {save_precision}'
Expand Down
2 changes: 1 addition & 1 deletion kohya_gui/extract_lycoris_locon_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def extract_lycoris_locon(
path, ext = os.path.splitext(output_name)
output_name = f"{path}_tmp{ext}"

run_cmd = fr'{PYTHON} "{scriptdir}/sd-scripts/tools/lycoris_locon_extract.py"'
run_cmd = fr'"{PYTHON}" "{scriptdir}/sd-scripts/tools/lycoris_locon_extract.py"'
if is_sdxl:
run_cmd += f" --is_sdxl"
if is_v2:
Expand Down
4 changes: 2 additions & 2 deletions kohya_gui/finetune_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ def train_model(

# create caption json file
if generate_caption_database:
run_cmd = fr'{PYTHON} "{scriptdir}/sd-scripts/finetune/merge_captions_to_metadata.py"'
run_cmd = fr'"{PYTHON}" "{scriptdir}/sd-scripts/finetune/merge_captions_to_metadata.py"'
if caption_extension == "":
run_cmd += f' --caption_extension=".caption"'
else:
Expand All @@ -474,7 +474,7 @@ def train_model(

# create images buckets
if generate_image_buckets:
run_cmd = fr'{PYTHON} "{scriptdir}/sd-scripts/finetune/prepare_buckets_latents.py"'
run_cmd = fr'"{PYTHON}" "{scriptdir}/sd-scripts/finetune/prepare_buckets_latents.py"'
run_cmd += fr' "{image_folder}"'
run_cmd += fr' "{train_dir}/{caption_metadata_filename}"'
run_cmd += fr' "{train_dir}/{latent_metadata_filename}"'
Expand Down
2 changes: 1 addition & 1 deletion kohya_gui/git_caption_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def caption_images(
return

log.info(f'GIT captioning files in {train_data_dir}...')
run_cmd = fr'{PYTHON} "{scriptdir}/sd-scripts/finetune/make_captions_by_git.py"'
run_cmd = fr'"{PYTHON}" "{scriptdir}/sd-scripts/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
2 changes: 1 addition & 1 deletion kohya_gui/group_images_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def group_images(

log.info(f'Grouping images in {input_folder}...')

run_cmd = fr'{PYTHON} "{scriptdir}/tools/group_images.py"'
run_cmd = fr'"{PYTHON}" "{scriptdir}/tools/group_images.py"'
run_cmd += f' "{input_folder}"'
run_cmd += f' "{output_folder}"'
run_cmd += f' {(group_size)}'
Expand Down
4 changes: 2 additions & 2 deletions kohya_gui/merge_lora_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,10 +385,10 @@ def merge_lora(
return

if not sdxl_model:
run_cmd = fr'{PYTHON} "{scriptdir}/sd-scripts/networks/merge_lora.py"'
run_cmd = fr'"{PYTHON}" "{scriptdir}/sd-scripts/networks/merge_lora.py"'
else:
run_cmd = (
fr'{PYTHON} "{scriptdir}/sd-scripts/networks/sdxl_merge_lora.py"'
fr'"{PYTHON}" "{scriptdir}/sd-scripts/networks/sdxl_merge_lora.py"'
)
if sd_model:
run_cmd += fr' --sd_model "{sd_model}"'
Expand Down
2 changes: 1 addition & 1 deletion kohya_gui/merge_lycoris_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def merge_lycoris(
):
log.info('Merge model...')

run_cmd = fr'{PYTHON} "{scriptdir}/tools/merge_lycoris.py"'
run_cmd = fr'"{PYTHON}" "{scriptdir}/tools/merge_lycoris.py"'
run_cmd += fr' "{base_model}"'
run_cmd += fr' "{lycoris_model}"'
run_cmd += fr' "{output_name}"'
Expand Down
2 changes: 1 addition & 1 deletion kohya_gui/resize_lora_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def resize_lora(
if device == '':
device = 'cuda'

run_cmd = fr'{PYTHON} "{scriptdir}/sd-scripts/networks/resize_lora.py"'
run_cmd = fr'"{PYTHON}" "{scriptdir}/sd-scripts/networks/resize_lora.py"'
run_cmd += f' --save_precision {save_precision}'
run_cmd += fr' --save_to "{save_to}"'
run_cmd += fr' --model "{model}"'
Expand Down
2 changes: 1 addition & 1 deletion kohya_gui/svd_merge_lora_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def svd_merge_lora(
ratio_c /= total_ratio
ratio_d /= total_ratio

run_cmd = fr'{PYTHON} "{scriptdir}/sd-scripts/networks/svd_merge_lora.py"'
run_cmd = fr'"{PYTHON}" "{scriptdir}/sd-scripts/networks/svd_merge_lora.py"'
run_cmd += f' --save_precision {save_precision}'
run_cmd += f' --precision {precision}'
run_cmd += fr' --save_to "{save_to}"'
Expand Down
2 changes: 1 addition & 1 deletion kohya_gui/verify_lora_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def verify_lora(
msgbox('The provided model A is not a file')
return

run_cmd = fr'{PYTHON} "{scriptdir}/sd-scripts/networks/check_lora_weights.py" "{lora_model}"'
run_cmd = fr'"{PYTHON}" "{scriptdir}/sd-scripts/networks/check_lora_weights.py" "{lora_model}"'

log.info(run_cmd)

Expand Down
45 changes: 35 additions & 10 deletions setup/setup_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,73 +422,98 @@ def pip(arg: str, ignore: bool = False, quiet: bool = False, show_stdout: bool =
log.debug(f'Pip output: {txt}')
return txt


def installed(package, friendly: str = None):
#
# This function was adapted from code written by vladimandic: https://github.com/vladmandic/automatic/commits/master
#
"""
Checks if the specified package(s) are installed with the correct version.
This function can handle package specifications with or without version constraints,
and can also filter out command-line options and URLs when a 'friendly' string is provided.

# Remove brackets and their contents from the line using regular expressions
# e.g., diffusers[torch]==0.10.2 becomes diffusers==0.10.2
Parameters:
- package: A string that specifies one or more packages with optional version constraints.
- friendly: An optional string used to provide a cleaner version of the package string
that excludes command-line options and URLs.

Returns:
- True if all specified packages are installed with the correct versions, False otherwise.

Note:
This function was adapted from code written by vladimandic.
"""

# Remove any optional features specified in brackets (e.g., "package[option]==version" becomes "package==version")
package = re.sub(r'\[.*?\]', '', package)

try:
if friendly:
# If a 'friendly' version of the package string is provided, split it into components
pkgs = friendly.split()

# Exclude command-line options and URLs like "--index-url https://download.pytorch.org/whl/cu118"
# Filter out command-line options and URLs from the package specification
pkgs = [
p
for p in package.split()
if not p.startswith('--') and "://" not in p # Exclude command-line options and URLs
if not p.startswith('--') and "://" not in p
]
else:
# Split the package string into components, excluding '-' and '=' prefixed items
pkgs = [
p
for p in package.split()
if not p.startswith('-') and not p.startswith('=')
]
# For each package component, extract the package name, excluding any URLs
pkgs = [
p.split('/')[-1] for p in pkgs
] # get only package name if installing from URL
]

for pkg in pkgs:
# Parse the package name and version based on the version specifier used
if '>=' in pkg:
pkg_name, pkg_version = [x.strip() for x in pkg.split('>=')]
elif '==' in pkg:
pkg_name, pkg_version = [x.strip() for x in pkg.split('==')]
else:
pkg_name, pkg_version = pkg.strip(), None

# Attempt to find the installed package by its name
spec = pkg_resources.working_set.by_key.get(pkg_name, None)
if spec is None:
# Try again with lowercase name
spec = pkg_resources.working_set.by_key.get(pkg_name.lower(), None)
if spec is None:
# Try replacing underscores with dashes
spec = pkg_resources.working_set.by_key.get(pkg_name.replace('_', '-'), None)

if spec is not None:
# Package is found, check version
version = pkg_resources.get_distribution(pkg_name).version
log.debug(f'Package version found: {pkg_name} {version}')

if pkg_version is not None:
# Verify if the installed version meets the specified constraints
if '>=' in pkg:
ok = version >= pkg_version
else:
ok = version == pkg_version

if not ok:
# Version mismatch, log warning and return False
log.warning(f'Package wrong version: {pkg_name} {version} required {pkg_version}')
return False
else:
# Package not found, log debug message and return False
log.debug(f'Package version not found: {pkg_name}')
return False

# All specified packages are installed with the correct versions
return True
except ModuleNotFoundError:
# One or more packages are not installed, log debug message and return False
log.debug(f'Package not installed: {pkgs}')
return False



# install package using pip if not already installed
def install(
#
Expand Down