1 Star 0 Fork 0

Lewen / kohya_ss

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

Kohya's GUI

This repository primarily provides a Gradio GUI for Kohya's Stable Diffusion trainers. However, support for Linux OS is also offered through community contributions. macOS support is not optimal at the moment but might work if the conditions are favorable.

The GUI allows you to set the training parameters and generate and run the required CLI commands to train the model.

Table of Contents

🦒 Colab

This Colab notebook was not created or maintained by me; however, it appears to function effectively. The source can be found at: https://github.com/camenduru/kohya_ss-colab.

I would like to express my gratitude to camendutu for their valuable contribution. If you encounter any issues with the Colab notebook, please report them on their repository.

Colab Info
Open In Colab kohya_ss_gui_colab

Installation

Windows

Windows Pre-requirements

To install the necessary dependencies on a Windows system, follow these steps:

  1. Install Python 3.10.11.

    • During the installation process, ensure that you select the option to add Python to the 'PATH' environment variable.
  2. Install CUDA 11.8 toolkit.

  3. Install Git.

  4. Install the Visual Studio 2015, 2017, 2019, and 2022 redistributable.

Setup Windows

To set up the project, follow these steps:

  1. Open a terminal and navigate to the desired installation directory.

  2. Clone the repository by running the following command:

    git clone https://github.com/bmaltais/kohya_ss.git
  3. Change into the kohya_ss directory:

    cd kohya_ss
  4. Run the setup script by executing the following command:

    .\setup.bat

    During the accelerate config step, use the default values as proposed during the configuration unless you know your hardware demands otherwise. The amount of VRAM on your GPU does not impact the values used.

Optional: CUDNN 8.9.6.50

The following steps are optional but will improve the learning speed for owners of NVIDIA 30X0/40X0 GPUs. These steps enable larger training batch sizes and faster training speeds.

  1. Run .\setup.bat and select 2. (Optional) Install cudnn files (if you want to use the latest supported cudnn version).

Linux and macOS

Linux Pre-requirements

To install the necessary dependencies on a Linux system, ensure that you fulfill the following requirements:

  • Ensure that venv support is pre-installed. You can install it on Ubuntu 22.04 using the command:

    apt install python3.10-venv
  • Install the CUDA 11.8 Toolkit by following the instructions provided in this link.

  • Make sure you have Python version 3.10.9 or higher (but lower than 3.11.0) installed on your system.

Setup Linux

To set up the project on Linux or macOS, perform the following steps:

  1. Open a terminal and navigate to the desired installation directory.

  2. Clone the repository by running the following command:

    git clone https://github.com/bmaltais/kohya_ss.git
  3. Change into the kohya_ss directory:

    cd kohya_ss
  4. If you encounter permission issues, make the setup.sh script executable by running the following command:

    chmod +x ./setup.sh
  5. Run the setup script by executing the following command:

    ./setup.sh

    Note: If you need additional options or information about the runpod environment, you can use setup.sh -h or setup.sh --help to display the help message.

Install Location

The default installation location on Linux is the directory where the script is located. If a previous installation is detected in that location, the setup will proceed there. Otherwise, the installation will fall back to /opt/kohya_ss. If /opt is not writable, the fallback location will be $HOME/kohya_ss. Finally, if none of the previous options are viable, the installation will be performed in the current directory.

For macOS and other non-Linux systems, the installation process will attempt to detect the previous installation directory based on where the script is run. If a previous installation is not found, the default location will be $HOME/kohya_ss. You can override this behavior by specifying a custom installation directory using the -d or --dir option when running the setup script.

If you choose to use the interactive mode, the default values for the accelerate configuration screen will be "This machine," "None," and "No" for the remaining questions. These default answers are the same as the Windows installation.

Runpod

Manual installation

To install the necessary components for Runpod and run kohya_ss, follow these steps:

  1. Select the Runpod pytorch 2.0.1 template. This is important. Other templates may not work.

  2. SSH into the Runpod.

  3. Clone the repository by running the following command:

    cd /workspace
    git clone https://github.com/bmaltais/kohya_ss.git
  4. Run the setup script:

    cd kohya_ss
    ./setup-runpod.sh
  5. Run the GUI with:

    ./gui.sh --share --headless

    or with this if you expose 7860 directly via the runpod configuration:

    ./gui.sh --listen=0.0.0.0 --headless
  6. Connect to the public URL displayed after the installation process is completed.

Pre-built Runpod template

To run from a pre-built Runpod template, you can:

  1. Open the Runpod template by clicking on https://runpod.io/gsc?template=ya6013lj5a&ref=w18gds2n.

  2. Deploy the template on the desired host.

  3. Once deployed, connect to the Runpod on HTTP 3010 to access the kohya_ss GUI. You can also connect to auto1111 on HTTP 3000.

Docker

Local docker build

If you prefer to use Docker, follow the instructions below:

  1. Ensure that you have Git and Docker installed on your Windows or Linux system.

  2. Open your OS shell (Command Prompt or Terminal) and run the following commands:

    git clone --recursive https://github.com/bmaltais/kohya_ss.git
    cd kohya_ss
    docker compose up -d --build

    Note: The initial run may take up to 20 minutes to complete.

    Please be aware of the following limitations when using Docker:

    • All training data must be placed in the dataset subdirectory, as the Docker container cannot access files from other directories.
    • The file picker feature is not functional. You need to manually set the folder path and config file path.
    • Dialogs may not work as expected, and it is recommended to use unique file names to avoid conflicts.
    • This Dockerfile has been designed to be easily disposable. You can discard the container at any time and docker build it with a new version of the code. To update the system, run update scripts outside of Docker and rebuild using docker compose down && docker compose up -d --build.

    If you are running Linux, an alternative Docker container port with fewer limitations is available here.

ashleykleynhans runpod docker builds

You may want to use the following Dockerfile repositories to build the images:

Upgrading

To upgrade your installation to a new version, follow the instructions below.

Windows Upgrade

If a new release becomes available, you can upgrade your repository by running the following commands from the root directory of the project:

  1. Pull the latest changes from the repository:

    git pull
  2. Run the setup script:

    .\setup.bat

Linux and macOS Upgrade

To upgrade your installation on Linux or macOS, follow these steps:

  1. Open a terminal and navigate to the root directory of the project.

  2. Pull the latest changes from the repository:

    git pull
  3. Refresh and update everything:

    ./setup.sh

Starting GUI Service

To launch the GUI service, you can use the provided scripts or run the kohya_gui.py script directly. Use the command line arguments listed below to configure the underlying service.

--listen: Specify the IP address to listen on for connections to Gradio.
--username: Set a username for authentication.
--password: Set a password for authentication.
--server_port: Define the port to run the server listener on.
--inbrowser: Open the Gradio UI in a web browser.
--share: Share the Gradio UI.
--language: Set custom language

Launching the GUI on Windows

On Windows, you can use either the gui.ps1 or gui.bat script located in the root directory. Choose the script that suits your preference and run it in a terminal, providing the desired command line arguments. Here's an example:

gui.ps1 --listen 127.0.0.1 --server_port 7860 --inbrowser --share

or

gui.bat --listen 127.0.0.1 --server_port 7860 --inbrowser --share

Launching the GUI on Linux and macOS

To launch the GUI on Linux or macOS, run the gui.sh script located in the root directory. Provide the desired command line arguments as follows:

gui.sh --listen 127.0.0.1 --server_port 7860 --inbrowser --share

Custom Path Defaults

You can now specify custom paths more easily:

  • Simply copy the config example.toml file located in the root directory of the repository to config.toml.
  • Edit the config.toml file to adjust paths and settings according to your preferences.

LoRA

To train a LoRA, you can currently use the train_network.py code. You can create a LoRA network by using the all-in-one GUI.

Once you have created the LoRA network, you can generate images using auto1111 by installing this extension.

Sample image generation during training

A prompt file might look like this, for example:

# prompt 1
masterpiece, best quality, (1girl), in white shirts, upper body, looking at viewer, simple background --n low quality, worst quality, bad anatomy, bad composition, poor, low effort --w 768 --h 768 --d 1 --l 7.5 --s 28

# prompt 2
masterpiece, best quality, 1boy, in business suit, standing at street, looking back --n (low quality, worst quality), bad anatomy, bad composition, poor, low effort --w 576 --h 832 --d 2 --l 5.5 --s 40

Lines beginning with # are comments. You can specify options for the generated image with options like --n after the prompt. The following options can be used:

  • --n: Negative prompt up to the next option.
  • --w: Specifies the width of the generated image.
  • --h: Specifies the height of the generated image.
  • --d: Specifies the seed of the generated image.
  • --l: Specifies the CFG scale of the generated image.
  • --s: Specifies the number of steps in the generation.

The prompt weighting such as ( ) and [ ] is working.

Troubleshooting

If you encounter any issues, refer to the troubleshooting steps below.

Page File Limit

If you encounter an X error related to the page file, you may need to increase the page file size limit in Windows.

No module called tkinter

If you encounter an error indicating that the module tkinter is not found, try reinstalling Python 3.10 on your system.

SDXL training

The documentation in this section will be moved to a separate document later.

Change History

2024/03/21 (v23.0.15)

  • Add support for toml dataset configuration fole to all trainers
  • Add new setup menu option to install Triton 2.1.0 for Windows
  • Add support for LyCORIS BOFT and DoRA and QLyCORIS options for LoHA, LoKr and LoCon
  • Fix issue with vae path validation
  • Other fixes

2024/03/19 (v23.0.14)

  • Fix blip caption issue

2024/03/19 (v23.0.13)

  • Fix issue with image samples.

2024/03/16 (v23.0.12)

New Features & Improvements

  • Enhanced Logging and Tracking Capabilities

    • Added support for configuring advanced logging and tracking:
      • wandb_run_name: Set a custom name for your Weights & Biases runs to easily identify and organize your experiments.
      • log_tracker_name and log_tracker_config: Integrate custom logging trackers with your projects. Specify the tracker name and provide its configuration to enable detailed monitoring and logging of your runs.
  • Custom Path Defaults

    • You can now specify custom paths more easily:
      • Simply copy the config example.toml file located in the root directory of the repository to config.toml.
      • Edit the config.toml file to adjust paths and settings according to your preferences.

Software Updates

  • sd-scripts updated to v0.8.5

    • Bug Fixes:
      • Corrected an issue where the value of timestep embedding was incorrect during SDXL training. This fix ensures accurate training progress and results.
      • Addressed a related inference issue with the generation script, improving the reliability of SDXL model outputs.
    • Note: The exact impact of this bug is currently unknown, but it's recommended to update to v0.8.5 for anyone engaged in SDXL training to ensure optimal performance and results.
  • Upgrade of lycoris_lora Python Module

    • Updated the lycoris_lora module to version 2.2.0.post3. This update may include bug fixes, performance improvements, and new features.

Recommendations for Users

  • To benefit from the latest features and improvements, users are encouraged to update their installations and configurations accordingly.

2024/03/13 (v23.0.11)

  • Increase icon size.
  • More setup fixes.

2024/03/13 (v23.0.9)

  • Reworked how setup can be run to improve Stability Matrix support.
  • Added support for huggingface-based vea path.

2024/03/12 (v23.0.8)

  • Add the ability to create output and logs folder if it does not exist

2024/03/12 (v23.0.7)

  • Fixed minor issues related to functions and file paths.

2024/03/11 (v23.0.6)

  • Fixed an issue with PYTHON paths that have "spaces" in them.

2024/03/11 (v23.0.5)

  • Updated python module verification.
  • Removed cudnn module installation in Windows.

2024/03/10 (v23.0.4)

  • Updated bitsandbytes to 0.43.0.
  • Added packaging to runpod setup.

2024/03/10 (v23.0.3)

  • Fixed a bug with setup.
  • Enforced proper python version before running the GUI to prevent issues with execution of the GUI.

2024/03/10 (v23.0.2)

  • Improved validation of the path provided by users before running training.

2024/03/09 (v23.0.1)

  • Updated bitsandbytes module to 0.43.0 as it provides native Windows support.
  • Minor fixes to the code.

2024/03/02 (v23.0.0)

  • Used sd-scripts release 0.8.4 post commit fccbee27277d65a8dcbdeeb81787ed4116b92e0b.
  • Major code refactoring thanks to @wkpark. This will make updating sd-scripts cleaner by keeping sd-scripts files separate from the GUI files. This will also make configuration more streamlined with fewer tabs and more accordion elements. Hope you like the new style.
  • This new release is implementing a significant structure change, moving all of the sd-scripts written by kohya under a folder called sd-scripts in the root of this project. This folder is a submodule that will be populated during setup or GUI execution.
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [2022] [kohya-ss] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

暂无描述 展开 收起
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/leVenWing/kohya_ss.git
git@gitee.com:leVenWing/kohya_ss.git
leVenWing
kohya_ss
kohya_ss
master

搜索帮助