summaryrefslogtreecommitdiffstats
path: root/training/strategy
diff options
context:
space:
mode:
authorVolpeon <git@volpeon.ink>2023-03-23 11:07:57 +0100
committerVolpeon <git@volpeon.ink>2023-03-23 11:07:57 +0100
commit0767c7bc82645186159965c2a6be4278e33c6721 (patch)
treea136470ab85dbb99ab51d9be4a7831fe21612ab3 /training/strategy
parentFix (diff)
downloadtextual-inversion-diff-0767c7bc82645186159965c2a6be4278e33c6721.tar.gz
textual-inversion-diff-0767c7bc82645186159965c2a6be4278e33c6721.tar.bz2
textual-inversion-diff-0767c7bc82645186159965c2a6be4278e33c6721.zip
Update
Diffstat (limited to 'training/strategy')
-rw-r--r--training/strategy/dreambooth.py8
-rw-r--r--training/strategy/lora.py12
-rw-r--r--training/strategy/ti.py4
3 files changed, 12 insertions, 12 deletions
diff --git a/training/strategy/dreambooth.py b/training/strategy/dreambooth.py
index e5e84c8..28fccff 100644
--- a/training/strategy/dreambooth.py
+++ b/training/strategy/dreambooth.py
@@ -137,8 +137,8 @@ def dreambooth_strategy_callbacks(
137 137
138 print("Saving model...") 138 print("Saving model...")
139 139
140 unet_ = accelerator.unwrap_model(unet, False) 140 unet_ = accelerator.unwrap_model(unet, keep_fp32_wrapper=False)
141 text_encoder_ = accelerator.unwrap_model(text_encoder, False) 141 text_encoder_ = accelerator.unwrap_model(text_encoder, keep_fp32_wrapper=False)
142 142
143 with ema_context(): 143 with ema_context():
144 pipeline = VlpnStableDiffusion( 144 pipeline = VlpnStableDiffusion(
@@ -160,8 +160,8 @@ def dreambooth_strategy_callbacks(
160 @torch.no_grad() 160 @torch.no_grad()
161 def on_sample(step): 161 def on_sample(step):
162 with ema_context(): 162 with ema_context():
163 unet_ = accelerator.unwrap_model(unet, False) 163 unet_ = accelerator.unwrap_model(unet, keep_fp32_wrapper=True)
164 text_encoder_ = accelerator.unwrap_model(text_encoder, False) 164 text_encoder_ = accelerator.unwrap_model(text_encoder, keep_fp32_wrapper=True)
165 165
166 orig_unet_dtype = unet_.dtype 166 orig_unet_dtype = unet_.dtype
167 orig_text_encoder_dtype = text_encoder_.dtype 167 orig_text_encoder_dtype = text_encoder_.dtype
diff --git a/training/strategy/lora.py b/training/strategy/lora.py
index aa75bec..1c8fad6 100644
--- a/training/strategy/lora.py
+++ b/training/strategy/lora.py
@@ -47,7 +47,6 @@ def lora_strategy_callbacks(
47 save_samples_ = partial( 47 save_samples_ = partial(
48 save_samples, 48 save_samples,
49 accelerator=accelerator, 49 accelerator=accelerator,
50 text_encoder=text_encoder,
51 tokenizer=tokenizer, 50 tokenizer=tokenizer,
52 vae=vae, 51 vae=vae,
53 sample_scheduler=sample_scheduler, 52 sample_scheduler=sample_scheduler,
@@ -72,6 +71,7 @@ def lora_strategy_callbacks(
72 @contextmanager 71 @contextmanager
73 def on_train(epoch: int): 72 def on_train(epoch: int):
74 tokenizer.train() 73 tokenizer.train()
74 text_encoder.train()
75 yield 75 yield
76 76
77 @contextmanager 77 @contextmanager
@@ -89,8 +89,8 @@ def lora_strategy_callbacks(
89 def on_checkpoint(step, postfix): 89 def on_checkpoint(step, postfix):
90 print(f"Saving checkpoint for step {step}...") 90 print(f"Saving checkpoint for step {step}...")
91 91
92 unet_ = accelerator.unwrap_model(unet, False) 92 unet_ = accelerator.unwrap_model(unet, keep_fp32_wrapper=False)
93 text_encoder_ = accelerator.unwrap_model(text_encoder, False) 93 text_encoder_ = accelerator.unwrap_model(text_encoder, keep_fp32_wrapper=False)
94 94
95 lora_config = {} 95 lora_config = {}
96 state_dict = get_peft_model_state_dict(unet, state_dict=accelerator.get_state_dict(unet)) 96 state_dict = get_peft_model_state_dict(unet, state_dict=accelerator.get_state_dict(unet))
@@ -111,10 +111,10 @@ def lora_strategy_callbacks(
111 111
112 @torch.no_grad() 112 @torch.no_grad()
113 def on_sample(step): 113 def on_sample(step):
114 unet_ = accelerator.unwrap_model(unet, False) 114 unet_ = accelerator.unwrap_model(unet, keep_fp32_wrapper=True)
115 text_encoder_ = accelerator.unwrap_model(text_encoder, False) 115 text_encoder_ = accelerator.unwrap_model(text_encoder, keep_fp32_wrapper=True)
116 116
117 save_samples_(step=step, unet=unet_) 117 save_samples_(step=step, unet=unet_, text_encoder=text_encoder_)
118 118
119 del unet_ 119 del unet_
120 del text_encoder_ 120 del text_encoder_
diff --git a/training/strategy/ti.py b/training/strategy/ti.py
index bd0d178..2038e34 100644
--- a/training/strategy/ti.py
+++ b/training/strategy/ti.py
@@ -156,8 +156,8 @@ def textual_inversion_strategy_callbacks(
156 @torch.no_grad() 156 @torch.no_grad()
157 def on_sample(step): 157 def on_sample(step):
158 with ema_context(): 158 with ema_context():
159 unet_ = accelerator.unwrap_model(unet, False) 159 unet_ = accelerator.unwrap_model(unet, keep_fp32_wrapper=True)
160 text_encoder_ = accelerator.unwrap_model(text_encoder, False) 160 text_encoder_ = accelerator.unwrap_model(text_encoder, keep_fp32_wrapper=True)
161 161
162 orig_unet_dtype = unet_.dtype 162 orig_unet_dtype = unet_.dtype
163 orig_text_encoder_dtype = text_encoder_.dtype 163 orig_text_encoder_dtype = text_encoder_.dtype