memoryai commited on
Commit
69bd807
·
verified ·
1 Parent(s): 1ee8060

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 -4
scripts/training/train_flux_lora.py CHANGED
@@ -303,10 +303,18 @@ def main():
303
  num_training_steps=args.max_train_steps,
304
  )
305
 
306
- # Fast-forward scheduler if resuming
307
- if resume_step > 0:
308
- for _ in range(resume_step):
309
- lr_scheduler.step()
 
 
 
 
 
 
 
 
310
 
311
  # Dataset
312
  print(f" Loading dataset from {args.data_dir}")
 
303
  num_training_steps=args.max_train_steps,
304
  )
305
 
306
+ # Restore optimizer + scheduler state if resuming
307
+ if resume_step > 0 and resume_path:
308
+ training_state_path = resume_path / "training_state.pt"
309
+ if training_state_path.exists():
310
+ state = torch.load(str(training_state_path), map_location="cpu")
311
+ optimizer.load_state_dict(state["optimizer"])
312
+ lr_scheduler.load_state_dict(state["lr_scheduler"])
313
+ print(f" Restored optimizer + scheduler state from checkpoint")
314
+ else:
315
+ print(f" No training_state.pt found, fast-forwarding scheduler...")
316
+ for _ in range(resume_step):
317
+ lr_scheduler.step()
318
 
319
  # Dataset
320
  print(f" Loading dataset from {args.data_dir}")