From f32ce0aead1d384eb5dd21ba492e4e31d0f3ad5d Mon Sep 17 00:00:00 2001 From: JSTayco Date: Sun, 2 Apr 2023 12:32:56 -0700 Subject: [PATCH 1/5] Removed tensorflow from requirements.txt for macOS Added CPU architecture detection for packages --- requirements.txt | 1 - setup.sh | 40 +++++++++++++++++++++++++++++++--------- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/requirements.txt b/requirements.txt index 0882cea..acdcfbb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -27,7 +27,6 @@ timm==0.6.12 huggingface-hub==0.12.0; sys_platform != 'darwin' huggingface-hub==0.13.0; sys_platform == 'darwin' tensorflow==2.10.1; sys_platform != 'darwin' -tensorflow-macos==2.12.0; sys_platform == 'darwin' # For locon support lycoris-lora @ git+https://github.com/KohakuBlueleaf/LyCORIS.git@c3d925421209a22a60d863ffa3de0b3e7e89f047 # lycoris_lora==0.1.4 diff --git a/setup.sh b/setup.sh index 4705fcf..d8efdaf 100755 --- a/setup.sh +++ b/setup.sh @@ -2,6 +2,12 @@ # This file will be the host environment setup file for all operating systems other than base Windows. +# Set the required package versions here. +# They will be appended to the requirements.txt file in the installation directory. +TENSORFLOW_VERSION="2.12.0" +TENSORFLOW_MACOS_VERSION="2.12.0" +TENSORFLOW_METAL_VERSION="0.8.0" + display_help() { cat <&3 - echo "Replacing the . for lib to our DIR variable in tmp/requirements_tmp.txt." >&3 - awk -v dir="$DIR" '/#.*kohya_ss.*library/{print; getline; sub(/^\.$/, dir)}1' "$DIR/requirements.txt" >/tmp/requirements_tmp.txt + #This will copy our requirements.txt file out and make the khoya_ss lib a dynamic location then cleanup. + local TEMP_REQUIREMENTS_FILE="$DIR/requirements_tmp_for_setup.txt" + echo "Copying $DIR/requirements.txt to $TEMP_REQUIREMENTS_FILE" >&3 + echo "Replacing the . for lib to our DIR variable in $TEMP_REQUIREMENTS_FILE." >&3 + awk -v dir="$DIR" '/#.*kohya_ss.*library/{print; getline; sub(/^\.$/, dir)}1' "$DIR/requirements.txt" >"$TEMP_REQUIREMENTS_FILE" + + # This will check if macOS is running then determine if M1+ or Intel CPU. + # It will append the appropriate packages to the requirements.txt file. + # Other OSs won't be affected and the version variables are at the top of this file. + if [[ "$(uname)" == "Darwin" ]]; then + # Check if the processor is Apple Silicon (arm64) + if [[ "$(uname -m)" == "arm64" ]]; then + echo "tensorflow-macos==$TENSORFLOW_MACOS_VERSION" >>"$TEMP_REQUIREMENTS_FILE" + echo "tensorflow-metal==$TENSORFLOW_METAL_VERSION" >>"$TEMP_REQUIREMENTS_FILE" + # Check if the processor is Intel (x86_64) + elif [[ "$(uname -m)" == "x86_64" ]]; then + echo "tensorflow==$TENSORFLOW_VERSION" >>"$TEMP_REQUIREMENTS_FILE" + fi + fi + if [ $VERBOSITY == 2 ]; then - python -m pip install --quiet --use-pep517 --upgrade -r /tmp/requirements_tmp.txt >&3 + python -m pip install --quiet --use-pep517 --upgrade -r "$TEMP_REQUIREMENTS_FILE" >&3 else - python -m pip install --use-pep517 --upgrade -r /tmp/requirements_tmp.txt >&3 + python -m pip install --use-pep517 --upgrade -r "$TEMP_REQUIREMENTS_FILE" >&3 fi echo "Removing the temp requirements file." - if [ -f /tmp/requirements_tmp.txt ]; then - rm /tmp/requirements_tmp.txt + if [ -f "$TEMP_REQUIREMENTS_FILE" ]; then + rm -f "$TEMP_REQUIREMENTS_FILE" fi if [ -n "$VIRTUAL_ENV" ]; then @@ -584,4 +606,4 @@ elif [[ "$OSTYPE" == "msys" ]]; then # MinGW has the msys environment which is a standalone suite of Linux utilies on Windows # "git bash" on Windows may also be detected as msys. echo "This hasn't been validated in msys (mingw) on Windows yet." -fi \ No newline at end of file +fi From a59fdbcd5973b2aa04c893b52a14303d6c00aace Mon Sep 17 00:00:00 2001 From: JSTayco Date: Sun, 2 Apr 2023 12:35:47 -0700 Subject: [PATCH 2/5] Typo fixes Makes the SAST happy. --- README.md | 6 +++--- setup.sh | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index be608ec..6aa9211 100644 --- a/README.md +++ b/README.md @@ -275,7 +275,7 @@ This will store your a backup file with your current locally installed pip packa - Fix an issue that images are loaded twice in Windows environment. - Add Min-SNR Weighting strategy. Details are in [#308](https://github.com/kohya-ss/sd-scripts/pull/308). Thank you to AI-Casanova for this great work! - Add `--min_snr_gamma` option to training scripts, 5 is recommended by paper. - - The Min SNR gamma fiels can be found unser the advanced training tab in all trainers. + - The Min SNR gamma fields can be found under the advanced training tab in all trainers. - Fixed the error while images are ended with capital image extensions. Thanks to @kvzn. https://github.com/bmaltais/kohya_ss/pull/454 * 2023/03/26 (v21.3.5) - Fix for https://github.com/bmaltais/kohya_ss/issues/230 @@ -283,11 +283,11 @@ This will store your a backup file with your current locally installed pip packa * 2023/03/25 (v21.3.4) - Added untested support for MacOS base on this gist: https://gist.github.com/jstayco/9f5733f05b9dc29de95c4056a023d645 - Let me know how this work. From the look of it it appear to be well tought out. I modified a few things to make it fit better with the rest of the code in the repo. + Let me know how this work. From the look of it it appear to be well thought out. I modified a few things to make it fit better with the rest of the code in the repo. - Fix for issue https://github.com/bmaltais/kohya_ss/issues/433 by implementing default of 0. - Removed non applicable save_model_as choices for LoRA and TI. * 2023/03/24 (v21.3.3) - - Add support for custom user gui files. THey will be created at installation time or when upgrading is missing. You will see two files in the root of the folder. One named `gui-user.bat` and the other `gui-user.ps1`. Edit the file based on your prefered terminal. Simply add the parameters you want to pass the gui in there and execute it to start the gui with them. Enjoy! + - Add support for custom user gui files. THey will be created at installation time or when upgrading is missing. You will see two files in the root of the folder. One named `gui-user.bat` and the other `gui-user.ps1`. Edit the file based on your preferred terminal. Simply add the parameters you want to pass the gui in there and execute it to start the gui with them. Enjoy! * 2023/03/23 (v21.3.2) - Fix issue reported: https://github.com/bmaltais/kohya_ss/issues/439 * 2023/03/23 (v21.3.1) diff --git a/setup.sh b/setup.sh index d8efdaf..607f2bc 100755 --- a/setup.sh +++ b/setup.sh @@ -600,10 +600,10 @@ elif [[ "$OSTYPE" == "darwin"* ]]; then configure_accelerate echo -e "Setup finished! Run ./gui.sh to start." elif [[ "$OSTYPE" == "cygwin" ]]; then - # Cygwin is a standalone suite of Linux utilies on Windows + # Cygwin is a standalone suite of Linux utilities on Windows echo "This hasn't been validated on cygwin yet." elif [[ "$OSTYPE" == "msys" ]]; then - # MinGW has the msys environment which is a standalone suite of Linux utilies on Windows + # MinGW has the msys environment which is a standalone suite of Linux utilities on Windows # "git bash" on Windows may also be detected as msys. echo "This hasn't been validated in msys (mingw) on Windows yet." fi From 6b5b131775b41e80195bcac51d1fa1467452c114 Mon Sep 17 00:00:00 2001 From: JSTayco Date: Sun, 2 Apr 2023 12:42:04 -0700 Subject: [PATCH 3/5] Tiny README typo fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6aa9211..645b27e 100644 --- a/README.md +++ b/README.md @@ -253,7 +253,7 @@ pip freeze > uninstall.txt pip uninstall -r uninstall.txt ``` -This will store your a backup file with your current locally installed pip packages and then uninstall them. Then, redo the installation instructions within the kohya_ss venv. +This will store a backup file with your current locally installed pip packages and then uninstall them. Then, redo the installation instructions within the kohya_ss venv. ## Change History From 12010c2c9c663defa2742548da3140c8afb83572 Mon Sep 17 00:00:00 2001 From: bmaltais Date: Sun, 2 Apr 2023 19:09:20 -0400 Subject: [PATCH 4/5] Update readme --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index be608ec..a02f8c5 100644 --- a/README.md +++ b/README.md @@ -257,6 +257,8 @@ This will store your a backup file with your current locally installed pip packa ## Change History +* 2024/04/02 (v21.4.1) + - removes TensorFlow from requirements.txt for Darwin platforms as pip does not support advanced conditionals like CPU architecture. The logic is now defined in setup.sh to avoid version bump headaches, and the selection logic is in the pre-existing pip function. Additionally, the release includes the addition of the tensorflow-metal package for M1+ Macs, which enables GPU acceleration per Apple's documentation. Thanks @jstayco * 2024/04/01 (v21.4.0) - Improved linux and macos installation and updates script. See README for more details. Many thanks to @jstayco and @Galunid for the great PR! - Fix issue with "missing library" error. From adad3272dc5cb45163c720b0df902ed99e347bf5 Mon Sep 17 00:00:00 2001 From: bmaltais Date: Sun, 2 Apr 2023 19:12:09 -0400 Subject: [PATCH 5/5] Update readme --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 665f5d7..8d6788b 100644 --- a/README.md +++ b/README.md @@ -257,8 +257,11 @@ This will store a backup file with your current locally installed pip packages a ## Change History -* 2024/04/02 (v21.4.1) +* 2024/04/02 (v21.4.2) - removes TensorFlow from requirements.txt for Darwin platforms as pip does not support advanced conditionals like CPU architecture. The logic is now defined in setup.sh to avoid version bump headaches, and the selection logic is in the pre-existing pip function. Additionally, the release includes the addition of the tensorflow-metal package for M1+ Macs, which enables GPU acceleration per Apple's documentation. Thanks @jstayco +* 2023/04/01 (v21.4.1) + - Fix type for linux install by @bmaltais in https://github.com/bmaltais/kohya_ss/pull/517 + - Fix .gitignore by @bmaltais in https://github.com/bmaltais/kohya_ss/pull/518 * 2024/04/01 (v21.4.0) - Improved linux and macos installation and updates script. See README for more details. Many thanks to @jstayco and @Galunid for the great PR! - Fix issue with "missing library" error.