Skip to content

Commit cd90a74

Browse files
authored
Avoid creating a progress bar when it is disabled.
This is useful when exporting a pipeline, and allows a compiler to avoid trying to compile away tqdm.
1 parent 63b631f commit cd90a74

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/diffusers/pipelines/pipeline_utils.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,16 @@
102102

103103
logger = logging.get_logger(__name__)
104104

105+
class NotTQDMNoOp:
106+
def __init__(*args, **kwargs):
107+
return
108+
def __enter__(self, *args, **kwargs):
109+
return self
110+
def __exit__(*args, **kwargs):
111+
return
112+
def update(*args, **kwargs):
113+
return
114+
105115

106116
@dataclass
107117
class ImagePipelineOutput(BaseOutput):
@@ -1560,6 +1570,8 @@ def progress_bar(self, iterable=None, total=None):
15601570
f"`self._progress_bar_config` should be of type `dict`, but is {type(self._progress_bar_config)}."
15611571
)
15621572

1573+
if self._progress_bar_config.get('disable', False) == True:
1574+
return NotTQDMNoOp()
15631575
if iterable is not None:
15641576
return tqdm(iterable, **self._progress_bar_config)
15651577
elif total is not None:

0 commit comments

Comments
 (0)