Shortcuts

MLFlowLogger

class lightning.pytorch.loggers.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)[소스]

기반 클래스: lightning.pytorch.loggers.logger.Logger

Log using MLflow.

Install it with pip:

pip install mlflow  # or mlflow-skinny
from lightning.pytorch import Trainer
from lightning.pytorch.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 LightningModule as follows:

from lightning.pytorch 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(...)
매개변수
  • experiment_name (str) – The name of the experiment.

  • run_name (Optional[str]) – Name of the new run. The run_name is internally stored as a mlflow.runName tag. If the mlflow.runName tag has already been set in tags, the value is overridden by the run_name.

  • tracking_uri (Optional[str]) – Address of local or remote tracking server. If not provided, defaults to MLFLOW_TRACKING_URI environment variable if set, otherwise it falls back to file:<save_dir>.

  • tags (Optional[Dict[str, Any]]) – A dictionary tags for the experiment.

  • save_dir (Optional[str]) – 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.

  • log_model (Literal[True, False, ‘all’]) –

    Log checkpoints created by ModelCheckpoint as MLFlow artifacts.

    • if log_model == 'all', checkpoints are logged during training.

    • if log_model == True, checkpoints are logged at the end of training, except when save_top_k == -1 which also logs every checkpoint during training.

    • if log_model == False (default), no checkpoint is logged.

  • prefix (str) – A string to put at the beginning of metric keys.

  • artifact_location (Optional[str]) – The location to store run artifacts. If not provided, the server picks an appropriate default.

  • run_id (Optional[str]) – The run identifier of the experiment. If not provided, a new run is started.

예외 발생

ModuleNotFoundError – If required MLFlow package is not installed on the device.

after_save_checkpoint(checkpoint_callback)[소스]

Called after model checkpoint callback saves a new checkpoint.

매개변수

checkpoint_callback (ModelCheckpoint) – the model checkpoint callback instance

반환 형식

None

finalize(status='success')[소스]

Do any processing that is necessary to finalize an experiment.

매개변수

status (str) – Status that the experiment finished with (e.g. success, failed, aborted)

반환 형식

None

log_hyperparams(params)[소스]

Record hyperparameters.

매개변수
  • params (Union[Dict[str, Any], Namespace]) – Namespace or Dict containing the hyperparameters

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

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

반환 형식

None

log_metrics(metrics, step=None)[소스]

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

매개변수
  • metrics (Mapping[str, float]) – Dictionary with metric names as keys and measured quantities as values

  • step (Optional[int]) – Step number at which the metrics should be recorded

반환 형식

None

property experiment: None

Actual MLflow object. To use MLflow features in your LightningModule do the following.

Example:

self.logger.experiment.some_mlflow_function()
반환 형식

None

property experiment_id: Optional[str]

Create the experiment if it does not exist to get the experiment id.

반환 형식

Optional[str]

반환

The experiment id.

property name: Optional[str]

Get the experiment id.

반환 형식

Optional[str]

반환

The experiment id.

property run_id: Optional[str]

Create the experiment if it does not exist to get the run id.

반환 형식

Optional[str]

반환

The run id.

property save_dir: Optional[str]

The root file directory in which MLflow experiments are saved.

반환 형식

Optional[str]

반환

Local path to the root experiment directory if the tracking uri is local. Otherwise returns None.

property version: Optional[str]

Get the run id.

반환 형식

Optional[str]

반환

The run id.


© Copyright Copyright (c) 2018-2023, Lightning AI et al...

Built with Sphinx using a theme provided by Read the Docs.