mirror of
https://github.com/kohya-ss/sd-scripts.git
synced 2026-04-08 22:35:09 +00:00
fix placing of requires_grad_ of U-Net
This commit is contained in:
@@ -12,10 +12,13 @@ import toml
|
|||||||
|
|
||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
import torch
|
import torch
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import intel_extension_for_pytorch as ipex
|
import intel_extension_for_pytorch as ipex
|
||||||
|
|
||||||
if torch.xpu.is_available():
|
if torch.xpu.is_available():
|
||||||
from library.ipex import ipex_init
|
from library.ipex import ipex_init
|
||||||
|
|
||||||
ipex_init()
|
ipex_init()
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
@@ -428,8 +431,10 @@ class NetworkTrainer:
|
|||||||
# set top parameter requires_grad = True for gradient checkpointing works
|
# set top parameter requires_grad = True for gradient checkpointing works
|
||||||
if train_text_encoder:
|
if train_text_encoder:
|
||||||
t_enc.text_model.embeddings.requires_grad_(True)
|
t_enc.text_model.embeddings.requires_grad_(True)
|
||||||
else:
|
|
||||||
unet.parameters().__next__().requires_grad_(True)
|
# set top parameter requires_grad = True for gradient checkpointing works
|
||||||
|
if not train_text_encoder: # train U-Net only
|
||||||
|
unet.parameters().__next__().requires_grad_(True)
|
||||||
else:
|
else:
|
||||||
unet.eval()
|
unet.eval()
|
||||||
for t_enc in text_encoders:
|
for t_enc in text_encoders:
|
||||||
|
|||||||
Reference in New Issue
Block a user