How to get current run_id inside of mlflow.start_run()?

mlflow.active_run() returns nothing so I can't just usecurrent_rui_id = mlflow.active_run().info.run_id

I have to get run_id inside of this construction for being able to continue logging parameters, metrics and artifacts inside of another block but for the same model:

with mlflow.start_run(run_name="test_ololo"): """ fitting a model here ... """ for name, val in metrics: mlflow.log_metric(name, np.float(val)) # Log our parameters into mlflow for k, v in params.items(): mlflow.log_param(key=k, value=v) pytorch.log_model(learn.model, f'model') mlflow.log_artifact('./outputs/fig.jpg')

I have to get current run_id to continue training inside the same run

with mlflow.start_run(run_id="215d3a71925a4709a9b694c45012988a"): """ fit again log_metrics """ pytorch.log_model(learn.model, f'model') mlflow.log_artifact('./outputs/fig2.jpg')

3 Answers

with mlflow.start_run(run_name="test_ololo") as run: run_id = run.info.run_id
1

You can try this code snippet:

import mlflow
mlflow.start_run()
run = mlflow.active_run()
print("Active run_id: {}".format(run.info.run_id))
mlflow.end_run()
1

The above should work and is in fact the best way to get a hold of active run inside of the with mlflow.start_run() block.

For completeness, mlflow.active_run().info.run_id will also work if executed inside of the with block. The with block will end mlflow run on exit, so there is no active run once the block exited.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like