Skip to content

Commit e4d9e3c

Browse files
committed
remove dependency for omegaconf #ref 1284
1 parent de0e0b9 commit e4d9e3c

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

Diff for: README.md

+4
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ The majority of scripts is licensed under ASL 2.0 (including codes from Diffuser
167167

168168
- Training scripts can now output training settings to wandb or Tensor Board logs. Specify the `--log_config` option. PR [#1285](https://github.com/kohya-ss/sd-scripts/pull/1285) Thanks to ccharest93, plucked, rockerBOO, and VelocityRa!
169169
- Some settings, such as API keys and directory specifications, are not output due to security issues.
170+
171+
- The ControlNet training script `train_controlnet.py` for SD1.5/2.x was not working, but it has been fixed. PR [#1284](https://github.com/kohya-ss/sd-scripts/pull/1284) Thanks to sdbds!
170172

171173
- An option `--disable_mmap_load_safetensors` is added to disable memory mapping when loading the model's .safetensors in SDXL. PR [#1266](https://github.com/kohya-ss/sd-scripts/pull/1266) Thanks to Zovjsra!
172174
- It seems that the model file loading is faster in the WSL environment etc.
@@ -215,6 +217,8 @@ https://github.com/kohya-ss/sd-scripts/pull/1290) Thanks to frodo821!
215217
- 各学習スクリプトで学習設定を wandb や Tensor Board などのログに出力できるようになりました。`--log_config` オプションを指定してください。PR [#1285](https://github.com/kohya-ss/sd-scripts/pull/1285) ccharest93 氏、plucked 氏、rockerBOO 氏および VelocityRa 氏に感謝します。
216218
- API キーや各種ディレクトリ指定など、一部の設定はセキュリティ上の問題があるため出力されません。
217219

220+
- SD1.5/2.x 用の ControlNet 学習スクリプト `train_controlnet.py` が動作しなくなっていたのが修正されました。PR [#1284](https://github.com/kohya-ss/sd-scripts/pull/1284) sdbds 氏に感謝します。
221+
218222
- SDXL でモデルの .safetensors を読み込む際にメモリマッピングを無効化するオプション `--disable_mmap_load_safetensors` が追加されました。PR [#1266](https://github.com/kohya-ss/sd-scripts/pull/1266) Zovjsra 氏に感謝します。
219223
- WSL 環境等でモデルファイルの読み込みが高速化されるようです。
220224
- `sdxl_train.py``sdxl_train_network.py``sdxl_train_textual_inversion.py``sdxl_train_control_net_lllite.py` で使用可能です。

Diff for: requirements.txt

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ easygui==0.98.3
1717
toml==0.10.2
1818
voluptuous==0.13.1
1919
huggingface-hub==0.20.1
20-
omegaconf==2.3.0
2120
# for Image utils
2221
imagesize==1.4.1
2322
# for BLIP captioning

Diff for: train_controlnet.py

+31-7
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@
55
import random
66
import time
77
from multiprocessing import Value
8-
from omegaconf import OmegaConf
8+
9+
# from omegaconf import OmegaConf
910
import toml
1011

1112
from tqdm import tqdm
1213

1314
import torch
1415
from library import deepspeed_utils
1516
from library.device_utils import init_ipex, clean_memory_on_device
17+
1618
init_ipex()
1719

1820
from torch.nn.parallel import DistributedDataParallel as DDP
@@ -197,7 +199,23 @@ def train(args):
197199
"resnet_time_scale_shift": "default",
198200
"projection_class_embeddings_input_dim": None,
199201
}
200-
unet.config = OmegaConf.create(unet.config)
202+
# unet.config = OmegaConf.create(unet.config)
203+
204+
# make unet.config iterable and accessible by attribute
205+
class CustomConfig:
206+
def __init__(self, **kwargs):
207+
self.__dict__.update(kwargs)
208+
209+
def __getattr__(self, name):
210+
if name in self.__dict__:
211+
return self.__dict__[name]
212+
else:
213+
raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{name}'")
214+
215+
def __contains__(self, name):
216+
return name in self.__dict__
217+
218+
unet.config = CustomConfig(**unet.config)
201219

202220
controlnet = ControlNetModel.from_unet(unet)
203221

@@ -230,7 +248,7 @@ def train(args):
230248
)
231249
vae.to("cpu")
232250
clean_memory_on_device(accelerator.device)
233-
251+
234252
accelerator.wait_for_everyone()
235253

236254
if args.gradient_checkpointing:
@@ -239,7 +257,7 @@ def train(args):
239257
# 学習に必要なクラスを準備する
240258
accelerator.print("prepare optimizer, data loader etc.")
241259

242-
trainable_params = controlnet.parameters()
260+
trainable_params = list(controlnet.parameters())
243261

244262
_, _, optimizer = train_util.get_optimizer(args, trainable_params)
245263

@@ -348,7 +366,9 @@ def train(args):
348366
if args.log_tracker_config is not None:
349367
init_kwargs = toml.load(args.log_tracker_config)
350368
accelerator.init_trackers(
351-
"controlnet_train" if args.log_tracker_name is None else args.log_tracker_name, config=train_util.get_sanitized_config_or_none(args), init_kwargs=init_kwargs
369+
"controlnet_train" if args.log_tracker_name is None else args.log_tracker_name,
370+
config=train_util.get_sanitized_config_or_none(args),
371+
init_kwargs=init_kwargs,
352372
)
353373

354374
loss_recorder = train_util.LossRecorder()
@@ -424,7 +444,9 @@ def remove_model(old_ckpt_name):
424444
)
425445

426446
# Sample a random timestep for each image
427-
timesteps, huber_c = train_util.get_timesteps_and_huber_c(args, 0, noise_scheduler.config.num_train_timesteps, noise_scheduler, b_size, latents.device)
447+
timesteps, huber_c = train_util.get_timesteps_and_huber_c(
448+
args, 0, noise_scheduler.config.num_train_timesteps, noise_scheduler, b_size, latents.device
449+
)
428450

429451
# Add noise to the latents according to the noise magnitude at each timestep
430452
# (this is the forward diffusion process)
@@ -456,7 +478,9 @@ def remove_model(old_ckpt_name):
456478
else:
457479
target = noise
458480

459-
loss = train_util.conditional_loss(noise_pred.float(), target.float(), reduction="none", loss_type=args.loss_type, huber_c=huber_c)
481+
loss = train_util.conditional_loss(
482+
noise_pred.float(), target.float(), reduction="none", loss_type=args.loss_type, huber_c=huber_c
483+
)
460484
loss = loss.mean([1, 2, 3])
461485

462486
loss_weights = batch["loss_weights"] # 各sampleごとのweight

0 commit comments

Comments
 (0)