Skip to content

Commit

Permalink
feature: clean up terminal output
Browse files Browse the repository at this point in the history
- recording timing and memory usage of various steps
- re-use logging context for composition images
- load sdxl weights in a more VRAM efficient way
- switch to diffusers weights for default weights for sd15
  • Loading branch information
brycedrennan committed Jan 1, 2024
1 parent 0d78b82 commit 9e3403d
Show file tree
Hide file tree
Showing 13 changed files with 470 additions and 199 deletions.
15 changes: 7 additions & 8 deletions imaginairy/api/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,14 @@ def _record_step(img, description, image_count, step_count, prompt):
f"{base_count:06}_{prompt.seed}_{prompt.solver_type.replace('_', '')}{prompt.steps}_"
f"PS{prompt.prompt_strength}{img_str}_{prompt_normalized(prompt.prompt_text)}"
)

for image_type in result.images:
subpath = os.path.join(outdir, image_type)
os.makedirs(subpath, exist_ok=True)
filepath = os.path.join(
subpath, f"{basefilename}_[{image_type}].{output_file_extension}"
)
result.save(filepath, image_type=image_type)
logger.info(f" [{image_type}] saved to: {filepath}")
logger.info(f" {image_type:<22} {filepath}")
if image_type == return_filename_type:
result_filenames.append(filepath)
if videogen:
Expand Down Expand Up @@ -123,7 +122,8 @@ def _record_step(img, description, image_count, step_count, prompt):
start_pause_duration_ms=1500,
end_pause_duration_ms=1000,
)
logger.info(f" [gif] {len(frames)} frames saved to: {filepath}")
image_type = "gif"
logger.info(f" {image_type:<22} {filepath}")
if make_compare_gif and prompt.init_image:
subpath = os.path.join(outdir, "gif")
os.makedirs(subpath, exist_ok=True)
Expand All @@ -137,7 +137,8 @@ def _record_step(img, description, image_count, step_count, prompt):
imgs=frames,
outpath=filepath,
)
logger.info(f" [gif-comparison] saved to: {filepath}")
image_type = "gif"
logger.info(f" {image_type:<22} {filepath}")

base_count += 1
del result
Expand Down Expand Up @@ -192,9 +193,8 @@ def imagine(
), fix_torch_nn_layer_norm(), fix_torch_group_norm():
for i, prompt in enumerate(prompts):
concrete_prompt = prompt.make_concrete_copy()
logger.info(
f"🖼 Generating {i + 1}/{num_prompts}: {concrete_prompt.prompt_description()}"
)
prog_text = f"{i + 1}/{num_prompts}"
logger.info(f"🖼 {prog_text} {concrete_prompt.prompt_description()}")
for attempt in range(unsafe_retry_count + 1):
if attempt > 0 and isinstance(concrete_prompt.seed, int):
concrete_prompt.seed += 100_000_000 + attempt
Expand All @@ -204,7 +204,6 @@ def imagine(
progress_img_callback=progress_img_callback,
progress_img_interval_steps=progress_img_interval_steps,
progress_img_interval_min_s=progress_img_interval_min_s,
half_mode=half_mode,
add_caption=add_caption,
dtype=torch.float16 if half_mode else torch.float32,
)
Expand Down
2 changes: 1 addition & 1 deletion imaginairy/api/generate_compvis.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ def latent_logger(latents):
is_nsfw=safety_score.is_nsfw,
safety_score=safety_score,
result_images=result_images,
timings=lc.get_timings(),
performance_stats=lc.get_performance_stats(),
progress_latents=progress_latents.copy(),
)

Expand Down
Loading

0 comments on commit 9e3403d

Please sign in to comment.