The easy practice to train Lora model & evaluate it is to using stable diffusion webui, https://github.com/AUTOMATIC1111/stable-diffusion-webui/tree/master, and install extension sd-webui-train-tools, https://github.com/liasece/sd-webui-train-tools. But after installed extension, following instruction to train lora model, there is a error happened can cause lora training failed. The error is when importlib networks.lora, it reports networks.lora not a module.
I spend some time to investigate the reason and try fix it. Google cannot find a solution. From the error, it looks that module path is not in system path. But after append module path into system path. The error still is there. After debug, finally find it is a bug in https://github.com/liasece/sd-webui-train-tools/blob/main/liasece_sd_webui_train_tools/train.py. In the following function, sub_module="library" is wrong. Correct value is None. After set sub_module=None (or remove the argument because default is None), Lora training starts
def train(cfg: ArgStore) -> None:
args = cfg.create_args()
with pc.PythonContextWarper(
to_module_path= os.path.abspath(os.path.join(os.path.dirname(__file__), "sd_scripts")),
path_include= os.path.abspath(os.path.join(os.path.dirname(__file__), "..")),
sub_module="library",
):
# begin training
train_network.train(args)
Correct version:
def train(cfg: ArgStore) -> None:
args = cfg.create_args()
with pc.PythonContextWarper(
to_module_path= os.path.abspath(os.path.join(os.path.dirname(__file__), "sd_scripts")),
path_include= os.path.abspath(os.path.join(os.path.dirname(__file__), "..")),
sub_module=None,
):
# begin training
train_network.train(args)