Skip to content

Logging

๐Ÿค— Diffusers has a centralized logging system to easily manage the verbosity of the library. The default verbosity is set to WARNING.

To change the verbosity level, use one of the direct setters. For instance, to change the verbosity to the INFO level.

import mindone.diffusers

mindone.diffusers.logging.set_verbosity_info()

You can also use the environment variable DIFFUSERS_VERBOSITY to override the default verbosity. You can set it to one of the following: debug, info, warning, error, critical. For example:

DIFFUSERS_VERBOSITY=error ./myprogram.py

Additionally, some warnings can be disabled by setting the environment variable DIFFUSERS_NO_ADVISORY_WARNINGS to a true value, like 1. This disables any warning logged by [logger.warning_advice]. For example:

DIFFUSERS_NO_ADVISORY_WARNINGS=1 ./myprogram.py

Here is an example of how to use the same logger as the library in your own module or script:

from mindone.diffusers.utils import logging

logging.set_verbosity_info()
logger = logging.get_logger("diffusers")
logger.info("INFO")
logger.warning("WARN")

All methods of the logging module are documented below. The main methods are get_verbosity to get the current level of verbosity in the logger and set_verbosity to set the verbosity to the level of your choice.

In order from the least verbose to the most verbose:

Method Integer value Description
diffusers.logging.CRITICAL or diffusers.logging.FATAL 50 only report the most critical errors
diffusers.logging.ERROR 40 only report errors
diffusers.logging.WARNING or diffusers.logging.WARN 30 only report errors and warnings (default)
diffusers.logging.INFO 20 only report errors, warnings, and basic information
diffusers.logging.DEBUG 10 report all information

By default, tqdm progress bars are displayed during model download. disable_progress_bar and enable_progress_bar are used to enable or disable this behavior.

Base setters

mindone.diffusers.utils.logging.set_verbosity_error()

Set the verbosity to the ERROR level.

Source code in mindone/diffusers/utils/logging.py
170
171
172
def set_verbosity_error() -> None:
    """Set the verbosity to the `ERROR` level."""
    return set_verbosity(ERROR)

mindone.diffusers.utils.logging.set_verbosity_warning()

Set the verbosity to the WARNING level.

Source code in mindone/diffusers/utils/logging.py
160
161
162
def set_verbosity_warning() -> None:
    """Set the verbosity to the `WARNING` level."""
    return set_verbosity(WARNING)

mindone.diffusers.utils.logging.set_verbosity_info()

Set the verbosity to the INFO level.

Source code in mindone/diffusers/utils/logging.py
155
156
157
def set_verbosity_info() -> None:
    """Set the verbosity to the `INFO` level."""
    return set_verbosity(INFO)

mindone.diffusers.utils.logging.set_verbosity_debug()

Set the verbosity to the DEBUG level.

Source code in mindone/diffusers/utils/logging.py
165
166
167
def set_verbosity_debug() -> None:
    """Set the verbosity to the `DEBUG` level."""
    return set_verbosity(DEBUG)

Other functions

mindone.diffusers.utils.logging.get_verbosity()

Return the current level for the ๐Ÿค— Diffusers' root logger as an int.

RETURNS DESCRIPTION
int

int: Logging level integers which can be one of:

  • 50: diffusers.logging.CRITICAL or diffusers.logging.FATAL
  • 40: diffusers.logging.ERROR
  • 30: diffusers.logging.WARNING or diffusers.logging.WARN
  • 20: diffusers.logging.INFO
  • 10: diffusers.logging.DEBUG
Source code in mindone/diffusers/utils/logging.py
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
def get_verbosity() -> int:
    """
    Return the current level for the ๐Ÿค— Diffusers' root logger as an `int`.

    Returns:
        `int`:
            Logging level integers which can be one of:

            - `50`: `diffusers.logging.CRITICAL` or `diffusers.logging.FATAL`
            - `40`: `diffusers.logging.ERROR`
            - `30`: `diffusers.logging.WARNING` or `diffusers.logging.WARN`
            - `20`: `diffusers.logging.INFO`
            - `10`: `diffusers.logging.DEBUG`

    """

    _configure_library_root_logger()
    return _get_library_root_logger().getEffectiveLevel()

mindone.diffusers.utils.logging.set_verbosity(verbosity)

Set the verbosity level for the ๐Ÿค— Diffusers' root logger.

PARAMETER DESCRIPTION
verbosity

Logging level which can be one of:

  • diffusers.logging.CRITICAL or diffusers.logging.FATAL
  • diffusers.logging.ERROR
  • diffusers.logging.WARNING or diffusers.logging.WARN
  • diffusers.logging.INFO
  • diffusers.logging.DEBUG

TYPE: `int`

Source code in mindone/diffusers/utils/logging.py
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
def set_verbosity(verbosity: int) -> None:
    """
    Set the verbosity level for the ๐Ÿค— Diffusers' root logger.

    Args:
        verbosity (`int`):
            Logging level which can be one of:

            - `diffusers.logging.CRITICAL` or `diffusers.logging.FATAL`
            - `diffusers.logging.ERROR`
            - `diffusers.logging.WARNING` or `diffusers.logging.WARN`
            - `diffusers.logging.INFO`
            - `diffusers.logging.DEBUG`
    """

    _configure_library_root_logger()
    _get_library_root_logger().setLevel(verbosity)

mindone.diffusers.utils.logging.get_logger(name=None)

Return a logger with the specified name.

This function is not supposed to be directly accessed unless you are writing a custom diffusers module.

Source code in mindone/diffusers/utils/logging.py
102
103
104
105
106
107
108
109
110
111
112
113
def get_logger(name: Optional[str] = None) -> logging.Logger:
    """
    Return a logger with the specified name.

    This function is not supposed to be directly accessed unless you are writing a custom diffusers module.
    """

    if name is None:
        name = _get_library_name()

    _configure_library_root_logger()
    return logging.getLogger(name)

mindone.diffusers.utils.logging.enable_default_handler()

Enable the default handler of the ๐Ÿค— Diffusers' root logger.

Source code in mindone/diffusers/utils/logging.py
184
185
186
187
188
189
190
def enable_default_handler() -> None:
    """Enable the default handler of the ๐Ÿค— Diffusers' root logger."""

    _configure_library_root_logger()

    assert _default_handler is not None
    _get_library_root_logger().addHandler(_default_handler)

mindone.diffusers.utils.logging.disable_default_handler()

Disable the default handler of the ๐Ÿค— Diffusers' root logger.

Source code in mindone/diffusers/utils/logging.py
175
176
177
178
179
180
181
def disable_default_handler() -> None:
    """Disable the default handler of the ๐Ÿค— Diffusers' root logger."""

    _configure_library_root_logger()

    assert _default_handler is not None
    _get_library_root_logger().removeHandler(_default_handler)

mindone.diffusers.utils.logging.enable_explicit_format()

Enable explicit formatting for every ๐Ÿค— Diffusers' logger. The explicit formatter is as follows:

[LEVELNAME|FILENAME|LINE NUMBER] TIME >> MESSAGE
All handlers currently bound to the root logger are affected by this method.

Source code in mindone/diffusers/utils/logging.py
230
231
232
233
234
235
236
237
238
239
240
241
242
def enable_explicit_format() -> None:
    """
    Enable explicit formatting for every ๐Ÿค— Diffusers' logger. The explicit formatter is as follows:
    ```
    [LEVELNAME|FILENAME|LINE NUMBER] TIME >> MESSAGE
    ```
    All handlers currently bound to the root logger are affected by this method.
    """
    handlers = _get_library_root_logger().handlers

    for handler in handlers:
        formatter = logging.Formatter("[%(levelname)s|%(filename)s:%(lineno)s] %(asctime)s >> %(message)s")
        handler.setFormatter(formatter)

mindone.diffusers.utils.logging.reset_format()

Resets the formatting for ๐Ÿค— Diffusers' loggers.

All handlers currently bound to the root logger are affected by this method.

Source code in mindone/diffusers/utils/logging.py
245
246
247
248
249
250
251
252
253
254
def reset_format() -> None:
    """
    Resets the formatting for ๐Ÿค— Diffusers' loggers.

    All handlers currently bound to the root logger are affected by this method.
    """
    handlers = _get_library_root_logger().handlers

    for handler in handlers:
        handler.setFormatter(None)

mindone.diffusers.utils.logging.enable_progress_bar()

Enable tqdm progress bar.

Source code in mindone/diffusers/utils/logging.py
321
322
323
324
def enable_progress_bar() -> None:
    """Enable tqdm progress bar."""
    global _tqdm_active
    _tqdm_active = True

mindone.diffusers.utils.logging.disable_progress_bar()

Disable tqdm progress bar.

Source code in mindone/diffusers/utils/logging.py
327
328
329
330
def disable_progress_bar() -> None:
    """Disable tqdm progress bar."""
    global _tqdm_active
    _tqdm_active = False