You are viewing v0.19.0 version.
A newer version
v1.2.1 is available.
Logging with Accelerate
Accelerate has its own logging utility to handle logging while in a distributed system.
To utilize this replace cases of logging
with accelerate.logging
:
- import logging
+ from accelerate.logging import get_logger
- logger = logging.getLogger(__name__)
+ logger = get_logger(__name__)
Setting the log level
The log level can be set with the ACCELERATE_LOG_LEVEL
environment variable or by passing
log_level
to get_logger
:
from accelerate.logging import get_logger
logger = get_logger(__name__, log_level="INFO")
accelerate.logging.get_logger
< source >( name: str log_level: str = None )
Returns a logging.Logger
for name
that can handle multiprocessing.
If a log should be called on all processes, pass main_process_only=False
Example:
>>> from accelerate.logging import get_logger
>>> logger = get_logger(__name__)
>>> logger.info("My log", main_process_only=False)
>>> logger.debug("My log", main_process_only=True)
>>> logger = get_logger(__name__, log_level="DEBUG")
>>> logger.info("My log")
>>> logger.debug("My second log")