mirror of
https://github.com/kohya-ss/sd-scripts.git
synced 2026-04-08 22:35:09 +00:00
feat: added function to load training config with .toml
This commit is contained in:
21
fine_tune.py
21
fine_tune.py
@@ -5,6 +5,7 @@ import argparse
|
||||
import gc
|
||||
import math
|
||||
import os
|
||||
import toml
|
||||
|
||||
from tqdm import tqdm
|
||||
import torch
|
||||
@@ -362,4 +363,24 @@ if __name__ == '__main__':
|
||||
parser.add_argument("--train_text_encoder", action="store_true", help="train text encoder / text encoderも学習する")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.config_file:
|
||||
config_path = args.config_file + ".toml" if not args.config_file.endswith(".toml") else args.config_file
|
||||
if os.path.exists(config_path):
|
||||
print(f"Loading settings from {config_path}...")
|
||||
with open(config_path, "r") as f:
|
||||
config_dict = toml.load(f)
|
||||
|
||||
ignore_nesting_dict = {}
|
||||
for section_name, section_dict in config_dict.items():
|
||||
for key, value in section_dict.items():
|
||||
ignore_nesting_dict[key] = value
|
||||
|
||||
config_args = argparse.Namespace(**ignore_nesting_dict)
|
||||
args = parser.parse_args(namespace=config_args)
|
||||
args.config_file = args.config_file.split(".")[0]
|
||||
print(args.config_file)
|
||||
else:
|
||||
print(f"{config_path} not found.")
|
||||
|
||||
train(args)
|
||||
|
||||
Reference in New Issue
Block a user