memoryai commited on
Commit
b476a30
·
verified ·
1 Parent(s): 6af373d

Upload scripts/training/train_flux_lora.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. scripts/training/train_flux_lora.py +12 -2
scripts/training/train_flux_lora.py CHANGED
@@ -131,13 +131,18 @@ def generate_samples(
131
  num_inference_steps=28, guidance_scale=3.5,
132
  ):
133
  from diffusers import FluxPipeline
134
- import numpy as np
135
 
136
  output_dir = Path(output_dir) / "samples"
137
  output_dir.mkdir(parents=True, exist_ok=True)
138
 
139
  transformer.eval()
140
 
 
 
 
 
 
 
141
  try:
142
  pipe = FluxPipeline.from_pretrained(
143
  "black-forest-labs/FLUX.1-dev",
@@ -149,7 +154,7 @@ def generate_samples(
149
  tokenizer_2=tokenizer_2,
150
  torch_dtype=torch.bfloat16,
151
  )
152
- pipe = pipe.to(train_device)
153
 
154
  for i, prompt in enumerate(prompts):
155
  image = pipe(
@@ -165,6 +170,11 @@ def generate_samples(
165
  except Exception as e:
166
  print(f" WARNING: Sample generation failed: {e}")
167
 
 
 
 
 
 
168
  transformer.train()
169
  torch.cuda.empty_cache()
170
 
 
131
  num_inference_steps=28, guidance_scale=3.5,
132
  ):
133
  from diffusers import FluxPipeline
 
134
 
135
  output_dir = Path(output_dir) / "samples"
136
  output_dir.mkdir(parents=True, exist_ok=True)
137
 
138
  transformer.eval()
139
 
140
+ # Move all components to same device for inference
141
+ gen_device = train_device
142
+ vae.to(gen_device)
143
+ text_encoder.to(gen_device)
144
+ text_encoder_2.to(gen_device)
145
+
146
  try:
147
  pipe = FluxPipeline.from_pretrained(
148
  "black-forest-labs/FLUX.1-dev",
 
154
  tokenizer_2=tokenizer_2,
155
  torch_dtype=torch.bfloat16,
156
  )
157
+ pipe = pipe.to(gen_device)
158
 
159
  for i, prompt in enumerate(prompts):
160
  image = pipe(
 
170
  except Exception as e:
171
  print(f" WARNING: Sample generation failed: {e}")
172
 
173
+ # Move components back to encode_device for training
174
+ vae.to(encode_device)
175
+ text_encoder.to(encode_device)
176
+ text_encoder_2.to(encode_device)
177
+
178
  transformer.train()
179
  torch.cuda.empty_cache()
180