在把玩stable diffusion
的webUI和comfyUI后,思考着自己也微调
一个个性化风格的checkpoint、LyCORIS或LoRA。
做好,环境问题搞崩心态的准备。
我的旧电脑,GPU才4G,直接跑蹦了三次。
在没有好电脑的情况下,还是别自己制作模型啦,费时间、费电脑,GPU不够的情况下,肯定跑不出来。
python:3.10.9(官方推荐),官方强调一定不能是3.11+,否则跑不了。
大概需要准备10-20张图片。
这里我们用华仔的图片:
https://stable-diffusion-art.com/wp-content/uploads/2023/09/lora_training_captions.zip
这个是在线图片处理网站:https://www.birme.net/
https://github.com/bmaltais/kohya_ss#setup
git clone https://github.com/bmaltais/kohya_ss.git
下载好了后,在目录下打开cmd
运行:
.\setup.bat
安装过程中,会有报错信息,如下面我的安装信息,就有error错误的。
这时,我们再单独安装他们即可。
我的安装信息如下:
07:30:01-098969 INFO Python 3.10.9 on Windows
07:30:01-114591 INFO nVidia toolkit detected
07:30:22-313445 INFO Torch 2.0.1+cu118
07:30:27-317148 INFO Torch backend: nVidia CUDA 11.8 cuDNN 8700
07:30:27-524602 INFO Torch detected GPU: NVIDIA GeForce GTX 960M VRAM 4096 Arch (5, 0) Cores 5
07:30:27-546322 INFO Installing modules from requirements_windows_torch2.txt...
07:30:27-571730 INFO Installing package: torch==2.0.1+cu118 torchvision==0.15.2+cu118 --index-url
https://download.pytorch.org/whl/cu118
07:30:31-836436 INFO Installing package: xformers==0.0.21
07:31:57-013124 INFO Installing package: bitsandbytes==0.35.0
07:32:51-316790 INFO Installing package: tensorboard==2.12.3 tensorflow==2.12.0
07:37:59-014316 ERROR Error running pip: install --upgrade tensorboard==2.12.3 tensorflow==2.12.0
07:37:59-014316 INFO Installing modules from requirements.txt...
07:37:59-014316 WARNING Package wrong version: accelerate 0.23.0 required 0.19.0
07:37:59-014316 INFO Installing package: accelerate==0.19.0
07:38:03-229388 INFO Installing package: aiofiles==23.2.1
07:38:06-751172 INFO Installing package: altair==4.2.2
07:38:38-267155 INFO Installing package: dadaptation==3.1
07:38:51-524642 INFO Installing package: diffusers[torch]==0.18.2
07:38:59-209713 INFO Installing package: easygui==0.98.3
07:39:02-399649 WARNING Package wrong version: einops 0.6.1 required 0.6.0
07:39:02-415277 INFO Installing package: einops==0.6.0
07:39:06-136609 INFO Installing package: fairscale==0.4.13
07:39:25-893111 INFO Installing package: ftfy==6.1.1
07:39:29-690634 INFO Installing package: gradio==3.36.1
07:40:36-392666 WARNING Package wrong version: huggingface-hub 0.17.2 required 0.15.1
07:40:36-400190 INFO Installing package: huggingface-hub==0.15.1
07:40:40-941236 INFO Installing package: invisible-watermark==0.2.0
07:41:24-129685 INFO Installing package: lion-pytorch==0.0.6
07:41:30-507921 INFO Installing package: lycoris_lora==1.8.3
07:41:37-013021 INFO Installing package: open-clip-torch==2.20.0
07:41:50-051513 INFO Installing package: opencv-python==4.7.0.68
07:42:25-089723 INFO Installing package: prodigyopt==1.0
07:42:28-598267 INFO Installing package: pytorch-lightning==1.9.0
07:42:38-209014 WARNING Package wrong version: rich 13.5.3 required 13.4.1
07:42:38-215011 INFO Installing package: rich==13.4.1
07:42:43-854357 WARNING Package wrong version: safetensors 0.3.3 required 0.3.1
07:42:43-860357 INFO Installing package: safetensors==0.3.1
07:42:48-383515 INFO Installing package: timm==0.6.12
07:42:54-170484 INFO Installing package: tk==0.1.0
07:42:57-803992 INFO Installing package: toml==0.10.2
07:43:01-527071 WARNING Package wrong version: transformers 4.33.2 required 4.30.2
07:43:01-533037 INFO Installing package: transformers==4.30.2
07:43:24-744913 INFO Installing package: voluptuous==0.13.1
07:43:29-529060 INFO Installing package: wandb==0.15.0
我的路径:E:\openai\project\kohya_ss\venv
我习惯性的改为true
。原因是:1.来节省空间,2来已经安装过的模块,就不用再安装一遍了。
include-system-site-packages = true
在kohya_ss
目录下,双击gui.bat
文件,进行启动。
http://127.0.0.1:7860/
这个地址和stable diffusion webUI是同一个地址。
打开我们启动的页面:
路径:Utilities – Captioning – BLIP Captioning
(WD14 Captioning
也可以)
选择文件夹,选择我们处理好图片的文件夹
最后点击:Caption images
。就可以帮我们生成字幕了。
命令行中打印的日志如下:
To create a public link, set `share=True` in `launch()`.
19:29:13-558295 INFO Captioning files in E:/下载/AI绘图/AIGC/hanli...
19:29:13-561260 INFO ./venv/Scripts/python.exe "finetune/make_captions.py" --batch_size="1" --num_beams="1"
--top_p="0.9" --max_length="75" --min_length="5" --beam_search --caption_extension=".txt"
"E:/下载/AI绘图/AIGC/hanli"
--caption_weights="https://storage.googleapis.com/sfr-vision-language-research/BLIP/models/mode
l_large_caption.pth"
Current Working Directory is: E:\openai\project\kohya_ss
load images from E:\下载\AI绘图\AIGC\hanli
found 13 images.
loading BLIP caption: https://storage.googleapis.com/sfr-vision-language-research/BLIP/models/model_large_caption.pth
Downloading (…)solve/main/vocab.txt: 100%|███████████████████████████████████████████| 232k/232k [00:00<00:00, 360kB/s]
Downloading (…)okenizer_config.json: 100%|██████████████████████████████████████████████████| 28.0/28.0 [00:00<?, ?B/s]
Downloading (…)lve/main/config.json: 100%|████████████████████████████████████████████████████| 570/570 [00:00<?, ?B/s]
100%|█████████████████████████████████████████████████████████████████████████████| 1.66G/1.66G [09:01<00:00, 3.30MB/s]
load checkpoint from https://storage.googleapis.com/sfr-vision-language-research/BLIP/models/model_large_caption.pth
BLIP loaded
100%|██████████████████████████████████████████████████████████████████████████████████| 13/13 [00:30<00:00, 2.36s/it]
done!
19:41:08-386110 INFO ...captioning done
可以看出,它下载了一个1.6G的文件,这个问题,存在路径:C:\Users\yutao\.cache\torch\hub\checkpoints\model_large_caption.pth
可以看出存放在C盘,非常不友好。
点击Prepare training data
按钮,会生成如下图所示的文件夹:
路径: LoRa – Training – source model
路径: LoRa – Training – parameters – basic
参数:
Optimizer extra arguments : scale_parameter=False relative_step=False warmup_init=False
路径: LoRa – Training – parameters – advanced
参数说明:LoRA-training-parameters
点击“Start training” 开始训练。
这里我遇到了一个警告:
WARNING[XFORMERS]: xFormers can't load C++/CUDA extensions. xFormers was built for:
PyTorch 2.0.1+cu118 with CUDA 1108 (you have 2.0.1+cpu)
Python 3.10.11 (you have 3.10.9)
Please reinstall xformers (see https://github.com/facebookresearch/xformers#installing-xformers)
Memory-efficient attention, SwiGLU, sparse and more won't be available.
上面是说,CUDA
没法使用,也就意味着,我们无法调用GPU来跑,只能调用CPU来跑。
执行如下命令:
pip uninstall -y torch torchvision torchaudio
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
即可解决
参考地址:
SDXL LORA Training locally with Kohya
How to train Lora models
AnimateDiff|高质量文本到动画视频生成
LoRA-training-parameters