Shortcuts

logger

Functions

merge_dicts

Merge a sequence with dictionaries into one dictionary by aggregating the same keys with some given function.

Classes

DummyLogger

Dummy logger for internal use.

Logger

Base class for experiment loggers.

Abstract base class used to build new loggers.

class lightning.pytorch.loggers.logger.DummyLogger[source]

Bases: Logger

Dummy logger for internal use.

It is useful if we want to disable user’s logger for a feature, but still ensure that user code can run

log_hyperparams(*args, **kwargs)[source]

Record hyperparameters.

Parameters:
  • paramsNamespace or Dict containing the hyperparameters

  • args (Any) – Optional positional arguments, depends on the specific logger being used

  • kwargs (Any) – Optional keyword arguments, depends on the specific logger being used

Return type:

None

log_metrics(*args, **kwargs)[source]

Records metrics. This method logs metrics as soon as it received them.

Parameters:
  • metrics – Dictionary with metric names as keys and measured quantities as values

  • step – Step number at which the metrics should be recorded

Return type:

None

property experiment: _DummyExperiment

Return the experiment object associated with this logger.

property name: str

Return the experiment name.

property version: str

Return the experiment version.

class lightning.pytorch.loggers.logger.Logger[source]

Bases: Logger, ABC

Base class for experiment loggers.

after_save_checkpoint(checkpoint_callback)[source]

Called after model checkpoint callback saves a new checkpoint.

Parameters:

checkpoint_callback (ModelCheckpoint) – the model checkpoint callback instance

Return type:

None

property save_dir: Optional[str]

Return the root directory where experiment logs get saved, or None if the logger does not save data locally.

lightning.pytorch.loggers.logger.merge_dicts(dicts, agg_key_funcs=None, default_func=<function mean>)[source]

Merge a sequence with dictionaries into one dictionary by aggregating the same keys with some given function.

Parameters:
  • dicts (Sequence[Mapping]) – Sequence of dictionaries to be merged.

  • agg_key_funcs (Optional[Mapping]) – Mapping from key name to function. This function will aggregate a list of values, obtained from the same key of all dictionaries. If some key has no specified aggregation function, the default one will be used. Default is: None (all keys will be aggregated by the default function).

  • default_func (Callable[[Sequence[float]], float]) – Default function to aggregate keys, which are not presented in the agg_key_funcs map.

Return type:

Dict

Returns:

Dictionary with merged values.

Examples

>>> import pprint
>>> d1 = {'a': 1.7, 'b': 2.0, 'c': 1, 'd': {'d1': 1, 'd3': 3}}
>>> d2 = {'a': 1.1, 'b': 2.2, 'v': 1, 'd': {'d1': 2, 'd2': 3}}
>>> d3 = {'a': 1.1, 'v': 2.3, 'd': {'d3': 3, 'd4': {'d5': 1}}}
>>> dflt_func = min
>>> agg_funcs = {'a': np.mean, 'v': max, 'd': {'d1': sum}}
>>> pprint.pprint(merge_dicts([d1, d2, d3], agg_funcs, dflt_func))
{'a': 1.3,
 'b': 2.0,
 'c': 1,
 'd': {'d1': 3, 'd2': 3, 'd3': 3, 'd4': {'d5': 1}},
 'v': 2.3}