Add option to train TE MLP layers only[再]#13
Merged
maruo555 merged 1 commit intomaruo-mainfrom May 23, 2025
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
add --te_mlp_fc_only option to sdxl_train_network.py
patch training routine to restrict Text Encoder LoRA layers to CLIPMLP
本家の「Fix missing text encoder attn modules
kohya-ss#1964
で直る前の状態にしたいときのオプション。
解説(日本語)
sdxl_train_network.py に新しいオプション --te_mlp_fc_only が追加されました。
このフラグが指定されると、Text Encoder で LoRA により学習する対象モジュールが CLIPMLP のみとなります。
追加された処理では、引数 network_module で指定されたネットワークモジュールを動的に import し、そこに定義されている LoRANetwork.TEXT_ENCODER_TARGET_REPLACE_MODULE を ["CLIPMLP"] に上書きしています。
これによって、通常は "CLIPAttention" や "CLIPSdpaAttention" も対象となるところが、CLIPMLP のみが置き換え対象となり、mlp_fc1 / mlp_fc2 の層だけが学習されるようになります。
LoRA の既定の対象モジュールは networks/lora.py で定義されており、デフォルトでは ["CLIPAttention", "CLIPSdpaAttention", "CLIPMLP"] となっています。
CLI 引数としては、parser に以下のオプションが追加されています。
--te_mlp_fc_only
これを指定して学習を実行すると、Text Encoder のうち mlp_fc1 と mlp_fc2 だけに LoRA 層が挿入され、他の self_attn_* 系の層は学習対象になりません。
元の LoRA 実装では target リストに含まれるモジュールだけが変換されるため、この変数を変更するだけで目的の動作が実現できます。 mlp_fc1 と mlp_fc2 だけを学習させることができます。
こんな時は MLP のみをおすすめ
→ Attention 部分まで重ねると干渉しやすいので、MLP のみが安全
→ 単語重みの再スケールだけで十分表現できる場合が多い
→ 軽量 LoRA の方がロードも高速
逆に Attention + MLP を残した方が良いケース
• 複雑な情景指示を 1 行プロンプトで完結させたい
• 「タグの重複・順序」を細かく弄って表情/視線を調整する
•ControlNet なしでポーズを頑張りたい (TE Attention の変調が効くこと有)