Large-scale refactoring has been merged into main — migration guide inside #2358
kohya-ss
announced in
Announcements
Replies: 1 comment
-
|
great news. i was planning to make a fork to add few stuff so i can do once this is done |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Update (2026-06-12): The refactoring has been merged into main via #2372. See the migration guide at the bottom of this post. If anything broke for you after updating, please reply here.
更新 (2026-06-12): リファクタリングは #2372 により main にマージされました。本投稿末尾の移行ガイドをご確認ください。更新後に動作がおかしい点があれば、このスレッドで返信をお願いします。
Thank you for using and contributing to this repository.
A large-scale internal refactoring is currently in progress and is nearing completion. We plan to merge it into
mainsoon.The user-facing interface of each script (script names, command-line options, dataset configuration, etc.) is essentially unchanged, so you can continue using the scripts as before.
On the implementation side, the architecture-specific classes are largely preserved, but the internal APIs (base classes, utility modules, etc.) have changed significantly. Maintainers of forks and dependent tools are kindly asked to review their code after the merge.
After the merge, a migration guide outlining the main changes and old-to-new mappings will be added to this discussion.
Since the refactoring is still in progress, we would appreciate it if pull requests that touch the common parts could be submitted after the refactoring has been merged.
There may be some temporary inconvenience, but we appreciate your understanding, as this work aims to improve long-term maintainability. Thank you.
日本語
いつも当リポジトリをご利用いただき、また多数の貢献をいただき、ありがとうございます。
現在、大規模な内部リファクタリングを進めており、間もなく完了する見込みです。近日中に
mainへのマージを予定しています。各スクリプト利用時のインターフェース(スクリプト名、コマンドラインオプション、データセット設定など)には基本的には変更ありませんので、そのままお使いいただけます。
実装面では、各アーキテクチャのクラスは基本的に維持されていますが、内部のAPI(基底クラスやユーティリティモジュールなど)は大きく変更されています。そのため、forkされたリポジトリや、依存ツールのメンテナの方々におかれましては、マージ後に確認をお願いいたします。
マージ後に、主要な変更点や新旧の対応を示した移行ガイドをこのdiscussionに追加する予定です。
pull requestにつきまして、リファクタリングが進行中のため、共通部分に関するpull requestはリファクタリングのマージ後にご提出いただければ幸いです。
一時的にご不便をおかけする場面もあるかもしれませんが、将来的な保守性を向上させるための取り組みとしてご理解いただければ幸いです。よろしくお願いいたします。
Migration Guide for the Large-Scale Refactoring (PR #2372)
Overview (English)
A large-scale internal refactoring (PR #2372, "Refactor for ai agents") has been merged into
main.library/train_util.py(~7,000 lines) into 15 focused modules by responsibility.library/train_util.pyitself remains as a backward-compatible shim that re-exports all symbols. Access viafrom library import train_utiland attribute reads such astrain_util.HIGH_VRAMcontinue to work.Who is affected
library.train_utilare preserved by the shim, but the canonical locations have movedtrain_util.pysplit — symbol relocation tableFunctionality in
library/train_util.pymoved to the modules below. Imports viatrain_utilstill work, but new code should import from the new home.Open the symbol relocation table
library.accelerator_setupenable_high_vram,prepare_accelerator,prepare_dtype,prepare_dataset_args,patch_accelerator_for_fp16_training,HIGH_VRAMlibrary.argsadd_sd_models_arguments,add_optimizer_arguments,add_training_arguments,add_dataset_arguments,add_sd_saving_arguments,add_masked_loss_arguments,add_dit_training_arguments,verify_training_args,verify_command_line_training_args,read_config_from_file,get_sanitized_config_or_none,resume_from_local_or_hf_if_specifiedlibrary.optimizerget_optimizer,get_optimizer_train_eval_fn,is_schedulefree_optimizer,get_scheduler_fix,get_dummy_scheduler,append_lr_to_logs,append_lr_to_logs_with_nameslibrary.lossget_timesteps,get_noise_noisy_latents_and_timesteps,get_huber_threshold_if_needed,conditional_losslibrary.datasetBaseDataset,DatasetGroup,MinimalDataset,BucketManager,BucketBatchIndex,ImageInfo,AugHelper,collator_class,load_arbitrary_dataset,debug_dataset,split_train_val,glob_images,glob_images_pathlib,load_image,IMAGE_EXTENSIONS,IMAGE_TRANSFORMSlibrary.subsetBaseSubset,DreamBoothSubset,FineTuningSubset,ControlNetSubsetlibrary.dreambooth_datasetDreamBoothDatasetlibrary.finetuning_datasetFineTuningDatasetlibrary.controlnet_datasetControlNetDatasetlibrary.cachingcache_batch_latents,is_disk_cached_latents_is_expected,trim_and_resize_if_required,load_images_and_masks_for_cachinglibrary.model_ioload_target_model,replace_unet_modules,model_hash,calculate_sha256,precalculate_safetensors_hashes,addnet_hash_legacy,addnet_hash_safetensors,get_git_revision_hash,load_metadata_from_safetensors,get_sai_model_spec,build_minimum_network_metadata,SS_METADATA_*constantslibrary.checkpoint_iosave_sd_model_on_epoch_end_or_stepwise,save_sd_model_on_train_end,save_and_remove_state_on_epoch_end,save_and_remove_state_stepwise,save_state_on_train_end,get_epoch_ckpt_name,get_step_ckpt_name,get_last_ckpt_name,default_if_none,EPOCH_*/STEP_*/LAST_STATE_NAMEconstantslibrary.samplingsample_images,sample_images_common,sample_image_inference,get_my_scheduler,load_prompts,line_to_prompt_dict,SCHEDULER_*constantslibrary.hidden_statesget_hidden_states,get_hidden_states_sdxl,pool_workaroundlibrary.logging_utilinit_trackers,LossRecorderRemoved / renamed scripts
These affect user-facing invocations. Update if you ran them directly.
train_controlnet.pytrain_control_net.py(the old name was a duplicate that already emitted a deprecation warning)train_textual_inversion_XTI.py/XTI_hijack.pytrain_textual_inversion.py/sdxl_train_textual_inversion.pyfor standard Textual Inversionsdxl_train_control_net_lllite_old.pysdxl_train_control_net_lllite.pynetworks/merge_lora_old.pynetworks/merge_lora.pybitsandbytes_windows/(bundled DLLs)bitsandbytessupports Windows officially, so they are no longer neededFine-tuning dataset metadata specification
The metadata file format read by the fine-tuning dataset (a subset with
metadata_file, equivalent to the--in_jsoncommand-line argument) is now formally specified in the new documentdocs/dataset_metadata.md.library/finetuning_dataset.py(caption/tags/image_size); everything else is silently ignored. Both.jsonand.jsonlare supported.finetune/(make_captions.py(BLIP),merge_captions_to_metadata.py,merge_dd_tags_to_metadata.py,clean_captions_and_tags.py,prepare_buckets_latents.py, etc.) are now deprecated. The files remain in the repository, but their content is outdated (e.g. BLIP captioning no longer works). Going forward we specify only the metadata format, not the means of generating it. See "メタデータファイルの作成" indocs/train_README-ja.mdfor details.Tests
tests/test_train*.py,tests/test_sdxl_train*.py,tests/test_flux_train*.py,tests/test_sd3_train*.py, etc.) were removed.tools/dev/.Recommended actions (forks / extensions)
library.train_utilkeep working for now, but please update them to import directly from the new modules per the relocation table.main.We appreciate your patience — these changes are intended to improve long-term maintainability. Please report any issues in this Discussion.
日本語
概要
大規模な内部リファクタリング(PR #2372 "Refactor for ai agents")を
mainにマージしました。library/train_util.py(約7,000行)を、役割ごとの15個のモジュールに分割したことです。library/train_util.py自体は、全シンボルを再エクスポートする後方互換 shim として残しています。from library import train_util経由のアクセスやtrain_util.HIGH_VRAMのような属性参照も、これまでどおり動作します。影響範囲
library.train_util経由の import は shim により維持。ただし正規の置き場所(canonical location)が移動しましたtrain_util.pyの分割 — シンボル再配置表library/train_util.pyの各機能は、以下のモジュールに移動しました。train_util経由でも引き続き import できますが、新規コードは移動先から直接 import してください。シンボル再配置表を開く
library.accelerator_setupenable_high_vram,prepare_accelerator,prepare_dtype,prepare_dataset_args,patch_accelerator_for_fp16_training,HIGH_VRAMlibrary.argsadd_sd_models_arguments,add_optimizer_arguments,add_training_arguments,add_dataset_arguments,add_sd_saving_arguments,add_masked_loss_arguments,add_dit_training_arguments,verify_training_args,verify_command_line_training_args,read_config_from_file,get_sanitized_config_or_none,resume_from_local_or_hf_if_specifiedlibrary.optimizerget_optimizer,get_optimizer_train_eval_fn,is_schedulefree_optimizer,get_scheduler_fix,get_dummy_scheduler,append_lr_to_logs,append_lr_to_logs_with_nameslibrary.lossget_timesteps,get_noise_noisy_latents_and_timesteps,get_huber_threshold_if_needed,conditional_losslibrary.datasetBaseDataset,DatasetGroup,MinimalDataset,BucketManager,BucketBatchIndex,ImageInfo,AugHelper,collator_class,load_arbitrary_dataset,debug_dataset,split_train_val,glob_images,glob_images_pathlib,load_image,IMAGE_EXTENSIONS,IMAGE_TRANSFORMSlibrary.subsetBaseSubset,DreamBoothSubset,FineTuningSubset,ControlNetSubsetlibrary.dreambooth_datasetDreamBoothDatasetlibrary.finetuning_datasetFineTuningDatasetlibrary.controlnet_datasetControlNetDatasetlibrary.cachingcache_batch_latents,is_disk_cached_latents_is_expected,trim_and_resize_if_required,load_images_and_masks_for_cachinglibrary.model_ioload_target_model,replace_unet_modules,model_hash,calculate_sha256,precalculate_safetensors_hashes,addnet_hash_legacy,addnet_hash_safetensors,get_git_revision_hash,load_metadata_from_safetensors,get_sai_model_spec,build_minimum_network_metadata,SS_METADATA_*定数library.checkpoint_iosave_sd_model_on_epoch_end_or_stepwise,save_sd_model_on_train_end,save_and_remove_state_on_epoch_end,save_and_remove_state_stepwise,save_state_on_train_end,get_epoch_ckpt_name,get_step_ckpt_name,get_last_ckpt_name,default_if_none,EPOCH_*/STEP_*/LAST_STATE_NAMEなどの定数library.samplingsample_images,sample_images_common,sample_image_inference,get_my_scheduler,load_prompts,line_to_prompt_dict,SCHEDULER_*定数library.hidden_statesget_hidden_states,get_hidden_states_sdxl,pool_workaroundlibrary.logging_utilinit_trackers,LossRecorder削除・改名されたスクリプト
以下はユーザー向けの呼び出しに影響します。該当スクリプトを直接実行していた場合は変更してください。
train_controlnet.pytrain_control_net.pyを使用してください(旧名は以前から非推奨警告を出していた重複スクリプトです)train_textual_inversion_XTI.py/XTI_hijack.pytrain_textual_inversion.py/sdxl_train_textual_inversion.pyを使用してくださいsdxl_train_control_net_lllite_old.pysdxl_train_control_net_lllite.pyを使用してくださいnetworks/merge_lora_old.pynetworks/merge_lora.pyを使用してくださいbitsandbytes_windows/(同梱 DLL 一式)bitsandbytesは Windows を公式サポートしているため不要ですfine-tuning データセットのメタデータ仕様
fine-tuning 方式のデータセット(サブセットに
metadata_fileを指定、またはコマンドライン引数--in_json相当)が読み込むメタデータファイルの形式を、新ドキュメントdocs/dataset_metadata.mdで明文化しました。library/finetuning_dataset.pyがパースする 3 フィールド(caption/tags/image_size)のみで、それ以外は黙って無視されます。.json/.jsonlの両形式に対応します。finetune/フォルダ内のスクリプト(make_captions.py(BLIP)、merge_captions_to_metadata.py、merge_dd_tags_to_metadata.py、clean_captions_and_tags.py、prepare_buckets_latents.pyなど)は非推奨となりました。ファイル自体はリポジトリに残っていますが、BLIP によるキャプショニングが現在は動作しないなど内容が古くなっています。今後はメタデータの「形式」のみを仕様とし、生成手段は規定しません。詳細はdocs/train_README-ja.mdの「メタデータファイルの作成」を参照してください。テスト
tests/test_train*.py,tests/test_sdxl_train*.py,tests/test_flux_train*.py,tests/test_sd3_train*.pyなど)は削除しました。tools/dev/に移動しました。推奨対応(fork・拡張開発者向け)
library.train_utilから import している箇所は当面そのまま動きますが、上記の再配置表に従って新しいモジュールから直接 import するよう更新することを推奨します。ご不便をおかけしますが、これらの変更は長期的な保守性向上のためのものです。問題があればこの Discussion でお知らせください。
Beta Was this translation helpful? Give feedback.
All reactions