We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
logging.remove_handler() has a faulty assertion, doesn't allow registered handlers to be removed
### Describe the bug

in `utils/logging.py` there the function remove_handler seems to have a faulty assertion in it.

```py
def add_handler(handler: logging.Handler) -> None:
    """adds a handler to the HuggingFace Diffusers' root logger."""

    _configure_library_root_logger()

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


def remove_handler(handler: logging.Handler) -> None:
    """removes given handler from the HuggingFace Diffusers' root logger."""

    _configure_library_root_logger()

    assert handler is not None and handler not in _get_library_root_logger().handlers # <<< THIS ONE
    _get_library_root_logger().removeHandler(handler)
```

That line seems to have a `not` that shouldn't be there. (the `not in` to be precise)

Normally I'd just do a PR to remove it, but as I'm not that familiar with the codebase, nor Python in general, and don't yet have a solid grasp of what these things actually do (I'm just playing around trying to familiarize myself), I decided to make an issue instead so people who actually know the codebase can do it.

### Reproduction

```py
from diffusers import logging
from logging import Handler

class TestHandler(Handler):
    def __init__(self):
        super().__init__()

    def emit(self):
        pass

handler = TestHandler()
logging.add_handler(handler)
logging.remove_handler(handler)
```

### Logs

```shell
Traceback (most recent call last):
  File ".\test.py", line 14, in <module>
    logging.remove_handler(handler)
  File "C:\Users\XXX\XXX\venv\lib\site-packages\diffusers\utils\logging.py", line 221, in remove_handler
    assert handler is not None and handler not in _get_library_root_logger().handlers
AssertionError
```


### System Info

- `diffusers` version: 0.3.0
- Platform: Windows-10-10.0.19041-SP0
- Python version: 3.8.9
- PyTorch version (GPU?): 1.12.1+cpu (False)
- Huggingface_hub version: 0.9.1
- Transformers version: 4.21.3
- Using GPU in script?: no
- Using distributed or parallel set-up in script?: Don't understand the question, but seems irrelevant.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/diffusers/utils/logging.py`
Content:
```
1 # coding=utf-8
2 # Copyright 2023 Optuna, Hugging Face
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 """ Logging utilities."""
16 
17 import logging
18 import os
19 import sys
20 import threading
21 from logging import (
22     CRITICAL,  # NOQA
23     DEBUG,  # NOQA
24     ERROR,  # NOQA
25     FATAL,  # NOQA
26     INFO,  # NOQA
27     NOTSET,  # NOQA
28     WARN,  # NOQA
29     WARNING,  # NOQA
30 )
31 from typing import Dict, Optional
32 
33 from tqdm import auto as tqdm_lib
34 
35 
36 _lock = threading.Lock()
37 _default_handler: Optional[logging.Handler] = None
38 
39 log_levels = {
40     "debug": logging.DEBUG,
41     "info": logging.INFO,
42     "warning": logging.WARNING,
43     "error": logging.ERROR,
44     "critical": logging.CRITICAL,
45 }
46 
47 _default_log_level = logging.WARNING
48 
49 _tqdm_active = True
50 
51 
52 def _get_default_logging_level() -> int:
53     """
54     If DIFFUSERS_VERBOSITY env var is set to one of the valid choices return that as the new default level. If it is
55     not - fall back to `_default_log_level`
56     """
57     env_level_str = os.getenv("DIFFUSERS_VERBOSITY", None)
58     if env_level_str:
59         if env_level_str in log_levels:
60             return log_levels[env_level_str]
61         else:
62             logging.getLogger().warning(
63                 f"Unknown option DIFFUSERS_VERBOSITY={env_level_str}, "
64                 f"has to be one of: { ', '.join(log_levels.keys()) }"
65             )
66     return _default_log_level
67 
68 
69 def _get_library_name() -> str:
70     return __name__.split(".")[0]
71 
72 
73 def _get_library_root_logger() -> logging.Logger:
74     return logging.getLogger(_get_library_name())
75 
76 
77 def _configure_library_root_logger() -> None:
78     global _default_handler
79 
80     with _lock:
81         if _default_handler:
82             # This library has already configured the library root logger.
83             return
84         _default_handler = logging.StreamHandler()  # Set sys.stderr as stream.
85         _default_handler.flush = sys.stderr.flush
86 
87         # Apply our default configuration to the library root logger.
88         library_root_logger = _get_library_root_logger()
89         library_root_logger.addHandler(_default_handler)
90         library_root_logger.setLevel(_get_default_logging_level())
91         library_root_logger.propagate = False
92 
93 
94 def _reset_library_root_logger() -> None:
95     global _default_handler
96 
97     with _lock:
98         if not _default_handler:
99             return
100 
101         library_root_logger = _get_library_root_logger()
102         library_root_logger.removeHandler(_default_handler)
103         library_root_logger.setLevel(logging.NOTSET)
104         _default_handler = None
105 
106 
107 def get_log_levels_dict() -> Dict[str, int]:
108     return log_levels
109 
110 
111 def get_logger(name: Optional[str] = None) -> logging.Logger:
112     """
113     Return a logger with the specified name.
114 
115     This function is not supposed to be directly accessed unless you are writing a custom diffusers module.
116     """
117 
118     if name is None:
119         name = _get_library_name()
120 
121     _configure_library_root_logger()
122     return logging.getLogger(name)
123 
124 
125 def get_verbosity() -> int:
126     """
127     Return the current level for the 🤗 Diffusers' root logger as an `int`.
128 
129     Returns:
130         `int`:
131             Logging level integers which can be one of:
132 
133             - `50`: `diffusers.logging.CRITICAL` or `diffusers.logging.FATAL`
134             - `40`: `diffusers.logging.ERROR`
135             - `30`: `diffusers.logging.WARNING` or `diffusers.logging.WARN`
136             - `20`: `diffusers.logging.INFO`
137             - `10`: `diffusers.logging.DEBUG`
138 
139     """
140 
141     _configure_library_root_logger()
142     return _get_library_root_logger().getEffectiveLevel()
143 
144 
145 def set_verbosity(verbosity: int) -> None:
146     """
147     Set the verbosity level for the 🤗 Diffusers' root logger.
148 
149     Args:
150         verbosity (`int`):
151             Logging level which can be one of:
152 
153             - `diffusers.logging.CRITICAL` or `diffusers.logging.FATAL`
154             - `diffusers.logging.ERROR`
155             - `diffusers.logging.WARNING` or `diffusers.logging.WARN`
156             - `diffusers.logging.INFO`
157             - `diffusers.logging.DEBUG`
158     """
159 
160     _configure_library_root_logger()
161     _get_library_root_logger().setLevel(verbosity)
162 
163 
164 def set_verbosity_info() -> None:
165     """Set the verbosity to the `INFO` level."""
166     return set_verbosity(INFO)
167 
168 
169 def set_verbosity_warning() -> None:
170     """Set the verbosity to the `WARNING` level."""
171     return set_verbosity(WARNING)
172 
173 
174 def set_verbosity_debug() -> None:
175     """Set the verbosity to the `DEBUG` level."""
176     return set_verbosity(DEBUG)
177 
178 
179 def set_verbosity_error() -> None:
180     """Set the verbosity to the `ERROR` level."""
181     return set_verbosity(ERROR)
182 
183 
184 def disable_default_handler() -> None:
185     """Disable the default handler of the 🤗 Diffusers' root logger."""
186 
187     _configure_library_root_logger()
188 
189     assert _default_handler is not None
190     _get_library_root_logger().removeHandler(_default_handler)
191 
192 
193 def enable_default_handler() -> None:
194     """Enable the default handler of the 🤗 Diffusers' root logger."""
195 
196     _configure_library_root_logger()
197 
198     assert _default_handler is not None
199     _get_library_root_logger().addHandler(_default_handler)
200 
201 
202 def add_handler(handler: logging.Handler) -> None:
203     """adds a handler to the HuggingFace Diffusers' root logger."""
204 
205     _configure_library_root_logger()
206 
207     assert handler is not None
208     _get_library_root_logger().addHandler(handler)
209 
210 
211 def remove_handler(handler: logging.Handler) -> None:
212     """removes given handler from the HuggingFace Diffusers' root logger."""
213 
214     _configure_library_root_logger()
215 
216     assert handler is not None and handler not in _get_library_root_logger().handlers
217     _get_library_root_logger().removeHandler(handler)
218 
219 
220 def disable_propagation() -> None:
221     """
222     Disable propagation of the library log outputs. Note that log propagation is disabled by default.
223     """
224 
225     _configure_library_root_logger()
226     _get_library_root_logger().propagate = False
227 
228 
229 def enable_propagation() -> None:
230     """
231     Enable propagation of the library log outputs. Please disable the HuggingFace Diffusers' default handler to prevent
232     double logging if the root logger has been configured.
233     """
234 
235     _configure_library_root_logger()
236     _get_library_root_logger().propagate = True
237 
238 
239 def enable_explicit_format() -> None:
240     """
241     Enable explicit formatting for every 🤗 Diffusers' logger. The explicit formatter is as follows:
242     ```
243     [LEVELNAME|FILENAME|LINE NUMBER] TIME >> MESSAGE
244     ```
245     All handlers currently bound to the root logger are affected by this method.
246     """
247     handlers = _get_library_root_logger().handlers
248 
249     for handler in handlers:
250         formatter = logging.Formatter("[%(levelname)s|%(filename)s:%(lineno)s] %(asctime)s >> %(message)s")
251         handler.setFormatter(formatter)
252 
253 
254 def reset_format() -> None:
255     """
256     Resets the formatting for 🤗 Diffusers' loggers.
257 
258     All handlers currently bound to the root logger are affected by this method.
259     """
260     handlers = _get_library_root_logger().handlers
261 
262     for handler in handlers:
263         handler.setFormatter(None)
264 
265 
266 def warning_advice(self, *args, **kwargs) -> None:
267     """
268     This method is identical to `logger.warning()`, but if env var DIFFUSERS_NO_ADVISORY_WARNINGS=1 is set, this
269     warning will not be printed
270     """
271     no_advisory_warnings = os.getenv("DIFFUSERS_NO_ADVISORY_WARNINGS", False)
272     if no_advisory_warnings:
273         return
274     self.warning(*args, **kwargs)
275 
276 
277 logging.Logger.warning_advice = warning_advice
278 
279 
280 class EmptyTqdm:
281     """Dummy tqdm which doesn't do anything."""
282 
283     def __init__(self, *args, **kwargs):  # pylint: disable=unused-argument
284         self._iterator = args[0] if args else None
285 
286     def __iter__(self):
287         return iter(self._iterator)
288 
289     def __getattr__(self, _):
290         """Return empty function."""
291 
292         def empty_fn(*args, **kwargs):  # pylint: disable=unused-argument
293             return
294 
295         return empty_fn
296 
297     def __enter__(self):
298         return self
299 
300     def __exit__(self, type_, value, traceback):
301         return
302 
303 
304 class _tqdm_cls:
305     def __call__(self, *args, **kwargs):
306         if _tqdm_active:
307             return tqdm_lib.tqdm(*args, **kwargs)
308         else:
309             return EmptyTqdm(*args, **kwargs)
310 
311     def set_lock(self, *args, **kwargs):
312         self._lock = None
313         if _tqdm_active:
314             return tqdm_lib.tqdm.set_lock(*args, **kwargs)
315 
316     def get_lock(self):
317         if _tqdm_active:
318             return tqdm_lib.tqdm.get_lock()
319 
320 
321 tqdm = _tqdm_cls()
322 
323 
324 def is_progress_bar_enabled() -> bool:
325     """Return a boolean indicating whether tqdm progress bars are enabled."""
326     global _tqdm_active
327     return bool(_tqdm_active)
328 
329 
330 def enable_progress_bar() -> None:
331     """Enable tqdm progress bar."""
332     global _tqdm_active
333     _tqdm_active = True
334 
335 
336 def disable_progress_bar() -> None:
337     """Disable tqdm progress bar."""
338     global _tqdm_active
339     _tqdm_active = False
340
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/src/diffusers/utils/logging.py b/src/diffusers/utils/logging.py
--- a/src/diffusers/utils/logging.py
+++ b/src/diffusers/utils/logging.py
@@ -213,7 +213,7 @@
 
     _configure_library_root_logger()
 
-    assert handler is not None and handler not in _get_library_root_logger().handlers
+    assert handler is not None and handler in _get_library_root_logger().handlers
     _get_library_root_logger().removeHandler(handler)

{"golden_diff": "diff --git a/src/diffusers/utils/logging.py b/src/diffusers/utils/logging.py\n--- a/src/diffusers/utils/logging.py\n+++ b/src/diffusers/utils/logging.py\n@@ -213,7 +213,7 @@\n \n     _configure_library_root_logger()\n \n-    assert handler is not None and handler not in _get_library_root_logger().handlers\n+    assert handler is not None and handler in _get_library_root_logger().handlers\n     _get_library_root_logger().removeHandler(handler)\n", "issue": "logging.remove_handler() has a faulty assertion, doesn't allow registered handlers to be removed\n### Describe the bug\r\n\r\nin `utils/logging.py` there the function remove_handler seems to have a faulty assertion in it.\r\n\r\n```py\r\ndef add_handler(handler: logging.Handler) -> None:\r\n    \"\"\"adds a handler to the HuggingFace Diffusers' root logger.\"\"\"\r\n\r\n    _configure_library_root_logger()\r\n\r\n    assert handler is not None\r\n    _get_library_root_logger().addHandler(handler)\r\n\r\n\r\ndef remove_handler(handler: logging.Handler) -> None:\r\n    \"\"\"removes given handler from the HuggingFace Diffusers' root logger.\"\"\"\r\n\r\n    _configure_library_root_logger()\r\n\r\n    assert handler is not None and handler not in _get_library_root_logger().handlers # <<< THIS ONE\r\n    _get_library_root_logger().removeHandler(handler)\r\n```\r\n\r\nThat line seems to have a `not` that shouldn't be there. (the `not in` to be precise)\r\n\r\nNormally I'd just do a PR to remove it, but as I'm not that familiar with the codebase, nor Python in general, and don't yet have a solid grasp of what these things actually do (I'm just playing around trying to familiarize myself), I decided to make an issue instead so people who actually know the codebase can do it.\r\n\r\n### Reproduction\r\n\r\n```py\r\nfrom diffusers import logging\r\nfrom logging import Handler\r\n\r\nclass TestHandler(Handler):\r\n    def __init__(self):\r\n        super().__init__()\r\n\r\n    def emit(self):\r\n        pass\r\n\r\nhandler = TestHandler()\r\nlogging.add_handler(handler)\r\nlogging.remove_handler(handler)\r\n```\r\n\r\n### Logs\r\n\r\n```shell\r\nTraceback (most recent call last):\r\n  File \".\\test.py\", line 14, in <module>\r\n    logging.remove_handler(handler)\r\n  File \"C:\\Users\\XXX\\XXX\\venv\\lib\\site-packages\\diffusers\\utils\\logging.py\", line 221, in remove_handler\r\n    assert handler is not None and handler not in _get_library_root_logger().handlers\r\nAssertionError\r\n```\r\n\r\n\r\n### System Info\r\n\r\n- `diffusers` version: 0.3.0\r\n- Platform: Windows-10-10.0.19041-SP0\r\n- Python version: 3.8.9\r\n- PyTorch version (GPU?): 1.12.1+cpu (False)\r\n- Huggingface_hub version: 0.9.1\r\n- Transformers version: 4.21.3\r\n- Using GPU in script?: no\r\n- Using distributed or parallel set-up in script?: Don't understand the question, but seems irrelevant.\n", "before_files": [{"content": "# coding=utf-8\n# Copyright 2023 Optuna, Hugging Face\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\"\"\" Logging utilities.\"\"\"\n\nimport logging\nimport os\nimport sys\nimport threading\nfrom logging import (\n    CRITICAL,  # NOQA\n    DEBUG,  # NOQA\n    ERROR,  # NOQA\n    FATAL,  # NOQA\n    INFO,  # NOQA\n    NOTSET,  # NOQA\n    WARN,  # NOQA\n    WARNING,  # NOQA\n)\nfrom typing import Dict, Optional\n\nfrom tqdm import auto as tqdm_lib\n\n\n_lock = threading.Lock()\n_default_handler: Optional[logging.Handler] = None\n\nlog_levels = {\n    \"debug\": logging.DEBUG,\n    \"info\": logging.INFO,\n    \"warning\": logging.WARNING,\n    \"error\": logging.ERROR,\n    \"critical\": logging.CRITICAL,\n}\n\n_default_log_level = logging.WARNING\n\n_tqdm_active = True\n\n\ndef _get_default_logging_level() -> int:\n    \"\"\"\n    If DIFFUSERS_VERBOSITY env var is set to one of the valid choices return that as the new default level. If it is\n    not - fall back to `_default_log_level`\n    \"\"\"\n    env_level_str = os.getenv(\"DIFFUSERS_VERBOSITY\", None)\n    if env_level_str:\n        if env_level_str in log_levels:\n            return log_levels[env_level_str]\n        else:\n            logging.getLogger().warning(\n                f\"Unknown option DIFFUSERS_VERBOSITY={env_level_str}, \"\n                f\"has to be one of: { ', '.join(log_levels.keys()) }\"\n            )\n    return _default_log_level\n\n\ndef _get_library_name() -> str:\n    return __name__.split(\".\")[0]\n\n\ndef _get_library_root_logger() -> logging.Logger:\n    return logging.getLogger(_get_library_name())\n\n\ndef _configure_library_root_logger() -> None:\n    global _default_handler\n\n    with _lock:\n        if _default_handler:\n            # This library has already configured the library root logger.\n            return\n        _default_handler = logging.StreamHandler()  # Set sys.stderr as stream.\n        _default_handler.flush = sys.stderr.flush\n\n        # Apply our default configuration to the library root logger.\n        library_root_logger = _get_library_root_logger()\n        library_root_logger.addHandler(_default_handler)\n        library_root_logger.setLevel(_get_default_logging_level())\n        library_root_logger.propagate = False\n\n\ndef _reset_library_root_logger() -> None:\n    global _default_handler\n\n    with _lock:\n        if not _default_handler:\n            return\n\n        library_root_logger = _get_library_root_logger()\n        library_root_logger.removeHandler(_default_handler)\n        library_root_logger.setLevel(logging.NOTSET)\n        _default_handler = None\n\n\ndef get_log_levels_dict() -> Dict[str, int]:\n    return log_levels\n\n\ndef get_logger(name: Optional[str] = None) -> logging.Logger:\n    \"\"\"\n    Return a logger with the specified name.\n\n    This function is not supposed to be directly accessed unless you are writing a custom diffusers module.\n    \"\"\"\n\n    if name is None:\n        name = _get_library_name()\n\n    _configure_library_root_logger()\n    return logging.getLogger(name)\n\n\ndef get_verbosity() -> int:\n    \"\"\"\n    Return the current level for the \ud83e\udd17 Diffusers' root logger as an `int`.\n\n    Returns:\n        `int`:\n            Logging level integers which can be one of:\n\n            - `50`: `diffusers.logging.CRITICAL` or `diffusers.logging.FATAL`\n            - `40`: `diffusers.logging.ERROR`\n            - `30`: `diffusers.logging.WARNING` or `diffusers.logging.WARN`\n            - `20`: `diffusers.logging.INFO`\n            - `10`: `diffusers.logging.DEBUG`\n\n    \"\"\"\n\n    _configure_library_root_logger()\n    return _get_library_root_logger().getEffectiveLevel()\n\n\ndef set_verbosity(verbosity: int) -> None:\n    \"\"\"\n    Set the verbosity level for the \ud83e\udd17 Diffusers' root logger.\n\n    Args:\n        verbosity (`int`):\n            Logging level which can be one of:\n\n            - `diffusers.logging.CRITICAL` or `diffusers.logging.FATAL`\n            - `diffusers.logging.ERROR`\n            - `diffusers.logging.WARNING` or `diffusers.logging.WARN`\n            - `diffusers.logging.INFO`\n            - `diffusers.logging.DEBUG`\n    \"\"\"\n\n    _configure_library_root_logger()\n    _get_library_root_logger().setLevel(verbosity)\n\n\ndef set_verbosity_info() -> None:\n    \"\"\"Set the verbosity to the `INFO` level.\"\"\"\n    return set_verbosity(INFO)\n\n\ndef set_verbosity_warning() -> None:\n    \"\"\"Set the verbosity to the `WARNING` level.\"\"\"\n    return set_verbosity(WARNING)\n\n\ndef set_verbosity_debug() -> None:\n    \"\"\"Set the verbosity to the `DEBUG` level.\"\"\"\n    return set_verbosity(DEBUG)\n\n\ndef set_verbosity_error() -> None:\n    \"\"\"Set the verbosity to the `ERROR` level.\"\"\"\n    return set_verbosity(ERROR)\n\n\ndef disable_default_handler() -> None:\n    \"\"\"Disable the default handler of the \ud83e\udd17 Diffusers' root logger.\"\"\"\n\n    _configure_library_root_logger()\n\n    assert _default_handler is not None\n    _get_library_root_logger().removeHandler(_default_handler)\n\n\ndef enable_default_handler() -> None:\n    \"\"\"Enable the default handler of the \ud83e\udd17 Diffusers' root logger.\"\"\"\n\n    _configure_library_root_logger()\n\n    assert _default_handler is not None\n    _get_library_root_logger().addHandler(_default_handler)\n\n\ndef add_handler(handler: logging.Handler) -> None:\n    \"\"\"adds a handler to the HuggingFace Diffusers' root logger.\"\"\"\n\n    _configure_library_root_logger()\n\n    assert handler is not None\n    _get_library_root_logger().addHandler(handler)\n\n\ndef remove_handler(handler: logging.Handler) -> None:\n    \"\"\"removes given handler from the HuggingFace Diffusers' root logger.\"\"\"\n\n    _configure_library_root_logger()\n\n    assert handler is not None and handler not in _get_library_root_logger().handlers\n    _get_library_root_logger().removeHandler(handler)\n\n\ndef disable_propagation() -> None:\n    \"\"\"\n    Disable propagation of the library log outputs. Note that log propagation is disabled by default.\n    \"\"\"\n\n    _configure_library_root_logger()\n    _get_library_root_logger().propagate = False\n\n\ndef enable_propagation() -> None:\n    \"\"\"\n    Enable propagation of the library log outputs. Please disable the HuggingFace Diffusers' default handler to prevent\n    double logging if the root logger has been configured.\n    \"\"\"\n\n    _configure_library_root_logger()\n    _get_library_root_logger().propagate = True\n\n\ndef enable_explicit_format() -> None:\n    \"\"\"\n    Enable explicit formatting for every \ud83e\udd17 Diffusers' logger. The explicit formatter is as follows:\n    ```\n    [LEVELNAME|FILENAME|LINE NUMBER] TIME >> MESSAGE\n    ```\n    All handlers currently bound to the root logger are affected by this method.\n    \"\"\"\n    handlers = _get_library_root_logger().handlers\n\n    for handler in handlers:\n        formatter = logging.Formatter(\"[%(levelname)s|%(filename)s:%(lineno)s] %(asctime)s >> %(message)s\")\n        handler.setFormatter(formatter)\n\n\ndef reset_format() -> None:\n    \"\"\"\n    Resets the formatting for \ud83e\udd17 Diffusers' loggers.\n\n    All handlers currently bound to the root logger are affected by this method.\n    \"\"\"\n    handlers = _get_library_root_logger().handlers\n\n    for handler in handlers:\n        handler.setFormatter(None)\n\n\ndef warning_advice(self, *args, **kwargs) -> None:\n    \"\"\"\n    This method is identical to `logger.warning()`, but if env var DIFFUSERS_NO_ADVISORY_WARNINGS=1 is set, this\n    warning will not be printed\n    \"\"\"\n    no_advisory_warnings = os.getenv(\"DIFFUSERS_NO_ADVISORY_WARNINGS\", False)\n    if no_advisory_warnings:\n        return\n    self.warning(*args, **kwargs)\n\n\nlogging.Logger.warning_advice = warning_advice\n\n\nclass EmptyTqdm:\n    \"\"\"Dummy tqdm which doesn't do anything.\"\"\"\n\n    def __init__(self, *args, **kwargs):  # pylint: disable=unused-argument\n        self._iterator = args[0] if args else None\n\n    def __iter__(self):\n        return iter(self._iterator)\n\n    def __getattr__(self, _):\n        \"\"\"Return empty function.\"\"\"\n\n        def empty_fn(*args, **kwargs):  # pylint: disable=unused-argument\n            return\n\n        return empty_fn\n\n    def __enter__(self):\n        return self\n\n    def __exit__(self, type_, value, traceback):\n        return\n\n\nclass _tqdm_cls:\n    def __call__(self, *args, **kwargs):\n        if _tqdm_active:\n            return tqdm_lib.tqdm(*args, **kwargs)\n        else:\n            return EmptyTqdm(*args, **kwargs)\n\n    def set_lock(self, *args, **kwargs):\n        self._lock = None\n        if _tqdm_active:\n            return tqdm_lib.tqdm.set_lock(*args, **kwargs)\n\n    def get_lock(self):\n        if _tqdm_active:\n            return tqdm_lib.tqdm.get_lock()\n\n\ntqdm = _tqdm_cls()\n\n\ndef is_progress_bar_enabled() -> bool:\n    \"\"\"Return a boolean indicating whether tqdm progress bars are enabled.\"\"\"\n    global _tqdm_active\n    return bool(_tqdm_active)\n\n\ndef enable_progress_bar() -> None:\n    \"\"\"Enable tqdm progress bar.\"\"\"\n    global _tqdm_active\n    _tqdm_active = True\n\n\ndef disable_progress_bar() -> None:\n    \"\"\"Disable tqdm progress bar.\"\"\"\n    global _tqdm_active\n    _tqdm_active = False\n", "path": "src/diffusers/utils/logging.py"}], "after_files": [{"content": "# coding=utf-8\n# Copyright 2023 Optuna, Hugging Face\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\"\"\" Logging utilities.\"\"\"\n\nimport logging\nimport os\nimport sys\nimport threading\nfrom logging import (\n    CRITICAL,  # NOQA\n    DEBUG,  # NOQA\n    ERROR,  # NOQA\n    FATAL,  # NOQA\n    INFO,  # NOQA\n    NOTSET,  # NOQA\n    WARN,  # NOQA\n    WARNING,  # NOQA\n)\nfrom typing import Dict, Optional\n\nfrom tqdm import auto as tqdm_lib\n\n\n_lock = threading.Lock()\n_default_handler: Optional[logging.Handler] = None\n\nlog_levels = {\n    \"debug\": logging.DEBUG,\n    \"info\": logging.INFO,\n    \"warning\": logging.WARNING,\n    \"error\": logging.ERROR,\n    \"critical\": logging.CRITICAL,\n}\n\n_default_log_level = logging.WARNING\n\n_tqdm_active = True\n\n\ndef _get_default_logging_level() -> int:\n    \"\"\"\n    If DIFFUSERS_VERBOSITY env var is set to one of the valid choices return that as the new default level. If it is\n    not - fall back to `_default_log_level`\n    \"\"\"\n    env_level_str = os.getenv(\"DIFFUSERS_VERBOSITY\", None)\n    if env_level_str:\n        if env_level_str in log_levels:\n            return log_levels[env_level_str]\n        else:\n            logging.getLogger().warning(\n                f\"Unknown option DIFFUSERS_VERBOSITY={env_level_str}, \"\n                f\"has to be one of: { ', '.join(log_levels.keys()) }\"\n            )\n    return _default_log_level\n\n\ndef _get_library_name() -> str:\n    return __name__.split(\".\")[0]\n\n\ndef _get_library_root_logger() -> logging.Logger:\n    return logging.getLogger(_get_library_name())\n\n\ndef _configure_library_root_logger() -> None:\n    global _default_handler\n\n    with _lock:\n        if _default_handler:\n            # This library has already configured the library root logger.\n            return\n        _default_handler = logging.StreamHandler()  # Set sys.stderr as stream.\n        _default_handler.flush = sys.stderr.flush\n\n        # Apply our default configuration to the library root logger.\n        library_root_logger = _get_library_root_logger()\n        library_root_logger.addHandler(_default_handler)\n        library_root_logger.setLevel(_get_default_logging_level())\n        library_root_logger.propagate = False\n\n\ndef _reset_library_root_logger() -> None:\n    global _default_handler\n\n    with _lock:\n        if not _default_handler:\n            return\n\n        library_root_logger = _get_library_root_logger()\n        library_root_logger.removeHandler(_default_handler)\n        library_root_logger.setLevel(logging.NOTSET)\n        _default_handler = None\n\n\ndef get_log_levels_dict() -> Dict[str, int]:\n    return log_levels\n\n\ndef get_logger(name: Optional[str] = None) -> logging.Logger:\n    \"\"\"\n    Return a logger with the specified name.\n\n    This function is not supposed to be directly accessed unless you are writing a custom diffusers module.\n    \"\"\"\n\n    if name is None:\n        name = _get_library_name()\n\n    _configure_library_root_logger()\n    return logging.getLogger(name)\n\n\ndef get_verbosity() -> int:\n    \"\"\"\n    Return the current level for the \ud83e\udd17 Diffusers' root logger as an `int`.\n\n    Returns:\n        `int`:\n            Logging level integers which can be one of:\n\n            - `50`: `diffusers.logging.CRITICAL` or `diffusers.logging.FATAL`\n            - `40`: `diffusers.logging.ERROR`\n            - `30`: `diffusers.logging.WARNING` or `diffusers.logging.WARN`\n            - `20`: `diffusers.logging.INFO`\n            - `10`: `diffusers.logging.DEBUG`\n\n    \"\"\"\n\n    _configure_library_root_logger()\n    return _get_library_root_logger().getEffectiveLevel()\n\n\ndef set_verbosity(verbosity: int) -> None:\n    \"\"\"\n    Set the verbosity level for the \ud83e\udd17 Diffusers' root logger.\n\n    Args:\n        verbosity (`int`):\n            Logging level which can be one of:\n\n            - `diffusers.logging.CRITICAL` or `diffusers.logging.FATAL`\n            - `diffusers.logging.ERROR`\n            - `diffusers.logging.WARNING` or `diffusers.logging.WARN`\n            - `diffusers.logging.INFO`\n            - `diffusers.logging.DEBUG`\n    \"\"\"\n\n    _configure_library_root_logger()\n    _get_library_root_logger().setLevel(verbosity)\n\n\ndef set_verbosity_info() -> None:\n    \"\"\"Set the verbosity to the `INFO` level.\"\"\"\n    return set_verbosity(INFO)\n\n\ndef set_verbosity_warning() -> None:\n    \"\"\"Set the verbosity to the `WARNING` level.\"\"\"\n    return set_verbosity(WARNING)\n\n\ndef set_verbosity_debug() -> None:\n    \"\"\"Set the verbosity to the `DEBUG` level.\"\"\"\n    return set_verbosity(DEBUG)\n\n\ndef set_verbosity_error() -> None:\n    \"\"\"Set the verbosity to the `ERROR` level.\"\"\"\n    return set_verbosity(ERROR)\n\n\ndef disable_default_handler() -> None:\n    \"\"\"Disable the default handler of the \ud83e\udd17 Diffusers' root logger.\"\"\"\n\n    _configure_library_root_logger()\n\n    assert _default_handler is not None\n    _get_library_root_logger().removeHandler(_default_handler)\n\n\ndef enable_default_handler() -> None:\n    \"\"\"Enable the default handler of the \ud83e\udd17 Diffusers' root logger.\"\"\"\n\n    _configure_library_root_logger()\n\n    assert _default_handler is not None\n    _get_library_root_logger().addHandler(_default_handler)\n\n\ndef add_handler(handler: logging.Handler) -> None:\n    \"\"\"adds a handler to the HuggingFace Diffusers' root logger.\"\"\"\n\n    _configure_library_root_logger()\n\n    assert handler is not None\n    _get_library_root_logger().addHandler(handler)\n\n\ndef remove_handler(handler: logging.Handler) -> None:\n    \"\"\"removes given handler from the HuggingFace Diffusers' root logger.\"\"\"\n\n    _configure_library_root_logger()\n\n    assert handler is not None and handler in _get_library_root_logger().handlers\n    _get_library_root_logger().removeHandler(handler)\n\n\ndef disable_propagation() -> None:\n    \"\"\"\n    Disable propagation of the library log outputs. Note that log propagation is disabled by default.\n    \"\"\"\n\n    _configure_library_root_logger()\n    _get_library_root_logger().propagate = False\n\n\ndef enable_propagation() -> None:\n    \"\"\"\n    Enable propagation of the library log outputs. Please disable the HuggingFace Diffusers' default handler to prevent\n    double logging if the root logger has been configured.\n    \"\"\"\n\n    _configure_library_root_logger()\n    _get_library_root_logger().propagate = True\n\n\ndef enable_explicit_format() -> None:\n    \"\"\"\n    Enable explicit formatting for every \ud83e\udd17 Diffusers' logger. The explicit formatter is as follows:\n    ```\n    [LEVELNAME|FILENAME|LINE NUMBER] TIME >> MESSAGE\n    ```\n    All handlers currently bound to the root logger are affected by this method.\n    \"\"\"\n    handlers = _get_library_root_logger().handlers\n\n    for handler in handlers:\n        formatter = logging.Formatter(\"[%(levelname)s|%(filename)s:%(lineno)s] %(asctime)s >> %(message)s\")\n        handler.setFormatter(formatter)\n\n\ndef reset_format() -> None:\n    \"\"\"\n    Resets the formatting for \ud83e\udd17 Diffusers' loggers.\n\n    All handlers currently bound to the root logger are affected by this method.\n    \"\"\"\n    handlers = _get_library_root_logger().handlers\n\n    for handler in handlers:\n        handler.setFormatter(None)\n\n\ndef warning_advice(self, *args, **kwargs) -> None:\n    \"\"\"\n    This method is identical to `logger.warning()`, but if env var DIFFUSERS_NO_ADVISORY_WARNINGS=1 is set, this\n    warning will not be printed\n    \"\"\"\n    no_advisory_warnings = os.getenv(\"DIFFUSERS_NO_ADVISORY_WARNINGS\", False)\n    if no_advisory_warnings:\n        return\n    self.warning(*args, **kwargs)\n\n\nlogging.Logger.warning_advice = warning_advice\n\n\nclass EmptyTqdm:\n    \"\"\"Dummy tqdm which doesn't do anything.\"\"\"\n\n    def __init__(self, *args, **kwargs):  # pylint: disable=unused-argument\n        self._iterator = args[0] if args else None\n\n    def __iter__(self):\n        return iter(self._iterator)\n\n    def __getattr__(self, _):\n        \"\"\"Return empty function.\"\"\"\n\n        def empty_fn(*args, **kwargs):  # pylint: disable=unused-argument\n            return\n\n        return empty_fn\n\n    def __enter__(self):\n        return self\n\n    def __exit__(self, type_, value, traceback):\n        return\n\n\nclass _tqdm_cls:\n    def __call__(self, *args, **kwargs):\n        if _tqdm_active:\n            return tqdm_lib.tqdm(*args, **kwargs)\n        else:\n            return EmptyTqdm(*args, **kwargs)\n\n    def set_lock(self, *args, **kwargs):\n        self._lock = None\n        if _tqdm_active:\n            return tqdm_lib.tqdm.set_lock(*args, **kwargs)\n\n    def get_lock(self):\n        if _tqdm_active:\n            return tqdm_lib.tqdm.get_lock()\n\n\ntqdm = _tqdm_cls()\n\n\ndef is_progress_bar_enabled() -> bool:\n    \"\"\"Return a boolean indicating whether tqdm progress bars are enabled.\"\"\"\n    global _tqdm_active\n    return bool(_tqdm_active)\n\n\ndef enable_progress_bar() -> None:\n    \"\"\"Enable tqdm progress bar.\"\"\"\n    global _tqdm_active\n    _tqdm_active = True\n\n\ndef disable_progress_bar() -> None:\n    \"\"\"Disable tqdm progress bar.\"\"\"\n    global _tqdm_active\n    _tqdm_active = False\n", "path": "src/diffusers/utils/logging.py"}]}