diffusers icon indicating copy to clipboard operation
diffusers copied to clipboard

Add options to disable/hide progress bar

Open hysts opened this issue 3 years ago • 1 comments
trafficstars

Is your feature request related to a problem? Please describe.

This is a minor thing, but I find the progress bar annoying when I run inference with pipeline successively.

See this screenshot for example. In this case, I generated 10 images using DDIMPipeline and used tqdm myself, but the progress bars coming from __call__ of the pipeline are stacking up and annoying.

Describe the solution you'd like

It would be nice if disable and leave options of tqdm were available with pipelines. Keyword arguments (say, disable_tqdm and leave_tqdm?) could be added to __call__ methods and passed to tqdm. These are the relevant lines in case of DDPMPipeline: https://github.com/huggingface/diffusers/blob/92b6dbba1a25ed27b0bae38b089715132c7e6bcc/src/diffusers/pipelines/ddpm/pipeline_ddpm.py#L31 https://github.com/huggingface/diffusers/blob/92b6dbba1a25ed27b0bae38b089715132c7e6bcc/src/diffusers/pipelines/ddpm/pipeline_ddpm.py#L47

I found something that might be relevant in the logging module, but it's not used in the pipeline modules. Maybe this can be used.

hysts avatar Aug 13 '22 08:08 hysts

Thank you for opening the issue. I think it makes sense, the progress bars can be annoying when doing multiple generations. Think we can allow disabling progress bars. cc @anton-l @patrickvonplaten

patil-suraj avatar Aug 13 '22 08:08 patil-suraj

Yes agree! I'd be in favor of adding a function for this I think (dis/enable_progress_bar(...))

patrickvonplaten avatar Aug 23 '22 12:08 patrickvonplaten

@hysts would you like to try to make a PR for it? Think we could just just change:

for t in tqdm(self.scheduler.timesteps): 

with:

for t in self.progress_bar(self.scheduler.timesteps): 

and then have a function in general Pipelines that does:

def progress_bar(self, iterable):
     if self._is_progress_bar_enabled:
         return tqdm(iterable)
     else:
         return iterable

And then we just need a enable and disable function :-)

patrickvonplaten avatar Aug 23 '22 12:08 patrickvonplaten

Also cc @pcuenca @ydshieh in case you would be interested in taking a look here :-)

patrickvonplaten avatar Aug 23 '22 12:08 patrickvonplaten

I can take this as an exercise for using tqdm, unless @hysts would like to make a PR.

ydshieh avatar Aug 23 '22 15:08 ydshieh

Sure. I'll look into it and make a PR.

hysts avatar Aug 23 '22 22:08 hysts

Let's also make sure that we can handle additional arguments to tqdm (like total=) with **kwargs like so:

def progress_bar(self, iterable, **kwargs):
     if self._is_progress_bar_enabled:
         return tqdm(iterable, **kwargs)
     else:
         return iterable
for i, t in tqdm(enumerate(self.scheduler.timesteps), total=self.scheduler.num_inference_steps):

anton-l avatar Aug 24 '22 11:08 anton-l