kiwi.loggers

Module Contents

Classes

MLFlowTrackingLogger

Log using MLflow. Install it with pip:

Functions

normalize_metric_key(key)

Normalize key name for MLflow.

validate_metric_value(value)

kiwi.loggers.logger
kiwi.loggers._INVALID_PARAM_AND_METRIC_CHARACTERS
kiwi.loggers.normalize_metric_key(key)

Normalize key name for MLflow.

mlflow.exceptions.MlflowException: Invalid metric name: ‘WMT19_F1_MULT+PEARSON’. Names may only contain alphanumerics, underscores (_), dashes (-), periods (.), spaces ( ), and slashes (/).

This is raised by matching against r"^[/\w.\- ]*$".

kiwi.loggers.validate_metric_value(value)
class kiwi.loggers.MLFlowTrackingLogger(experiment_name: str = 'default', run_id: Optional[str] = None, tracking_uri: Optional[str] = None, tags: Optional[Dict[str, Any]] = None, save_dir: Optional[str] = None, always_log_artifacts: bool = False)

Bases: pytorch_lightning.loggers.MLFlowLogger

Log using MLflow. Install it with pip:

pip install mlflow

Example

>>> from pytorch_lightning import Trainer
>>> from pytorch_lightning.loggers import MLFlowLogger
>>> mlf_logger = MLFlowLogger(
...     experiment_name="default",
...     tracking_uri="file:./ml-runs"
... )
>>> trainer = Trainer(logger=mlf_logger)

Use the logger anywhere in you LightningModule as follows:

>>> from pytorch_lightning import LightningModule
>>> class LitModel(LightningModule):
...     def training_step(self, batch, batch_idx):
...         # example
...         self.logger.experiment.whatever_ml_flow_supports(...)
...
...     def any_lightning_module_function_or_hook(self):
...         self.logger.experiment.whatever_ml_flow_supports(...)
Parameters
  • experiment_name – The name of the experiment

  • tracking_uri – Address of local or remote tracking server. If not provided, defaults to file:<save_dir>.

  • tags – A dictionary tags for the experiment.

  • save_dir – A path to a local directory where the MLflow runs get saved. Defaults to ./mlflow if tracking_uri is not provided. Has no effect if tracking_uri is provided.

property tracking_uri(self)
log_param(self, key, value)
log_hyperparams(self, params: Dict[str, Any])None

Record hyperparameters.

Parameters

paramsNamespace containing the hyperparameters

log_metrics(self, metrics: Dict[str, float], step: Optional[int] = None, prefix='')None

Records metrics. This method logs metrics as as soon as it received them. If you want to aggregate metrics for one specific step, use the agg_and_log_metrics() method.

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

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

log_artifact(self, local_path, artifact_path=None)
log_artifacts(self, local_dir, artifact_path=None)
get_artifact_uri(self)
log_model(self, local_file, name=None)
log_tag(self, name: str, value: str)
log_tags(self, tags: Dict[str, str])