Skip to content

Commit f036950

Browse files
authored
Merge pull request #2074 from bmaltais/dev
v23.0.6
2 parents 5a60d05 + 6b10cb2 commit f036950

18 files changed

+59
-28
lines changed

.release

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v23.0.5
1+
v23.0.6

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ The GUI allows you to set the training parameters and generate and run the requi
3737
- [No module called tkinter](#no-module-called-tkinter)
3838
- [SDXL training](#sdxl-training)
3939
- [Change History](#change-history)
40+
- [2024/03/11 (v23.0.6)](#20240311-v2306)
41+
- [2024/03/11 (v23.0.5)](#20240311-v2305)
4042
- [2024/03/10 (v23.0.4)](#20240310-v2304)
4143
- [2024/03/10 (v23.0.3)](#20240310-v2303)
4244
- [2024/03/10 (v23.0.2)](#20240310-v2302)
@@ -363,6 +365,10 @@ The documentation in this section will be moved to a separate document later.
363365

364366
## Change History
365367

368+
### 2024/03/11 (v23.0.6)
369+
370+
- Fix issue with PYTHON path that have "spaces" in them
371+
366372
### 2024/03/11 (v23.0.5)
367373

368374
- Update python module verification

kohya_gui/basic_caption_gui.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def caption_images(
3838
log.info(f'Captioning files in {images_dir} with {caption_text}...')
3939

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

4444
# Add optional flags to the command

kohya_gui/blip_caption_gui.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def caption_images(
3737
log.info(f"Captioning files in {train_data_dir}...")
3838

3939
# Construct the command to run
40-
run_cmd = rf'{PYTHON} "{scriptdir}/sd-scripts/finetune/make_captions.py"'
40+
run_cmd = rf'"{PYTHON}" "{scriptdir}/sd-scripts/finetune/make_captions.py"'
4141
run_cmd += f' --batch_size="{int(batch_size)}"'
4242
run_cmd += f' --num_beams="{int(num_beams)}"'
4343
run_cmd += f' --top_p="{top_p}"'

kohya_gui/convert_lcm_gui.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def convert_lcm(
2828
lora_scale,
2929
model_type
3030
):
31-
run_cmd = fr'{PYTHON} "{scriptdir}/tools/lcm_convert.py"'
31+
run_cmd = fr'"{PYTHON}" "{scriptdir}/tools/lcm_convert.py"'
3232

3333
# Check if source model exist
3434
if not os.path.isfile(model_path):

kohya_gui/convert_model_gui.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def convert_model(
4949
msgbox('The provided target folder does not exist')
5050
return
5151

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

5454
v1_models = [
5555
'runwayml/stable-diffusion-v1-5',

kohya_gui/extract_lora_from_dylora_gui.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def extract_dylora(
5151
save_to = f"{path}_tmp{ext}"
5252

5353
run_cmd = (
54-
fr'{PYTHON} "{scriptdir}/sd-scripts/networks/extract_lora_from_dylora.py"'
54+
fr'"{PYTHON}" "{scriptdir}/sd-scripts/networks/extract_lora_from_dylora.py"'
5555
)
5656
run_cmd += fr' --save_to "{save_to}"'
5757
run_cmd += fr' --model "{model}"'

kohya_gui/extract_lora_gui.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def extract_lora(
7474
return
7575

7676
run_cmd = (
77-
fr'{PYTHON} "{scriptdir}/sd-scripts/networks/extract_lora_from_models.py"'
77+
fr'"{PYTHON}" "{scriptdir}/sd-scripts/networks/extract_lora_from_models.py"'
7878
)
7979
run_cmd += f' --load_precision {load_precision}'
8080
run_cmd += f' --save_precision {save_precision}'

kohya_gui/extract_lycoris_locon_gui.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def extract_lycoris_locon(
7474
path, ext = os.path.splitext(output_name)
7575
output_name = f"{path}_tmp{ext}"
7676

77-
run_cmd = fr'{PYTHON} "{scriptdir}/sd-scripts/tools/lycoris_locon_extract.py"'
77+
run_cmd = fr'"{PYTHON}" "{scriptdir}/sd-scripts/tools/lycoris_locon_extract.py"'
7878
if is_sdxl:
7979
run_cmd += f" --is_sdxl"
8080
if is_v2:

kohya_gui/finetune_gui.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ def train_model(
453453

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

475475
# create images buckets
476476
if generate_image_buckets:
477-
run_cmd = fr'{PYTHON} "{scriptdir}/sd-scripts/finetune/prepare_buckets_latents.py"'
477+
run_cmd = fr'"{PYTHON}" "{scriptdir}/sd-scripts/finetune/prepare_buckets_latents.py"'
478478
run_cmd += fr' "{image_folder}"'
479479
run_cmd += fr' "{train_dir}/{caption_metadata_filename}"'
480480
run_cmd += fr' "{train_dir}/{latent_metadata_filename}"'

kohya_gui/git_caption_gui.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def caption_images(
3333
return
3434

3535
log.info(f'GIT captioning files in {train_data_dir}...')
36-
run_cmd = fr'{PYTHON} "{scriptdir}/sd-scripts/finetune/make_captions_by_git.py"'
36+
run_cmd = fr'"{PYTHON}" "{scriptdir}/sd-scripts/finetune/make_captions_by_git.py"'
3737
if not model_id == '':
3838
run_cmd += f' --model_id="{model_id}"'
3939
run_cmd += f' --batch_size="{int(batch_size)}"'

kohya_gui/group_images_gui.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def group_images(
3232

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

35-
run_cmd = fr'{PYTHON} "{scriptdir}/tools/group_images.py"'
35+
run_cmd = fr'"{PYTHON}" "{scriptdir}/tools/group_images.py"'
3636
run_cmd += f' "{input_folder}"'
3737
run_cmd += f' "{output_folder}"'
3838
run_cmd += f' {(group_size)}'

kohya_gui/merge_lora_gui.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,10 +385,10 @@ def merge_lora(
385385
return
386386

387387
if not sdxl_model:
388-
run_cmd = fr'{PYTHON} "{scriptdir}/sd-scripts/networks/merge_lora.py"'
388+
run_cmd = fr'"{PYTHON}" "{scriptdir}/sd-scripts/networks/merge_lora.py"'
389389
else:
390390
run_cmd = (
391-
fr'{PYTHON} "{scriptdir}/sd-scripts/networks/sdxl_merge_lora.py"'
391+
fr'"{PYTHON}" "{scriptdir}/sd-scripts/networks/sdxl_merge_lora.py"'
392392
)
393393
if sd_model:
394394
run_cmd += fr' --sd_model "{sd_model}"'

kohya_gui/merge_lycoris_gui.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def merge_lycoris(
3636
):
3737
log.info('Merge model...')
3838

39-
run_cmd = fr'{PYTHON} "{scriptdir}/tools/merge_lycoris.py"'
39+
run_cmd = fr'"{PYTHON}" "{scriptdir}/tools/merge_lycoris.py"'
4040
run_cmd += fr' "{base_model}"'
4141
run_cmd += fr' "{lycoris_model}"'
4242
run_cmd += fr' "{output_name}"'

kohya_gui/resize_lora_gui.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def resize_lora(
5959
if device == '':
6060
device = 'cuda'
6161

62-
run_cmd = fr'{PYTHON} "{scriptdir}/sd-scripts/networks/resize_lora.py"'
62+
run_cmd = fr'"{PYTHON}" "{scriptdir}/sd-scripts/networks/resize_lora.py"'
6363
run_cmd += f' --save_precision {save_precision}'
6464
run_cmd += fr' --save_to "{save_to}"'
6565
run_cmd += fr' --model "{model}"'

kohya_gui/svd_merge_lora_gui.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def svd_merge_lora(
5353
ratio_c /= total_ratio
5454
ratio_d /= total_ratio
5555

56-
run_cmd = fr'{PYTHON} "{scriptdir}/sd-scripts/networks/svd_merge_lora.py"'
56+
run_cmd = fr'"{PYTHON}" "{scriptdir}/sd-scripts/networks/svd_merge_lora.py"'
5757
run_cmd += f' --save_precision {save_precision}'
5858
run_cmd += f' --precision {precision}'
5959
run_cmd += fr' --save_to "{save_to}"'

kohya_gui/verify_lora_gui.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def verify_lora(
3838
msgbox('The provided model A is not a file')
3939
return
4040

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

4343
log.info(run_cmd)
4444

setup/setup_common.py

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -422,73 +422,98 @@ def pip(arg: str, ignore: bool = False, quiet: bool = False, show_stdout: bool =
422422
log.debug(f'Pip output: {txt}')
423423
return txt
424424

425-
426425
def installed(package, friendly: str = None):
427-
#
428-
# This function was adapted from code written by vladimandic: https://github.com/vladmandic/automatic/commits/master
429-
#
426+
"""
427+
Checks if the specified package(s) are installed with the correct version.
428+
This function can handle package specifications with or without version constraints,
429+
and can also filter out command-line options and URLs when a 'friendly' string is provided.
430430
431-
# Remove brackets and their contents from the line using regular expressions
432-
# e.g., diffusers[torch]==0.10.2 becomes diffusers==0.10.2
431+
Parameters:
432+
- package: A string that specifies one or more packages with optional version constraints.
433+
- friendly: An optional string used to provide a cleaner version of the package string
434+
that excludes command-line options and URLs.
435+
436+
Returns:
437+
- True if all specified packages are installed with the correct versions, False otherwise.
438+
439+
Note:
440+
This function was adapted from code written by vladimandic.
441+
"""
442+
443+
# Remove any optional features specified in brackets (e.g., "package[option]==version" becomes "package==version")
433444
package = re.sub(r'\[.*?\]', '', package)
434445

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

439-
# Exclude command-line options and URLs like "--index-url https://download.pytorch.org/whl/cu118"
451+
# Filter out command-line options and URLs from the package specification
440452
pkgs = [
441453
p
442454
for p in package.split()
443-
if not p.startswith('--') and "://" not in p # Exclude command-line options and URLs
455+
if not p.startswith('--') and "://" not in p
444456
]
445457
else:
458+
# Split the package string into components, excluding '-' and '=' prefixed items
446459
pkgs = [
447460
p
448461
for p in package.split()
449462
if not p.startswith('-') and not p.startswith('=')
450463
]
464+
# For each package component, extract the package name, excluding any URLs
451465
pkgs = [
452466
p.split('/')[-1] for p in pkgs
453-
] # get only package name if installing from URL
454-
467+
]
468+
455469
for pkg in pkgs:
470+
# Parse the package name and version based on the version specifier used
456471
if '>=' in pkg:
457472
pkg_name, pkg_version = [x.strip() for x in pkg.split('>=')]
458473
elif '==' in pkg:
459474
pkg_name, pkg_version = [x.strip() for x in pkg.split('==')]
460475
else:
461476
pkg_name, pkg_version = pkg.strip(), None
462477

478+
# Attempt to find the installed package by its name
463479
spec = pkg_resources.working_set.by_key.get(pkg_name, None)
464480
if spec is None:
481+
# Try again with lowercase name
465482
spec = pkg_resources.working_set.by_key.get(pkg_name.lower(), None)
466483
if spec is None:
484+
# Try replacing underscores with dashes
467485
spec = pkg_resources.working_set.by_key.get(pkg_name.replace('_', '-'), None)
468486

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

473492
if pkg_version is not None:
493+
# Verify if the installed version meets the specified constraints
474494
if '>=' in pkg:
475495
ok = version >= pkg_version
476496
else:
477497
ok = version == pkg_version
478498

479499
if not ok:
500+
# Version mismatch, log warning and return False
480501
log.warning(f'Package wrong version: {pkg_name} {version} required {pkg_version}')
481502
return False
482503
else:
504+
# Package not found, log debug message and return False
483505
log.debug(f'Package version not found: {pkg_name}')
484506
return False
485507

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

491515

516+
492517
# install package using pip if not already installed
493518
def install(
494519
#

0 commit comments

Comments
 (0)