Accelerate documentation

Logging with Accelerate

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

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")


< >

( name: str log_level: str = None )


  • name (str) — The name for the logger, such as __file__
  • log_level (str, optional) — The log level to use. If not passed, will default to the LOG_LEVEL environment variable, or INFO if not

Returns a logging.Logger for name that can handle multiprocessing.

If a log should be called on all processes, pass main_process_only=False If a log should be called on all processes and in order, also pass in_order=True


>>> from accelerate.logging import get_logger

>>> logger = get_logger(__name__)

>>>"My log", main_process_only=False)
>>> logger.debug("My log", main_process_only=True)

>>> logger = get_logger(__name__, log_level="DEBUG")
>>>"My log")
>>> logger.debug("My second log")

>>> from accelerate import Accelerator

>>> accelerator = Accelerator()
>>> array = ["a", "b", "c", "d"]
>>> letter_at_rank = array[accelerator.process_index]
>>>, in_order=True)