topobench.utils.pylogger module#
A multi-GPU-friendly python command line logger.
- class Mapping#
Bases:
CollectionA Mapping is a generic container for associating key/value pairs.
This class provides concrete generic implementations of all methods except for __getitem__, __iter__, and __len__.
- get(k[, d]) D[k] if k in D, else d. d defaults to None.#
- items() a set-like object providing a view on D's items#
- keys() a set-like object providing a view on D's keys#
- values() an object providing a view on D's values#
- class RankedLogger(name='topobench.utils.pylogger', rank_zero_only=False, extra=None)#
Bases:
LoggerAdapterInitialize a multi-GPU-friendly python command line logger.
The logger logs on all processes with their rank prefixed in the log message.
- Parameters:
- namestr, optional
The name of the logger, by default __name__.
- rank_zero_onlybool, optional
Whether to force all logs to only occur on the rank zero process (default: False).
- extraMapping[str, object], optional
A dict-like object which provides contextual information. See logging.LoggerAdapter for more information (default: None).
- __init__(name='topobench.utils.pylogger', rank_zero_only=False, extra=None)#
Initialize the adapter with a logger and a dict-like object which provides contextual information. This constructor signature allows easy stacking of LoggerAdapters, if so desired.
You can effectively pass keyword arguments as shown in the following example:
adapter = LoggerAdapter(someLogger, dict(p1=v1, p2=”v2”))
- log(level, msg, rank=None, *args, **kwargs)#
Delegate a log call to the underlying logger.
The function first prefixes the message with the rank of the process it’s being logged from and then logs the message. If ‘rank’ is provided, then the log will only occur on that rank/process.
- Parameters:
- levelint
The level to log at. Look at logging.__init__.py for more information.
- msgstr
The message to log.
- rankint, optional
The rank to log at (default: None).
- *argsAny
Additional args to pass to the underlying logging function.
- **kwargsAny
Any additional keyword args to pass to the underlying logging function.
- rank_prefixed_message(message, rank)#
Add a prefix with the rank to a message.
- rank_zero_only(fn, default=None)#
Wrap a function to call internal function only in rank zero.
Function that can be used as a decorator to enable a function/method being called only on global rank 0.