hamiddimyati
03/28/2024, 10:59 AMkedro-mlflow
concept? In my case, I use pytorch lightning
, and they provided automatic logging using mlflow
. Using this logger, the metrics are automatically saved into a new folder. I'm wondering how to save this training metrics as artifact of experiment that can also be tracked in Kedro
catalog. Please help :)marrrcin
03/28/2024, 1:01 PMfrom 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)
So you need to bind the lightning logger to the current mlflow configuration.
It's just a matter of getting the run_id
from the current kedro-mlflow run:
def get_mlflow_run_id():
run_id = None
if (ar := mlflow.active_run()) and ar.info.run_id:
run_id = ar.info.run_id
return run_id
And similarly for other parameters. You can also use Kedro hooks to extract experiment_name
/ tracking_uri
from `kedro-mlflow`'s config, as it attaches itself to Kedro Context like context.mlflow
hamiddimyati
03/28/2024, 1:26 PMYolan Honoré-Rougé
03/29/2024, 7:42 AMmlflow.set_tracking_uri
and mlflow.set_experiment
so the MlflowLogger
of pytorch lightning should default to this. If it doesn't, it means that there is some configuration override happening under the hood, so we should check the source codeYolan Honoré-Rougé
03/29/2024, 7:43 AMmarrrcin
03/29/2024, 8:05 AMmarrrcin
03/29/2024, 8:06 AMhamiddimyati
04/01/2024, 7:33 AMexperiment_name
and tracking_uri
using Kedro hooks means should use I after_context_created
? Then, how to bring those info into the training node? What I think is to add them into catalog, which I can access those two as inputs in a training node. Is it a good approach or there is a better way? thankshamiddimyati
04/01/2024, 11:27 AMmarrrcin
04/02/2024, 7:20 AMafter_context_created
and before_node_run
- first one captures reference to the Kedro Context and the second one injects `experiment_name`/`tracking_uri` etc into the node. Example (of this idea - not exactly your case):
https://linen-slack.kedro.org/t/10362890/hi-all-another-question-slightly-smiling-face-i-am-creating-#ce99c8ab-3307-4932-9ff8-1e416e7f48ac