Buckets:

rtrm's picture
|
download
raw
11.8 kB
# Logging
🤗 Transformers has a centralized logging system, so that you can setup the verbosity of the library easily.
Currently the default verbosity of the library is `WARNING`.
To change the level of verbosity, just use one of the direct setters. For instance, here is how to change the verbosity
to the INFO level.
```python
import transformers
transformers.logging.set_verbosity_info()
```
You can also use the environment variable `TRANSFORMERS_VERBOSITY` to override the default verbosity. You can set it
to one of the following: `debug`, `info`, `warning`, `error`, `critical`, `fatal`. For example:
```bash
TRANSFORMERS_VERBOSITY=error ./myprogram.py
```
Additionally, some `warnings` can be disabled by setting the environment variable
`TRANSFORMERS_NO_ADVISORY_WARNINGS` to a true value, like *1*. This will disable any warning that is logged using
`logger.warning_advice`. For example:
```bash
TRANSFORMERS_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:
```python
from transformers.utils import logging
logging.set_verbosity_info()
logger = logging.get_logger("transformers")
logger.info("INFO")
logger.warning("WARN")
```
All the methods of this logging module are documented below, the main ones are
[logging.get_verbosity()](/docs/transformers/pr_33892/en/main_classes/logging#transformers.utils.logging.get_verbosity) to get the current level of verbosity in the logger and
[logging.set_verbosity()](/docs/transformers/pr_33892/en/main_classes/logging#transformers.utils.logging.set_verbosity) to set the verbosity to the level of your choice. In order (from the least
verbose to the most verbose), those levels (with their corresponding int values in parenthesis) are:
- `transformers.logging.CRITICAL` or `transformers.logging.FATAL` (int value, 50): only report the most
critical errors.
- `transformers.logging.ERROR` (int value, 40): only report errors.
- `transformers.logging.WARNING` or `transformers.logging.WARN` (int value, 30): only reports error and
warnings. This is the default level used by the library.
- `transformers.logging.INFO` (int value, 20): reports error, warnings and basic information.
- `transformers.logging.DEBUG` (int value, 10): report all information.
By default, `tqdm` progress bars will be displayed during model download. [logging.disable_progress_bar()](/docs/transformers/pr_33892/en/main_classes/logging#transformers.utils.logging.disable_progress_bar) and [logging.enable_progress_bar()](/docs/transformers/pr_33892/en/main_classes/logging#transformers.utils.logging.enable_progress_bar) can be used to suppress or unsuppress this behavior.
## `logging` vs `warnings`[[transformers.utils.logging.captureWarnings]]
Python has two logging systems that are often used in conjunction: `logging`, which is explained above, and `warnings`,
which allows further classification of warnings in specific buckets, e.g., `FutureWarning` for a feature or path
that has already been deprecated and `DeprecationWarning` to indicate an upcoming deprecation.
We use both in the `transformers` library. We leverage and adapt `logging`'s `captureWarnings` method to allow
management of these warning messages by the verbosity setters above.
What does that mean for developers of the library? We should respect the following heuristics:
- `warnings` should be favored for developers of the library and libraries dependent on `transformers`
- `logging` should be used for end-users of the library using it in every-day projects
See reference of the `captureWarnings` method below.
<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">
<docstring><name>transformers.utils.logging.captureWarnings</name><anchor>transformers.utils.logging.captureWarnings</anchor><source>https://github.com/huggingface/transformers/blob/vr_33892/src/transformers/utils/logging.py#L123</source><parameters>[{"name": "capture", "val": ""}]</parameters></docstring>
Calls the `captureWarnings` method from the logging library to enable management of the warnings emitted by the
`warnings` library.
Read more about this method here:
https://docs.python.org/3/library/logging.html#integration-with-the-warnings-module
All warnings will be logged through the `py.warnings` logger.
Careful: this method also adds a handler to this logger if it does not already have one, and updates the logging
level of that logger to the library's root logger.
</div>
## Base setters[[transformers.utils.logging.set_verbosity_error]]
<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">
<docstring><name>transformers.utils.logging.set_verbosity_error</name><anchor>transformers.utils.logging.set_verbosity_error</anchor><source>https://github.com/huggingface/transformers/blob/vr_33892/src/transformers/utils/logging.py#L217</source><parameters>[]</parameters></docstring>
Set the verbosity to the `ERROR` level.
</div>
<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">
<docstring><name>transformers.utils.logging.set_verbosity_warning</name><anchor>transformers.utils.logging.set_verbosity_warning</anchor><source>https://github.com/huggingface/transformers/blob/vr_33892/src/transformers/utils/logging.py#L207</source><parameters>[]</parameters></docstring>
Set the verbosity to the `WARNING` level.
</div>
<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">
<docstring><name>transformers.utils.logging.set_verbosity_info</name><anchor>transformers.utils.logging.set_verbosity_info</anchor><source>https://github.com/huggingface/transformers/blob/vr_33892/src/transformers/utils/logging.py#L202</source><parameters>[]</parameters></docstring>
Set the verbosity to the `INFO` level.
</div>
<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">
<docstring><name>transformers.utils.logging.set_verbosity_debug</name><anchor>transformers.utils.logging.set_verbosity_debug</anchor><source>https://github.com/huggingface/transformers/blob/vr_33892/src/transformers/utils/logging.py#L212</source><parameters>[]</parameters></docstring>
Set the verbosity to the `DEBUG` level.
</div>
## Other functions[[transformers.utils.logging.get_verbosity]]
<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">
<docstring><name>transformers.utils.logging.get_verbosity</name><anchor>transformers.utils.logging.get_verbosity</anchor><source>https://github.com/huggingface/transformers/blob/vr_33892/src/transformers/utils/logging.py#L160</source><parameters>[]</parameters><rettype>`int`</rettype><retdesc>The logging level.</retdesc></docstring>
Return the current level for the 🤗 Transformers's root logger as an int.
<Tip>
🤗 Transformers has following logging levels:
- 50: `transformers.logging.CRITICAL` or `transformers.logging.FATAL`
- 40: `transformers.logging.ERROR`
- 30: `transformers.logging.WARNING` or `transformers.logging.WARN`
- 20: `transformers.logging.INFO`
- 10: `transformers.logging.DEBUG`
</Tip>
</div>
<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">
<docstring><name>transformers.utils.logging.set_verbosity</name><anchor>transformers.utils.logging.set_verbosity</anchor><source>https://github.com/huggingface/transformers/blob/vr_33892/src/transformers/utils/logging.py#L183</source><parameters>[{"name": "verbosity", "val": ": int"}]</parameters><paramsdesc>- **verbosity** (`int`) --
Logging level, e.g., one of:
- `transformers.logging.CRITICAL` or `transformers.logging.FATAL`
- `transformers.logging.ERROR`
- `transformers.logging.WARNING` or `transformers.logging.WARN`
- `transformers.logging.INFO`
- `transformers.logging.DEBUG`</paramsdesc><paramgroups>0</paramgroups></docstring>
Set the verbosity level for the 🤗 Transformers's root logger.
</div>
<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">
<docstring><name>transformers.utils.logging.get_logger</name><anchor>transformers.utils.logging.get_logger</anchor><source>https://github.com/huggingface/transformers/blob/vr_33892/src/transformers/utils/logging.py#L146</source><parameters>[{"name": "name", "val": ": str | None = None"}]</parameters></docstring>
Return a logger with the specified name.
This function is not supposed to be directly accessed unless you are writing a custom transformers module.
</div>
<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">
<docstring><name>transformers.utils.logging.enable_default_handler</name><anchor>transformers.utils.logging.enable_default_handler</anchor><source>https://github.com/huggingface/transformers/blob/vr_33892/src/transformers/utils/logging.py#L231</source><parameters>[]</parameters></docstring>
Enable the default handler of the HuggingFace Transformers's root logger.
</div>
<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">
<docstring><name>transformers.utils.logging.disable_default_handler</name><anchor>transformers.utils.logging.disable_default_handler</anchor><source>https://github.com/huggingface/transformers/blob/vr_33892/src/transformers/utils/logging.py#L222</source><parameters>[]</parameters></docstring>
Disable the default handler of the HuggingFace Transformers's root logger.
</div>
<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">
<docstring><name>transformers.utils.logging.enable_explicit_format</name><anchor>transformers.utils.logging.enable_explicit_format</anchor><source>https://github.com/huggingface/transformers/blob/vr_33892/src/transformers/utils/logging.py#L277</source><parameters>[]</parameters></docstring>
<ExampleCodeBlock anchor="transformers.utils.logging.enable_explicit_format.example">
Enable explicit formatting for every HuggingFace Transformers's logger. The explicit formatter is as follows:
```
[LEVELNAME|FILENAME|LINE NUMBER] TIME >> MESSAGE
```
</ExampleCodeBlock>
All handlers currently bound to the root logger are affected by this method.
</div>
<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">
<docstring><name>transformers.utils.logging.reset_format</name><anchor>transformers.utils.logging.reset_format</anchor><source>https://github.com/huggingface/transformers/blob/vr_33892/src/transformers/utils/logging.py#L292</source><parameters>[]</parameters></docstring>
Resets the formatting for HuggingFace Transformers's loggers.
All handlers currently bound to the root logger are affected by this method.
</div>
<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">
<docstring><name>transformers.utils.logging.enable_progress_bar</name><anchor>transformers.utils.logging.enable_progress_bar</anchor><source>https://github.com/huggingface/transformers/blob/vr_33892/src/transformers/utils/logging.py#L397</source><parameters>[]</parameters></docstring>
Enable tqdm progress bar.
</div>
<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">
<docstring><name>transformers.utils.logging.disable_progress_bar</name><anchor>transformers.utils.logging.disable_progress_bar</anchor><source>https://github.com/huggingface/transformers/blob/vr_33892/src/transformers/utils/logging.py#L404</source><parameters>[]</parameters></docstring>
Disable tqdm progress bar.
</div>
<EditOnGithub source="https://github.com/huggingface/transformers/blob/main/docs/source/en/main_classes/logging.md" />

Xet Storage Details

Size:
11.8 kB
·
Xet hash:
4dc918e63f1e8814dc864d843e8f87b0b1f9137fd65d067b2b50cb7b2f923526

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.