thu / trainFlux /trainFlux_CLI.sh
housearch's picture
Update trainFlux/trainFlux_CLI.sh
9c291c1 verified
#使用 bash指令執行這個腳本 ---> bash kohya_ss.sh
#!/bin/bash
wget --trust-server-name --content-disposition https://huggingface.co/housearch/thu/resolve/main/trainFlux/download_caption_flux.py
wget --trust-server-name --content-disposition https://huggingface.co/housearch/thu/resolve/main/trainFlux/config_lora_b8base_flux.toml
wget --trust-server-name --content-disposition https://huggingface.co/housearch/thu/resolve/main/trainFlux/prompt.txt
cd /workspace
python -m venv env
source /workspace/env/bin/activate
pip install datasets huggingface_hub Pillow
python download_caption_flux.py
deactivate
cd /workspace
git clone https://github.com/kohya-ss/sd-scripts
cd sd-scripts
#預設是訓練SD1.5, SDXL的版本,如果要訓練SD3, Flux 必須切換至sd3
git branch -a
git checkout sd3
'''
另開 terminal 視窗,把以下內容貼上並按下enter執行,直接下載訓練Flux LoRA必須的相關模型(節省時間)
wget --trust-server-name --content-disposition https://huggingface.co/realung/flux1-dev.safetensors/resolve/main/flux1-dev.safetensors
wget --trust-server-name --content-disposition https://huggingface.co/comfyanonymous/flux_text_encoders/resolve/main/t5xxl_fp16.safetensors
wget --trust-server-name --content-disposition https://huggingface.co/comfyanonymous/flux_text_encoders/resolve/main/clip_l.safetensors
wget --trust-server-name --content-disposition https://huggingface.co/StableDiffusionVN/Flux/resolve/main/Vae/flux_vae.safetensors
'''
cd /workspace/sd-scripts
python -m venv env
source /workspace/sd-scripts/env/bin/activate
pip3 install torch==2.4.0 torchvision==0.19.0 --index-url https://download.pytorch.org/whl/cu124
pip install --upgrade -r requirements.txt
mkdir /workspace/train/
mkdir /workspace/train/img
mkdir /workspace/train/log
mkdir /workspace/train/model
mkdir /workspace/train/model/sample
cp -R /workspace/datasets /workspace/train/img/1_overhedlandscape
cp /workspace/prompt.txt /workspace/train/model/sample/prompt.txt
'''
訓練的資料夾重複數設為1
accelerate launch --multi_gpu --dynamo_backend no --dynamo_mode default --mixed_precision bf16 --gpu_ids 0,1,2 --num_processes 3 --num_machines 1 --num_cpu_threads_per_process 2 flux_train_network.py --config_file /workspace/config_lora_b8base_flux.toml
tensorboard --host 0.0.0.0 --logdir=/workspace/train/log
'''
cd /workspace/sd-scripts
source /workspace/sd-scripts/env/bin/activate