Skip to content

Commit

Permalink
fix: final output and progress on save
Browse files Browse the repository at this point in the history
  • Loading branch information
hanxiao committed Aug 3, 2022
1 parent 4fc9a78 commit fa13fff
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 18 deletions.
18 changes: 11 additions & 7 deletions discoart/persist.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def _sample(
is_sampling_done,
is_save_step,
is_save_gif,
is_image_output,
):
with threading.Lock():
is_sampling_done.clear()
Expand All @@ -50,16 +51,19 @@ def _sample(
).load_pil_image_to_datauri(image)

if is_save_step:
if cur_t == -1:
c.save_uri_to_file(os.path.join(output_dir, f'{_nb}-done-{k}.png'))
else:
c.save_uri_to_file(
os.path.join(output_dir, f'{_nb}-step-{j}-{k}.png')
)
if is_image_output:
if cur_t == -1:
c.save_uri_to_file(
os.path.join(output_dir, f'{_nb}-done-{k}.png')
)
else:
c.save_uri_to_file(
os.path.join(output_dir, f'{_nb}-step-{j}-{k}.png')
)

da[k].chunks.append(c)

if is_save_gif:
if is_save_gif and is_image_output:
da_gif[k].chunks.append(c)

# root doc always update with the latest progress
Expand Down
3 changes: 2 additions & 1 deletion discoart/resources/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,5 @@ name_docarray:
skip_event:
stop_event:
text_clip_on_cpu: False
truncate_overlength_prompt: False
truncate_overlength_prompt: False
image_output: True
5 changes: 4 additions & 1 deletion discoart/resources/docstrings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,7 @@ gif_size_ratio: |
[DiscoArt] The relative size vs. the original image, small size ratio gives smaller file size.
truncate_overlength_prompt: |
[DiscoArt] all CLIP models use 77 as the context length. Set this parameter truncates the prompt to the length of the model's context length.
[DiscoArt] all CLIP models use 77 as the context length. Set this parameter truncates the prompt to the length of the model's context length.
image_output: |
[DiscoArt] If set, then output will be saved as images. This includes intermediate, final results in the form of PNG and GIF. If set to False, then no images will be saved, everything will be saved in a Protobuf LZ4 format. https://docarray.jina.ai/fundamentals/documentarray/serialization/#from-to-bytes
20 changes: 11 additions & 9 deletions discoart/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,20 +460,22 @@ def cond_fn(x, t, **kwargs):
is_busy_evs[0],
is_save_step or is_complete,
args.gif_fps > 0,
args.image_output,
)
)

if is_complete or is_save_step:
threads.append(
_save_progress_thread(
_da,
_da_gif,
_nb,
output_dir,
args.gif_fps,
args.gif_size_ratio,
if args.image_output:
threads.append(
_save_progress_thread(
_da,
_da_gif,
_nb,
output_dir,
args.gif_fps,
args.gif_size_ratio,
)
)
)

threads.extend(
_persist_thread(
Expand Down

0 comments on commit fa13fff

Please sign in to comment.