summaryrefslogtreecommitdiffstats
path: root/training/strategy/lora.py
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/lora.py
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/lora.py')
-rw-r--r--training/strategy/lora.py12
1 files changed, 6 insertions, 6 deletions
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_