方案一

1
2
3
4
5
6
7
8
9
10
11
12
git clone https://github.com/bmaltais/kohya_ss.git
cd kohya_ss
python3 -m venv venv
source venv/bin/activate
./setup.sh
pip uninstall tensorboard tensorboard-data-server tensorboard-plugin-wit tensorflow tensorflow-estimator tensorflow-macos torch torchaudio torchmetrics torchvision
pip install torch torchvision torchaudio torchmetrics
pip install tensorflow
pip3 install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/cpu
pip install tensorflow torchmetrics
pip install -U -r requirements.txt
./gui.sh

方案二

步骤1.下载包并预热python。

1
2
3
4
5
6
7
git clone https://github.com/bmaltais/kohya_ss.git
cd kohya_ss

python -m venv venv
source venv/bin/activate
pip torch==2.0.0 torchvision==0.15.1
python -m pip install tensorflow-macos

步骤2.修改要求以避免GPU。

  1. requirements.txt -不要安装onnxruntime-gpu,而是安装onnxruntime
1
2
3
4
...
# onnxruntime-gpu==1.16.0
onnxruntime==1.16.0
...
  1. requirements_macos_arm64.txt -删除tensorflow-metal
1
2
3
4
torch==2.0.0 torchvision==0.15.1 -f https://download.pytorch.org/whl/cpu/torch_stable.html
xformers bitsandbytes==0.41.1
tensorflow-macos tensorboard==2.14.1
-r requirements.txt

步骤3.设置

1
./setup.sh

方案三

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# metal用のpytorchをインストール
pip3 install torch torchvision

# metal用のtensorflowをインストール
conda install -c apple tensorflow-deps
pip3 install tensorflow-macos tensorflow-metal tensorboard

# diffusersのインストール
pip install diffusers

# LoRAの学習用コードをダウンロード
git clone https://github.com/bmaltais/kohya_ss.git
cd kohya_ss

# requirements.txt の tensorflow, tensorboard はコメントアウトする
pip install -r requirements.txt

加速器设置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
accelerate config  # 终端输入命令

In which compute environment are you running?
Please select a choice using the arrow or number keys, and selecting with enter
➔ This machine
AWS (Amazon SageMaker)

Which type of machine are you using?
➔ No distributed training
multi-CPU
multi-GPU
TPU

Do you want to run your training on CPU only (even if a GPU / Apple Silicon / Ascend NPU device is available)? [yes/NO]:NO

Do you wish to optimize your script with torch dynamo?[yes/NO]:NO

Do you wish to use FP16 or BF16 (mixed precision)?
Please select a choice using the arrow or number keys, and selecting with enter
➔ no
fp16
bf16
fp8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

command_file: null
commands: null
compute_environment: LOCAL_MACHINE
deepspeed_config: {}
distributed_type: MPS
downcast_bf16: 'NO'
dynamo_backend: 'NO'
fsdp_config: {}
gpu_ids: null
machine_rank: 0
main_process_ip: null
main_process_port: null
main_training_function: main
megatron_lm_config: {}
mixed_precision: 'NO'
num_machines: 1
num_processes: 1
rdzv_backend: static
same_network: true
tpu_name: null
tpu_zone: null
use_cpu: false