From 839e30e4b8ca6554017fbab671bdf85fadf9a6ea Mon Sep 17 00:00:00 2001 From: Lincoln Stein Date: Sun, 11 Sep 2022 10:02:44 -0400 Subject: [PATCH 1/2] improve CUDA VRAM monitoring extra check that device==cuda before getting VRAM stats --- ldm/generate.py | 12 +++++++----- scripts/dream.py | 7 +++++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/ldm/generate.py b/ldm/generate.py index 05e2c6a440..8f67403633 100644 --- a/ldm/generate.py +++ b/ldm/generate.py @@ -357,12 +357,14 @@ class Generate: print( f'>> {len(results)} image(s) generated in', '%4.2fs' % (toc - tic) ) - print( - f'>> Max VRAM used for this generation:', - '%4.2fG' % (torch.cuda.max_memory_allocated() / 1e9), - ) + if torch.cuda.is_available() and self.device.type == 'cuda': + print( + f'>> Max VRAM used for this generation:', + '%4.2fG.' % (torch.cuda.max_memory_allocated() / 1e9), + 'Current VRAM utilization:' + '%4.2fG' % (torch.cuda.memory_allocated() / 1e9), + ) - if self.session_peakmem: self.session_peakmem = max( self.session_peakmem, torch.cuda.max_memory_allocated() ) diff --git a/scripts/dream.py b/scripts/dream.py index 0b1e80f66d..ece17d122b 100755 --- a/scripts/dream.py +++ b/scripts/dream.py @@ -130,8 +130,11 @@ def main_loop(t2i, outdir, prompt_as_dir, parser, infile): command = get_next_command(infile) except EOFError: done = True - break - + continue + except KeyboardInterrupt: + done = True + continue + # skip empty lines if not command.strip(): continue From 8748370f44e28b104fbaa23b4e2e54e64102d799 Mon Sep 17 00:00:00 2001 From: Lincoln Stein Date: Sun, 11 Sep 2022 10:22:32 -0400 Subject: [PATCH 2/2] negative -S indexing recovers correct previous seed; closes issue #476 --- scripts/dream.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/dream.py b/scripts/dream.py index ece17d122b..b1c62dcbee 100755 --- a/scripts/dream.py +++ b/scripts/dream.py @@ -185,6 +185,7 @@ def main_loop(t2i, outdir, prompt_as_dir, parser, infile): continue if opt.seed is not None and opt.seed < 0: # retrieve previous value! try: + print(f'last seeds = {last_seeds}, opt.seed={opt.seed}') opt.seed = last_seeds[opt.seed] print(f'reusing previous seed {opt.seed}') except IndexError: @@ -242,8 +243,8 @@ def main_loop(t2i, outdir, prompt_as_dir, parser, infile): # Here is where the images are actually generated! try: file_writer = PngWriter(current_outdir) - prefix = file_writer.unique_prefix() - seeds = set() + prefix = file_writer.unique_prefix() + seeds = list() results = [] # list of filename, prompt pairs grid_images = dict() # seed -> Image, only used if `do_grid` def image_writer(image, seed, upscaled=False): @@ -275,7 +276,7 @@ def main_loop(t2i, outdir, prompt_as_dir, parser, infile): # only append to results if we didn't overwrite an earlier output results.append([path, metadata_prompt]) - seeds.add(seed) + seeds.append(seed) t2i.prompt2image(image_callback=image_writer, **vars(opt))