Skip to content

Commit

Permalink
do not save cuda_rng_state if no cuda closes bmaltais#390
Browse files Browse the repository at this point in the history
  • Loading branch information
kohya-ss committed May 7, 2023
1 parent fdbdb47 commit e54b631
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions library/train_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3344,7 +3344,7 @@ def sample_images(
os.makedirs(save_dir, exist_ok=True)

rng_state = torch.get_rng_state()
cuda_rng_state = torch.cuda.get_rng_state()
cuda_rng_state = torch.cuda.get_rng_state() if torch.cuda.is_available() else None

with torch.no_grad():
with accelerator.autocast():
Expand Down Expand Up @@ -3451,7 +3451,8 @@ def sample_images(
torch.cuda.empty_cache()

torch.set_rng_state(rng_state)
torch.cuda.set_rng_state(cuda_rng_state)
if cuda_rng_state is not None:
torch.cuda.set_rng_state(cuda_rng_state)
vae.to(org_vae_device)


Expand Down

0 comments on commit e54b631

Please sign in to comment.