Giter Club home page Giter Club logo

ai-toolkit's Introduction

AI Toolkit by Ostris

Special Thanks

I want to give a special thanks to Huggingface for their amazing work, and their continued support of my work. This repo would not be possible without them.

IMPORTANT NOTE - READ THIS

This is an active WIP repo that is not ready for others to use. And definitely not ready for non developers to use. I am making major breaking changes and pushing straight to master until I have it in a planned state. I have big changes planned for config files and the general structure. I may change how training works entirely. You are welcome to use but keep that in mind. If more people start to use it, I will follow better branch checkout standards, but for now this is my personal active experiment.

Report bugs as you find them, but not knowing how to train ML models, setup an environment, or use python is not a bug. I will make all of this more user-friendly eventually

I will make a better readme later.

Installation

Requirements:

  • python >3.10
  • Nvidia GPU with enough ram to do what you need
  • python venv
  • git

Linux:

git clone https://github.com/ostris/ai-toolkit.git
cd ai-toolkit
git submodule update --init --recursive
python3 -m venv venv
source venv/bin/activate
# .\venv\Scripts\activate on windows
# install torch first
pip3 install torch
pip3 install -r requirements.txt

Windows:

git clone https://github.com/ostris/ai-toolkit.git
cd ai-toolkit
git submodule update --init --recursive
python -m venv venv
.\venv\Scripts\activate
pip install torch --use-pep517 --extra-index-url https://download.pytorch.org/whl/cu118
pip install -r requirements.txt

Current Tools

I have so many hodge podge scripts I am going to be moving over to this that I use in my ML work. But this is what is here so far.


Batch Image Generation

A image generator that can take frompts from a config file or form a txt file and generate them to a folder. I mainly needed this for an SDXL test I am doing but added some polish to it so it can be used for generat batch image generation. It all runs off a config file, which you can find an example of in config/examples/generate.example.yaml. Mere info is in the comments in the example


LoRA (lierla), LoCON (LyCORIS) extractor

It is based on the extractor in the LyCORIS tool, but adding some QOL features and LoRA (lierla) support. It can do multiple types of extractions in one run. It all runs off a config file, which you can find an example of in config/examples/extract.example.yml. Just copy that file, into the config folder, and rename it to whatever_you_want.yml. Then you can edit the file to your liking. and call it like so:

python3 run.py config/whatever_you_want.yml

You can also put a full path to a config file, if you want to keep it somewhere else.

python3 run.py "/home/user/whatever_you_want.yml"

More notes on how it works are available in the example config file itself. LoRA and LoCON both support extractions of 'fixed', 'threshold', 'ratio', 'quantile'. I'll update what these do and mean later. Most people used fixed, which is traditional fixed dimension extraction.

process is an array of different processes to run. You can add a few and mix and match. One LoRA, one LyCON, etc.


LoRA Rescale

Change <lora:my_lora:4.6> to <lora:my_lora:1.0> or whatever you want with the same effect. A tool for rescaling a LoRA's weights. Should would with LoCON as well, but I have not tested it. It all runs off a config file, which you can find an example of in config/examples/mod_lora_scale.yml. Just copy that file, into the config folder, and rename it to whatever_you_want.yml. Then you can edit the file to your liking. and call it like so:

python3 run.py config/whatever_you_want.yml

You can also put a full path to a config file, if you want to keep it somewhere else.

python3 run.py "/home/user/whatever_you_want.yml"

More notes on how it works are available in the example config file itself. This is useful when making all LoRAs, as the ideal weight is rarely 1.0, but now you can fix that. For sliders, they can have weird scales form -2 to 2 or even -15 to 15. This will allow you to dile it in so they all have your desired scale


LoRA Slider Trainer

Open In Colab

This is how I train most of the recent sliders I have on Civitai, you can check them out in my Civitai profile. It is based off the work by p1atdev/LECO and rohitgandikota/erasing But has been heavily modified to create sliders rather than erasing concepts. I have a lot more plans on this, but it is very functional as is. It is also very easy to use. Just copy the example config file in config/examples/train_slider.example.yml to the config folder and rename it to whatever_you_want.yml. Then you can edit the file to your liking. and call it like so:

python3 run.py config/whatever_you_want.yml

There is a lot more information in that example file. You can even run the example as is without any modifications to see how it works. It will create a slider that turns all animals into dogs(neg) or cats(pos). Just run it like so:

python3 run.py config/examples/train_slider.example.yml

And you will be able to see how it works without configuring anything. No datasets are required for this method. I will post an better tutorial soon.


Extensions!!

You can now make and share custom extensions. That run within this framework and have all the inbuilt tools available to them. I will probably use this as the primary development method going forward so I dont keep adding and adding more and more features to this base repo. I will likely migrate a lot of the existing functionality as well to make everything modular. There is an example extension in the extensions folder that shows how to make a model merger extension. All of the code is heavily documented which is hopefully enough to get you started. To make an extension, just copy that example and replace all the things you need to.

Model Merger - Example Extension

It is located in the extensions folder. It is a fully finctional model merger that can merge as many models together as you want. It is a good example of how to make an extension, but is also a pretty useful feature as well since most mergers can only do one model at a time and this one will take as many as you want to feed it. There is an example config file in there, just copy that to your config folder and rename it to whatever_you_want.yml. and use it like any other config file.

WIP Tools

VAE (Variational Auto Encoder) Trainer

This works, but is not ready for others to use and therefore does not have an example config. I am still working on it. I will update this when it is ready. I am adding a lot of features for criteria that I have used in my image enlargement work. A Critic (discriminator), content loss, style loss, and a few more. If you don't know, the VAE for stable diffusion (yes even the MSE one, and SDXL), are horrible at smaller faces and it holds SD back. I will fix this. I'll post more about this later with better examples later, but here is a quick test of a run through with various VAEs. Just went in and out. It is much worse on smaller faces than shown here.


TODO

  • Add proper regs on sliders
  • Add SDXL support (base model only for now)
  • Add plain erasing
  • Make Textual inversion network trainer (network that spits out TI embeddings)

Change Log

2023-08-05

  • Huge memory rework and slider rework. Slider training is better thant ever with no more ram spikes. I also made it so all 4 parts of the slider algorythm run in one batch so they share gradient accumulation. This makes it much faster and more stable.
  • Updated the example config to be something more practical and more updated to current methods. It is now a detail slide and shows how to train one without a subject. 512x512 slider training for 1.5 should work on 6GB gpu now. Will test soon to verify.

2021-10-20

  • Windows support bug fixes
  • Extensions! Added functionality to make and share custom extensions for training, merging, whatever. check out the example in the extensions folder. Read more about that above.
  • Model Merging, provided via the example extension.

2023-08-03

Another big refactor to make SD more modular.

Made batch image generation script

2023-08-01

Major changes and update. New LoRA rescale tool, look above for details. Added better metadata so Automatic1111 knows what the base model is. Added some experiments and a ton of updates. This thing is still unstable at the moment, so hopefully there are not breaking changes.

Unfortunately, I am too lazy to write a proper changelog with all the changes.

I added SDXL training to sliders... but.. it does not work properly. The slider training relies on a model's ability to understand that an unconditional (negative prompt) means you do not want that concept in the output. SDXL does not understand this for whatever reason, which makes separating out concepts within the model hard. I am sure the community will find a way to fix this over time, but for now, it is not going to work properly. And if any of you are thinking "Could we maybe fix it by adding 1 or 2 more text encoders to the model as well as a few more entirely separate diffusion networks?" No. God no. It just needs a little training without every experimental new paper added to it. The KISS principal.

2023-07-30

Added "anchors" to the slider trainer. This allows you to set a prompt that will be used as a regularizer. You can set the network multiplier to force spread consistency at high weights

ai-toolkit's People

Contributors

foundsol avatar jaretburkett avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ai-toolkit's Issues

[Feature] Compel support

Hi, I tested your Lora slider Colab, and it works great. Thank you for this project!

During testing, I found that for a precise slider, it is best for the --m +10 and --m -10 prompts to be as close visually as possible, i.e. "sunny day, sepia photo" vs "sunny day, modern photo". However, on the default prompt engineering level, each prompt produced drastically different results, even with a fixed seed, which affects the precise results of the Lora slider during the inference.

Would it be possible for you to take into account the possibility of integrating the Complel library within your syntax?

It will help, for example, to do prompts like:
"(sunny day:1.3), (sepia photo:0.3)" vs "(sunny day:1.3), (modern photo:0.3)"
Almost identical images on both positive and negative ends will help to do even more precise Lora sliders.

Anyway, thank you for your work and really easy-to-use colab. Amazing work!

Error running job: 'ExtractLoraProcess' object has no attribute 'dim'

File "/content/ai-toolkit/run.py", line 75, in
main()
File "/content/ai-toolkit/run.py", line 71, in main
raise e
File "/content/ai-toolkit/run.py", line 63, in main
job.run()
File "/content/ai-toolkit/jobs/ExtractJob.py", line 58, in run
process.run()
File "/content/ai-toolkit/jobs/process/ExtractLoraProcess.py", line 49, in run
super().run()
File "/content/ai-toolkit/jobs/process/BaseExtractProcess.py", line 37, in run
self.output_path = self.get_output_path()
File "/content/ai-toolkit/jobs/process/ExtractLoraProcess.py", line 72, in get_output_path
suffix = f"_{self.dim}"
AttributeError: 'ExtractLoraProcess' object has no attribute 'dim'

Extracting locon doesn't give this error, just the lora. Sure enough, I don't see dim defined anywhere in ExtractLoraProcess.py

Maybe it was meant to be self.linear_param ?

Slider Torch error: "optimizer got an empty parameter list"

The "optimizer got an empty parameter list" problem is persisting when I try to train sliders, no matter how much I change the yml. I did a clean install of this repository to try to solve it and it didn't work. I'm on Windows 11 pro w/ Python 3.10.9

Traceback (most recent call last):
  File "[...]\ai-toolkit\run.py", line 75, in <module>
    main()
  File "[...]\ai-toolkit\run.py", line 71, in main
    raise e
  File "[...]\ai-toolkit\run.py", line 63, in main
    job.run()
  File "[...]\ai-toolkit\jobs\TrainJob.py", line 49, in run
    process.run()
  File "[...]\ai-toolkit\jobs\process\BaseSDTrainProcess.py", line 484, in run
    optimizer = get_optimizer(params, optimizer_type, learning_rate=self.train_config.lr,
  File "[...]\ai-toolkit\toolkit\optimizer.py", line 53, in get_optimizer
    optimizer = torch.optim.AdamW(params, lr=float(learning_rate), **optimizer_params)
  File "[...]\ai-toolkit\venv\lib\site-packages\torch\optim\adamw.py", line 50, in __init__
    super().__init__(params, defaults)
  File "[...]\ai-toolkit\venv\lib\site-packages\torch\optim\optimizer.py", line 187, in __init__
    raise ValueError("optimizer got an empty parameter list")
ValueError: optimizer got an empty parameter list

Also, thank you very much for your work :)

No module named 'library' from library.lpw_stable_diffusion

I am facing this error through windows and google Colab. I made a fork and I'm organizing a colab for the sliders script (as soon as it's fully functional I will disclose). I like your work very much!

Windows:

Running 1 job
Error running job: No module named 'library'

========================================
Result:
 - 0 completed jobs
 - 1 failure
========================================
Traceback (most recent call last):
  File "...\ai-toolkit\run.py", line 73, in <module>
    main()
  File "...\ai-toolkit\run.py", line 69, in main
    raise e
  File "...\ai-toolkit\run.py", line 60, in main
    job = get_job(config_file, args.name)
  File "...\ai-toolkit\toolkit\job.py", line 14, in get_job
    from jobs import TrainJob
  File "...\ai-toolkit\jobs\__init__.py", line 1, in <module>
    from .BaseJob import BaseJob
  File "...\ai-toolkit\jobs\BaseJob.py", line 5, in <module>
    from jobs.process import BaseProcess
  File "...\ai-toolkit\jobs\process\__init__.py", line 1, in <module>
    from .BaseExtractProcess import BaseExtractProcess
  File "...\ai-toolkit\jobs\process\BaseExtractProcess.py", line 7, in <module>
    from toolkit.metadata import get_meta_for_safetensors
  File "...\ai-toolkit\toolkit\metadata.py", line 9, in <module>
    from toolkit.train_tools import addnet_hash_legacy
  File "...\ai-toolkit\toolkit\train_tools.py", line 26, in <module>
    from library.lpw_stable_diffusion import StableDiffusionLongPromptWeightingPipeline
ModuleNotFoundError: No module named 'library'

Google Colab:

Running 1 job
2023-08-10 09:35:19.203675: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT
Error running job: No module named 'library'

========================================
Result:
 - 0 completed jobs
 - 1 failure
========================================
Traceback (most recent call last):
  File "/content/ai-toolkit/run.py", line 73, in <module>
    main()
  File "/content/ai-toolkit/run.py", line 69, in main
    raise e
  File "/content/ai-toolkit/run.py", line 60, in main
    job = get_job(config_file, args.name)
  File "/content/ai-toolkit/toolkit/job.py", line 14, in get_job
    from jobs import TrainJob
  File "/content/ai-toolkit/jobs/__init__.py", line 1, in <module>
    from .BaseJob import BaseJob
  File "/content/ai-toolkit/jobs/BaseJob.py", line 5, in <module>
    from jobs.process import BaseProcess
  File "/content/ai-toolkit/jobs/process/__init__.py", line 1, in <module>
    from .BaseExtractProcess import BaseExtractProcess
  File "/content/ai-toolkit/jobs/process/BaseExtractProcess.py", line 7, in <module>
    from toolkit.metadata import get_meta_for_safetensors
  File "/content/ai-toolkit/toolkit/metadata.py", line 9, in <module>
    from toolkit.train_tools import addnet_hash_legacy
  File "/content/ai-toolkit/toolkit/train_tools.py", line 26, in <module>
    from library.lpw_stable_diffusion import StableDiffusionLongPromptWeightingPipeline
ModuleNotFoundError: No module named 'library'

[Development] Mismatch of tensor dimension offset multiplier

========================================
Traceback (most recent call last):
File "C:!NeuralNetwork\ai-toolkit\run.py", line 86, in
main()
File "C:!NeuralNetwork\ai-toolkit\run.py", line 82, in main
raise e
File "C:!NeuralNetwork\ai-toolkit\run.py", line 74, in main
job.run()
File "C:!NeuralNetwork\ai-toolkit\jobs\TrainJob.py", line 49, in run
process.run()
File "C:!NeuralNetwork\ai-toolkit\jobs\process\BaseSDTrainProcess.py", line 950, in run
loss_dict = self.hook_train_loop(batch)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:!NeuralNetwork\ai-toolkit\jobs\process\TrainSliderProcess.py", line 553, in hook_train_loop
offset_multiplier = offset_multiplier.view(offset.shape[0], 1, 1, 1)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: shape '[6, 1, 1, 1]' is invalid for input of size 1

You can fix the error by changing offset_multiplier = offset_multiplier.view(offset.shape[0], 1, 1, 1)
on offset_multiplier = offset_multiplier.expand(offset.shape[0], 1, 1, 1)

Slider-Colab_RuntimeError: cutlassF: no kernel found to launch!

Colab Error encountered when trying to run training again after removing the line trying to import non-existing module mentioned in issue #21


[<ipython-input-25-8519949f2c4c>] (https://localhost:8080/#) in <cell line: 1>()
----> 1 run_job(job_to_run)

23 frames

[/usr/local/lib/python3.10/dist-packages/diffusers/models/attention_processor.py](https://localhost:8080/#) in __call__(self, attn, hidden_states, encoder_hidden_states, attention_mask, temb, scale)
   1257         # the output of sdp = (batch, num_heads, seq_len, head_dim)
   1258         # TODO: add support for attn.scale when we move to Torch 2.1
-> 1259         hidden_states = F.scaled_dot_product_attention(
   1260             query, key, value, attn_mask=attention_mask, dropout_p=0.0, is_causal=False
   1261         )

RuntimeError: cutlassF: no kernel found to launch!

Using default profile to train slider lora, not working, not seeing error reported

Tested on windows or wsl2 internally trained 1.5_base and revAnimated both models generated no change in the image

But the first time I ran it, it worked for a bit.
There was a noticeable change at step 100.

After the second day, it didn't work..

I don't know where the error record is, I don't know the reason~ Sorry!

Running 1 job
{
    "type": "slider",
    "network": {
        "type": "lierla",
        "rank": 8,
        "alpha": 1.0
    },
    "train": {
        "noise_scheduler": "ddpm",
        "steps": 500,
        "lr": 0.0001,
        "gradient_checkpointing": true,
        "train_unet": true,
        "train_text_encoder": false,
        "optimizer": "adamw",
        "lr_scheduler": "constant",
        "max_denoising_steps": 40,
        "batch_size": 1,
        "dtype": "bf16",
        "noise_offset": 0.0
    },
    "model": {
        "name_or_path": "/mnt/e/sd_models/Stable-diffusion/revAnimated_v122.safetensors",
        "is_v2": false,
        "is_v_pred": false,
        "is_xl": false
    },
    "save": {
        "dtype": "float16",
        "save_every": 50
    },
    "sample": {
        "sampler": "ddpm",
        "sample_every": 20,
        "width": 512,
        "height": 512,
        "prompts": [
            "a golden retriever --m -5",
            "a golden retriever --m -3",
            "a golden retriever --m 3",
            "a golden retriever --m 5",
            "calico cat --m -5",
            "calico cat --m -3",
            "calico cat --m 3",
            "calico cat --m 5",
            "an elephant --m -5",
            "an elephant --m -3",
            "an elephant --m 3",
            "an elephant --m 5"
        ],
        "neg": "cartoon, fake, drawing, illustration, cgi, animated, anime, monochrome",
        "seed": 42,
        "walk_seed": false,
        "guidance_scale": 7,
        "sample_steps": 20,
        "network_multiplier": 1.0
    },
    "logging": {
        "log_every": 10,
        "use_wandb": false,
        "verbose": false
    },
    "slider": {
        "resolutions": [
            [
                512,
                512
            ]
        ],
        "targets": [
            {
                "target_class": "animal",
                "positive": "cat",
                "negative": "dog",
                "weight": 1.0
            }
        ],
        "anchors": [
            {
                "prompt": "a woman",
                "neg_prompt": "animal",
                "multiplier": 8.0
            },
            {
                "prompt": "a man",
                "neg_prompt": "animal",
                "multiplier": 8.0
            },
            {
                "prompt": "a person",
                "neg_prompt": "animal",
                "multiplier": 8.0
            }
        ]
    }
}

#############################################
# Running job: pet_slider_v1
#############################################


Running  1 process
You have disabled the safety checker for <class 'toolkit.pipelines.CustomStableDiffusionPipeline'> by passing `safety_checker=None`. Ensure that you abide to the conditions of the Stable Diffusion license and do not expose unfiltered results in services or applications open to the public. Both the diffusers team and Hugging Face strongly recommend to keep the safety filter enabled in all public facing circumstances, disabling it only for use-cases that involve analyzing network behavior or auditing its results. For more information, please have a look at https://github.com/huggingface/diffusers/pull/254 .
create LoRA network. base dim (rank): 8, alpha: 1.0
neuron dropout: p=None, rank dropout: p=None, module dropout: p=None
create LoRA for Text Encoder: 0 modules.
create LoRA for U-Net: 192 modules.
enable LoRA for U-Net
Loading prompt file from None
Prompt tensors not found. Encoding prompts..
Encoding prompts:   0%|                                                               | 0/1 [00:00<?, ?it/s]Encoding erase negative
Encoding enhance positive
Encoding erase positive (inverse)
Encoding enhance negative (inverse)
Generating baseline samples before training
Saving at step 50
Saved to output/LoRA/pet_slider_v1/pet_slider_v1_000000050.safetensors
Saving at step 100

屏幕截图 2023-08-05 114047
屏幕截图 2023-08-05 114412

Issue with sliders, comma separated

Comma separated positive and negative options result in the following error on windows while trying to generate a slider. Removing the commas allows the generator to move forward and create a slider lora.

Prompt tensors not found. Encoding prompts..
Error running job: 'NoneType' object has no attribute 'text_embeds'

Traceback (most recent call last):
File "E:\ai-toolkit-main\ai-toolkit\run.py", line 75, in main()
File "E:\ai-toolkit-main\ai-toolkit\run.py", line 71, in main raise e
File "E:\ai-toolkit-main\ai-toolkit\run.py", line 63, in main job.run()
File "E:\ai-toolkit-main\ai-toolkit\jobs\TrainJob.py", line 50, in run process.run()
File "E:\ai-toolkit-main\ai-toolkit\jobs\process\BaseSDTrainProcess.py", line 344, in run
self.hook_before_train_loop()
File "E:\ai-toolkit-main\ai-toolkit\jobs\process\TrainSliderProcess.py", line 114, in hook_before_train_loop
concat_prompt_pair_batch = concat_prompt_pairs(prompt_pair_batch).to('cpu')
File "E:\ai-toolkit-main\ai-toolkit\toolkit\prompt_utils.py", line 88, in concat_prompt_pairs
positive_target = concat_prompt_embeds([p.positive_target for p in prompt_pairs])
File "E:\ai-toolkit-main\ai-toolkit\toolkit\prompt_utils.py", line 77, in concat_prompt_embeds
text_embeds = torch.cat([p.text_embeds for p in prompt_embeds], dim=0)
File "E:\ai-toolkit-main\ai-toolkit\toolkit\prompt_utils.py", line 77, in
text_embeds = torch.cat([p.text_embeds for p in prompt_embeds], dim=0)
AttributeError: 'NoneType' object has no attribute 'text_embeds'

Memory error when training sdxl slider

Traceback (most recent call last):
File "D:\01_AItools\ai-toolkit\run.py", line 75, in
main()
File "D:\01_AItools\ai-toolkit\run.py", line 71, in main
raise e
File "D:\01_AItools\ai-toolkit\run.py", line 62, in main
job = get_job(config_file, args.name)
File "D:\01_AItools\ai-toolkit\toolkit\job.py", line 20, in get_job
return TrainJob(config)
File "D:\01_AItools\ai-toolkit\jobs\TrainJob.py", line 40, in init
self.load_processes(process_dict)
File "D:\01_AItools\ai-toolkit\jobs\BaseJob.py", line 65, in load_processes
self.process.append(ProcessClass(i, self, process))
File "D:\01_AItools\ai-toolkit\jobs\process\TrainSliderProcess.py", line 32, in init
self.slider_config = SliderConfig(**self.get_conf('slider', {}))
File "D:\01_AItools\ai-toolkit\toolkit\config_modules.py", line 154, in init
target_permutations = get_slider_target_permutations(target)
File "D:\01_AItools\ai-toolkit\toolkit\prompt_utils.py", line 255, in get_slider_target_permutations
neg_permutations = get_permutations(target.negative)
File "D:\01_AItools\ai-toolkit\toolkit\prompt_utils.py", line 246, in get_permutations
permutations = list(itertools.permutations(phrases))
MemoryError

A couple of problems I've encountered with the installation on my end

Problems with windows installation

1.Removed accelerator from requirements.txt.

Collecting accelerator (from -r requirements.txt (line 8))
  Using cached accelerator-2023.7.18.dev1.tar.gz (352 kB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [2 lines of output]
      Accelerator only works on posix platforms (like Linux).
      You could try running under WSL.
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

2.ai-toolkit\toolkit\config.py -72-77 line
Adding encoding='utf-8' works fine.

    if real_config_path.endswith('.json') or real_config_path.endswith('.jsonc'):
        with open(real_config_path, 'r',encoding='utf-8') as f:
            config = json.load(f, object_pairs_hook=OrderedDict)
    elif real_config_path.endswith('.yaml') or real_config_path.endswith('.yml'):
        with open(real_config_path, 'r',encoding='utf-8') as f:
            config = yaml.load(f, Loader=fixed_loader)
Traceback (most recent call last):
  File "D:\ai\sd_webui_all\ai-toolkit\run.py", line 73, in <module>
    main()
  File "D:\ai\sd_webui_all\ai-toolkit\run.py", line 69, in main
    raise e
  File "D:\ai\sd_webui_all\ai-toolkit\run.py", line 60, in main
    job = get_job(config_file, args.name)
  File "D:\ai\sd_webui_all\ai-toolkit\toolkit\job.py", line 5, in get_job
    config = get_config(config_path, name)
  File "D:\ai\sd_webui_all\ai-toolkit\toolkit\config.py", line 77, in get_config
    config = yaml.load(f, Loader=fixed_loader)
  File "C:\Users\woshi\miniconda3\envs\ai-tools\lib\site-packages\yaml\__init__.py", line 79, in load
    loader = Loader(stream)
  File "C:\Users\woshi\miniconda3\envs\ai-tools\lib\site-packages\yaml\loader.py", line 34, in __init__
    Reader.__init__(self, stream)
  File "C:\Users\woshi\miniconda3\envs\ai-tools\lib\site-packages\yaml\reader.py", line 85, in __init__
    self.determine_encoding()
  File "C:\Users\woshi\miniconda3\envs\ai-tools\lib\site-packages\yaml\reader.py", line 124, in determine_encoding
    self.update_raw()
  File "C:\Users\woshi\miniconda3\envs\ai-tools\lib\site-packages\yaml\reader.py", line 178, in update_raw
    data = self.stream.read(size)
UnicodeDecodeError: 'gbk' codec can't decode byte 0xaa in position 3245: illegal multibyte sequence

Slider-training_ModuleNotFoundError+

When running on Colab using your notebook this error is encountered as there is no such module there.


[<ipython-input-7-8519949f2c4c>](https://localhost:8080/#) in <cell line: 1>()
----> 1 run_job(job_to_run)

8 frames

# [/content/ai-toolkit/toolkit/pipelines.py] (https://localhost:8080/#) in <module>
      6 from diffusers import StableDiffusionXLPipeline, StableDiffusionPipeline, LMSDiscreteScheduler
      7 from diffusers.pipelines.stable_diffusion import StableDiffusionPipelineOutput
----> 8 from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion_k_diffusion import ModelWrapper
      9 from diffusers.pipelines.stable_diffusion_xl import StableDiffusionXLPipelineOutput
     10 from diffusers.pipelines.stable_diffusion_xl.pipeline_stable_diffusion_xl import rescale_noise_cfg

ModuleNotFoundError: No module named 'diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion_k_diffusion'

RuntimeError: CUTLASS submodule not found.

I'm a newbie, and wanted to try to train the Slider-Lora.
However, when installing according to your instructions, the console keeps showing me this:

  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [8 lines of output]
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "C:\Users\Azazellz\AppData\Local\Temp\pip-install-odh8ca7q\xformers_6ea7f7dc889b49b9891defb237c7fa97\setup.py", line 239, in <module>
          ext_modules=get_extensions(),
        File "C:\Users\Azazellz\AppData\Local\Temp\pip-install-odh8ca7q\xformers_6ea7f7dc889b49b9891defb237c7fa97\setup.py", line 157, in get_extensions
          raise RuntimeError(
      RuntimeError: CUTLASS submodule not found. Did you forget to run `git submodule update --init --recursive` ?
      [end of output]

I've tried doing git submodule update --init --recursive as it said - nothing.
Tried even cloning CUTLASS manually into the repositories folder (don't know if that was supposed to help) - nothing.

Google Сolab produces something related to Cutlass too:
17016066241680

Error

Trying to run the LoRA Slider Trainer example on windows gives me this error

(venv) PS C:\ai-toolkit> python run.py config/examples/train_slider.example.yml
Running 1 job
{
    "type": "slider",
    "network": {
        "type": "lierla",
        "linear": 8,
        "linear_alpha": 4
    },
    "train": {
        "noise_scheduler": "ddpm",
        "steps": 500,
        "lr": 0.0002,
        "gradient_checkpointing": true,
        "train_unet": true,
        "train_text_encoder": false,
        "min_snr_gamma": 5.0,
        "optimizer": "adamw",
        "lr_scheduler": "constant",
        "max_denoising_steps": 40,
        "batch_size": 1,
        "dtype": "bf16",
        "noise_offset": 0.0
    },
    "model": {
        "name_or_path": "runwayml/stable-diffusion-v1-5",
        "is_v2": false,
        "is_v_pred": false,
        "is_xl": false
    },
    "save": {
        "dtype": "float16",
        "save_every": 50,
        "max_step_saves_to_keep": 2
    },
    "sample": {
        "sampler": "ddpm",
        "sample_every": 20,
        "width": 512,
        "height": 512,
        "prompts": [
            "a woman in a coffee shop, black hat, blonde hair, blue jacket --m -5",
            "a woman in a coffee shop, black hat, blonde hair, blue jacket --m -3",
            "a woman in a coffee shop, black hat, blonde hair, blue jacket --m 3",
            "a woman in a coffee shop, black hat, blonde hair, blue jacket --m 5",
            "a golden retriever sitting on a leather couch, --m -5",
            "a golden retriever sitting on a leather couch --m -3",
            "a golden retriever sitting on a leather couch --m 3",
            "a golden retriever sitting on a leather couch --m 5",
            "a man with a beard and red flannel shirt, wearing vr goggles, walking into traffic --m -5",
            "a man with a beard and red flannel shirt, wearing vr goggles, walking into traffic --m -3",
            "a man with a beard and red flannel shirt, wearing vr goggles, walking into traffic --m 3",
            "a man with a beard and red flannel shirt, wearing vr goggles, walking into traffic --m 5"
        ],
        "neg": "cartoon, fake, drawing, illustration, cgi, animated, anime, monochrome",
        "seed": 42,
        "walk_seed": false,
        "guidance_scale": 7,
        "sample_steps": 20,
        "network_multiplier": 1.0
    },
    "logging": {
        "log_every": 10,
        "use_wandb": false,
        "verbose": false
    },
    "slider": {
        "resolutions": [
            [
                512,
                512
            ]
        ],
        "batch_full_slide": true,
        "targets": [
            {
                "target_class": "",
                "positive": "high detail, 8k, intricate, detailed, high resolution, high res, high quality",
                "negative": "blurry, boring, fuzzy, low detail, low resolution, low res, low quality",
                "weight": 1.0,
                "shuffle": true
            }
        ]
    }
}

#############################################
# Running job: detail_slider_v1
#############################################


Running  1 process
Loading pipeline components...: 100%|████████████████████████████████████████████████████| 7/7 [00:04<00:00,  1.71it/s]
Error running job: 'bool' object has no attribute '__module__'

========================================
Result:
 - 0 completed jobs
 - 1 failure
========================================
Traceback (most recent call last):
  File "C:\ai-toolkit\run.py", line 75, in <module>
    main()
  File "C:\ai-toolkit\run.py", line 71, in main
    raise e
  File "C:\ai-toolkit\run.py", line 63, in main
    job.run()
  File "C:\ai-toolkit\jobs\TrainJob.py", line 50, in run
    process.run()
  File "C:\ai-toolkit\jobs\process\BaseSDTrainProcess.py", line 236, in run
    self.sd.load_model()
  File "C:\ai-toolkit\toolkit\stable_diffusion_model.py", line 191, in load_model
    pipe = pipln.from_pretrained(
  File "C:\ai-toolkit\venv\lib\site-packages\diffusers\pipelines\pipeline_utils.py", line 1170, in from_pretrained
    model = pipeline_class(**init_kwargs)
  File "C:\ai-toolkit\venv\lib\site-packages\diffusers\pipelines\stable_diffusion\pipeline_stable_diffusion.py", line 183, in __init__
    self.register_modules(
  File "C:\ai-toolkit\venv\lib\site-packages\diffusers\pipelines\pipeline_utils.py", line 513, in register_modules
    library = not_compiled_module.__module__.split(".")[0]
AttributeError: 'bool' object has no attribute '__module__'. Did you mean: '__mod__'?

Very high system RAM use in certain scenario

Relevant error message:

Error running job:

========================================
Result:

  • 0 completed jobs
  • 1 failure
    ========================================
    Traceback (most recent call last):
    File "C:\Users\UserName\Desktop\AI\ai-toolkit\run.py", line 75, in
    main()
    File "C:\Users\UserName\Desktop\AI\ai-toolkit\run.py", line 71, in main
    raise e
    File "C:\Users\UserName\Desktop\AI\ai-toolkit\run.py", line 62, in main
    job = get_job(config_file, args.name)
    File "C:\Users\UserName\Desktop\AI\ai-toolkit\toolkit\job.py", line 20, in get_job
    return TrainJob(config)
    File "C:\Users\UserName\Desktop\AI\ai-toolkit\jobs\TrainJob.py", line 40, in init
    self.load_processes(process_dict)
    File "C:\Users\UserName\Desktop\AI\ai-toolkit\jobs\BaseJob.py", line 65, in load_processes
    self.process.append(ProcessClass(i, self, process))
    File "C:\Users\UserName\Desktop\AI\ai-toolkit\jobs\process\TrainSliderProcess.py", line 32, in init
    self.slider_config = SliderConfig(**self.get_conf('slider', {}))
    File "C:\Users\UserName\Desktop\AI\ai-toolkit\toolkit\config_modules.py", line 154, in init
    target_permutations = get_slider_target_permutations(target)
    File "C:\Users\UserName\Desktop\AI\ai-toolkit\toolkit\prompt_utils.py", line 260, in get_slider_target_permutations
    SliderTargetConfig(
    File "C:\Users\UserName\Desktop\AI\ai-toolkit\toolkit\config_modules.py", line 121, in init
    self.target_class: str = kwargs.get('target_class', '')
    MemoryError

It seems that if too many tags are put into "positive" and/or "negative" for your target, the program will eat up a very high amount of system ram.

Running with these prompts in the config led to the script trying to use every single bit of my 48gb of system ram it could possibly get.
Positive: "complex 3d render ultra detailed, 150 mm, beautiful studio soft light, rim light, vibrant details, hyperrealistic"
Negative: ""illustration, 3d, sepia, painting, cartoons, sketch, worst quality, low quality, normal quality"

However, ~4-8gb would be in use with a tags few pruned:
Positive: "Ultra detailed, 150 mm, beautiful studio soft light, rim light, vibrant details, hyperrealistic"
Negative: "illustration, sepia, painting, cartoons, sketch, worst quality, low quality, normal quality"

As an addendum, if "shuffle" is set to false, this does not happen,

The slider does not work with SDXL.

I have already trained 3 different LoRA-slider with different settings of positive and negative, but the sliders are obtained for detail, and not for what I trained.

Hair Style Slider:

  • Positive: "trendy hairstyle, stylish hair, modern haircut, chic hairdo, fashionable hair, contemporary style, well-styled hair"
  • Negative: "outdated hairstyle, old-fashioned hair, dated haircut, unkempt hairdo, unfashionable hair, stale style, messy hair"

Fitness Level Slider:

  • Positive: "fit physique, toned body, athletic build, muscular frame, healthy look, strong appearance, vigorous physique"
  • Negative: "unfit physique, flabby body, out-of-shape build, weak frame, unhealthy look, frail appearance, lethargic physique"

Technological Advancement Slider:

  • Positive: "advanced technology, modern gadgets, futuristic tech, innovative devices, high-tech environment, cutting-edge technology, state-of-the-art tech"
  • Negative: "outdated technology, old gadgets, antiquated tech, obsolete devices, low-tech environment, behind-the-times technology, dated tech"

Can't train slider on NAI

I have tried running the slider script on NAI models, but I get an error every time. The example worked just fine.

On the fp16 safetensors version, I get the error: AttributeError: 'CLIPTextModel' object has no attribute 'embeddings'
On the original ckpt version, I get the error: KeyError: 'time_embed.0.weight'

I've tried changing the dtype, but to no avail. Any chance to fix this?

Thanks for this amazing work!

The adaptations you made here are remarkable!. thanks for sharing this work!.
Do you have any plans to migrate the slider/extraction work for SDXL loras as well?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.