Log using MLflow.
- class pytorch_lightning.loggers.mlflow.MLFlowLogger(experiment_name='lightning_logs', run_name=None, tracking_uri=None, tags=None, save_dir='./mlruns', log_model=False, prefix='', artifact_location=None, run_id=None)¶
Log using MLflow.
Install it with pip:
pip install mlflow
from pytorch_lightning import Trainer from pytorch_lightning.loggers import MLFlowLogger mlf_logger = MLFlowLogger(experiment_name="lightning_logs", tracking_uri="file:./ml-runs") trainer = Trainer(logger=mlf_logger)
Use the logger anywhere in your
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(...)
str]) – Name of the new run. The run_name is internally stored as a
mlflow.runNametag. If the
mlflow.runNametag has already been set in tags, the value is overridden by the run_name.
Log checkpoints created by
ModelCheckpointas MLFlow artifacts.
log_model == 'all', checkpoints are logged during training.
log_model == True, checkpoints are logged at the end of training, except when
== -1which also logs every checkpoint during training.
log_model == False(default), no checkpoint is logged.
ModuleNotFoundError – If required MLFlow package is not installed on the device.
Called after model checkpoint callback saves a new checkpoint.
Do any processing that is necessary to finalize an experiment.
- log_metrics(metrics, step=None)¶
Records metrics. This method logs metrics as soon as it received them.
- property experiment: None¶
Actual MLflow object. To use MLflow features in your
LightningModuledo the following.
- property experiment_id: Optional[str]¶
Create the experiment if it does not exist to get the experiment id.
The experiment id.
- property run_id: Optional[str]¶
Create the experiment if it does not exist to get the run id.
The run id.
- property save_dir: Optional[str]¶
The root file directory in which MLflow experiments are saved.
Local path to the root experiment directory if the tracking uri is local. Otherwise returns None.