newleaf
newleaf

Reputation: 2457

mlflow Exception: Run with UUID is already active

Used mlflow.set_tracking_uri to set up tracking_uri and set_experiment, got an error and check back to run following code again. got an error that "Exception: Run with UUID is already active." Try to use mlflow.end_run to end current run, but got RestException: RESOURCE_DOES_NOT_EXIST: Run UUID not found. Currently stuck in this infinite loop. Any suggestion?

    mlflow.set_experiment("my_experiment")
    mlflow.start_run(run_name='my_project')
    mlflow.set_tag('input_len',len(input))
    mlflow.log_param('metrics', r2)

Upvotes: 3

Views: 8194

Answers (2)

Prakhar Patidar
Prakhar Patidar

Reputation: 144

In my case, i was using mlflow.get_artifact_uri() just after set_tracking_uri().

Mlflow creates a run for get_artifact_uri() function and when we again try to start a run, it throws the above exception.

Buggy code

mlflow.set_tracking_uri("http://localhost:5000")
mlflow.set_experiment('Exp1')
print('artifact uri:', mlflow.get_artifact_uri())

with mlflow.start_run():
    mlflow.log_param('SIZE',100)        
Exception: Run with UUID f7d3c1318eeb403cbcf6545b061654e1 is already active. To start a new run, first end the current run with mlflow.end_run(). To start a nested run, call start_run with nested=True

So get_artifact_uri() has to be used inside the start_run content. and it worked.

Working code

mlflow.set_tracking_uri("http://localhost:5000")
mlflow.set_experiment('Exp1')

with mlflow.start_run():
    print('artifact uri:', mlflow.get_artifact_uri())
    mlflow.log_param('SIZE',100)    

Upvotes: 7

Addison Klinke
Addison Klinke

Reputation: 1186

My case was slightly different, but I'm posting the solution here in case it helps newcomers to this thread. I was accidentally setting run tags before starting the run

mlflow.set_experiment('my_experiment')
mlflow.set_tag('input_len', len(input))  # Auto-creates a run ID
mlflow.start_run(run_name='my_project')  # Tries to name the same run, throwing error

Ensuring that start_run came before all other logging/tags solved the issue

Upvotes: 6

Related Questions