colossalai.logging

colossalai.logging.get_dist_logger(name='colossalai')[source]

Get logger instance based on name. The DistributedLogger will create singleton instances, which means that only one logger instance is created per name.

Parameters

name (str) – name of the logger, name must be unique

Returns

A distributed logger singleton instance.

Return type

colossalai.logging.DistributedLogger

class colossalai.logging.DistributedLogger(name)[source]

This is a distributed event logger class essentially based on logging.

Parameters

name (str) – The name of the logger.

Note

The parallel_mode used in info, warning, debug and error should be concluded in ParallelMode. More details about ParallelMode could be found in parallel_mode.

static get_instance(name)[source]

Get the unique single logger instance based on name.

Parameters

name (str) – The name of the logger.

Returns

A DistributedLogger object

Return type

DistributedLogger

set_level(level)[source]

Set the logging level

Parameters

level (str) – Can only be INFO, DEBUG, WARNING and ERROR.

log_to_file(path, mode='a', level='INFO', suffix=None)[source]

Save the logs to file

Parameters
  • path (A string or pathlib.Path object) – The file to save the log.

  • mode (str) – The mode to write log into the file.

  • level (str) – Can only be INFO, DEBUG, WARNING and ERROR.

  • suffix (str) – The suffix string of log’s name.

info(message, parallel_mode=ParallelMode.GLOBAL, ranks=None)[source]

Log an info message.

Parameters
  • message (str) – The message to be logged.

  • parallel_mode (colossalai.context.parallel_mode.ParallelMode) – The parallel mode used for logging. Defaults to ParallelMode.GLOBAL.

  • ranks (List[int]) – List of parallel ranks.

warning(message, parallel_mode=ParallelMode.GLOBAL, ranks=None)[source]

Log a warning message.

Parameters
  • message (str) – The message to be logged.

  • parallel_mode (colossalai.context.parallel_mode.ParallelMode) – The parallel mode used for logging. Defaults to ParallelMode.GLOBAL.

  • ranks (List[int]) – List of parallel ranks.

debug(message, parallel_mode=ParallelMode.GLOBAL, ranks=None)[source]

Log a debug message.

Parameters
  • message (str) – The message to be logged.

  • parallel_mode (colossalai.context.parallel_mode.ParallelMode) – The parallel mode used for logging. Defaults to ParallelMode.GLOBAL.

  • ranks (List[int]) – List of parallel ranks.

error(message, parallel_mode=ParallelMode.GLOBAL, ranks=None)[source]

Log an error message.

Parameters
  • message (str) – The message to be logged.

  • parallel_mode (colossalai.context.parallel_mode.ParallelMode) – The parallel mode used for logging. Defaults to ParallelMode.GLOBAL.

  • ranks (List[int]) – List of parallel ranks.

colossalai.logging.disable_existing_loggers(include=None, exclude=['colossalai'])[source]

Set the level of existing loggers to WARNING. By default, it will “disable” all existing loggers except the logger named “colossalai”.

Parameters
  • include (Optional[List[str]], optional) – Loggers whose name in this list will be disabled. If set to None, exclude argument will be used. Defaults to None.

  • exclude (List[str], optional) – Loggers whose name not in this list will be disabled. This argument will be used only when include is None. Defaults to [‘colossalai’].