Support : OFT merge to base model #1580
Merged
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.
既存のsdxl_merge_lora.pyに対して、
OFTをベースモデルへマージできるように機能追加しました。
Additional Changes
1.OFT学習結果のベースモデルへのマージ対応
複数のOFTのマージは非対応。
2.並列処理による高速化
import concurrent.futuresを用いることで、並列処理化。
OFTはLoRAと比べて、CPUでのマージが長いので並列処理を追加しました(※1)
3. CUDA対応
torch.device('cuda' ・・・行の追加により、CUDAでマージ処理できます(※2)
No.2,3はOFTのみ対応しています。LoRAには非対応です。
理由は、校閲が難しくならないよう情報を小出しにしただけです。変更自体は簡単です(数行書き換えるだけ?)
補足
・ 設計当初、sdxl_merge_lora.pyと独立したスクリプトとして作成を検討しましたが、
OFTは従来sdxl向けの学習方式なので同じ用途ですし、また共有できるライブラリが多いので、
統合する方が使いまわしやすいと考えました。
皆様のご意見を踏まえて対応します。
・ FLUX.1の期待が高まる現在、今さらOFTのマージの提案ではありますが、
VRAM10GB~16GBクラスにおいて、実用面を考慮すると、SDXLとOFTは最高クラスの組み合わせです(※3)。OFT普及のためにぜひ承認をお願いします。
動作確認結果
Lora @ extension for Stable Diffusion web UI と同等画風で、ほぼ同じ構図が出ることを確認済み。
※1:CPU利用の場合、私の環境ではCPU占有率が上がらず1hr以上かかりましたが、並列化によってマージ時間を25%に短縮できました。
※2:変数Rを適用する処理が30min→1secに短縮されました。
※3:VRAM14GB以下だとSDXL Fine tuning は利用困難。LoConや学習層削減するとクオリティ低下が顕著です。
一方、OFTは直行性を考慮した計算効率の高さゆえに、Fine tuningと同等の忠実さ、LoConと同程度のVRAMコストというメリットがあります。
しかしながら、ベースモデルにマージする手段がないため、繰り返しの学習が難しいです。OFTのマージが重要だと判断しました。