cancel
Showing results for 
Search instead for 
Did you mean: 
Machine Learning
Dive into the world of machine learning on the Databricks platform. Explore discussions on algorithms, model training, deployment, and more. Connect with ML enthusiasts and experts.
cancel
Showing results for 
Search instead for 
Did you mean: 

Model Registration and hosting

intelliconnectq
New Contributor II

I have train & tested a model in databricks, now I want to register it and host it. But I am unable too do so. Please find attach snapshot of code & error

intelliconnectq_0-1762230437372.png

 

1 ACCEPTED SOLUTION

Accepted Solutions

joelrobin
Databricks Employee
Databricks Employee

Hi @intelliconnectq The above code will fail with AttributeError: 'NoneType' object has no attribute 'info' on the line: model_uri = f"runs:/{mlflow.active_run().info.run_id}/xgboost-model" 

This happens because once the with mlflow.start_run(): block ends, the MLflow run is no longer active, so calling mlflow.active_run() returns None. You cannot fetch run info after the run is closed.​ 

Resolution:
You need to fetch the run ID inside the with block while the run is still active:
with mlflow.start_run() as run:
    mlflow.xgboost.log_model(xgb_model, "xgboost-model", signature=signature)
    mlflow.log_metric("rmse", rmse)
    mlflow.log_metric("mae", mae)
    run_id = run.info.run_id  # Capture run_id here

model_uri = f"runs:/{run_id}/xgboost-model"
registered_model = mlflow.register_model(model_uri, "catalog.schema.RealEstateValueEstimator")
 

View solution in original post

2 REPLIES 2

joelrobin
Databricks Employee
Databricks Employee

Hi @intelliconnectq The above code will fail with AttributeError: 'NoneType' object has no attribute 'info' on the line: model_uri = f"runs:/{mlflow.active_run().info.run_id}/xgboost-model" 

This happens because once the with mlflow.start_run(): block ends, the MLflow run is no longer active, so calling mlflow.active_run() returns None. You cannot fetch run info after the run is closed.​ 

Resolution:
You need to fetch the run ID inside the with block while the run is still active:
with mlflow.start_run() as run:
    mlflow.xgboost.log_model(xgb_model, "xgboost-model", signature=signature)
    mlflow.log_metric("rmse", rmse)
    mlflow.log_metric("mae", mae)
    run_id = run.info.run_id  # Capture run_id here

model_uri = f"runs:/{run_id}/xgboost-model"
registered_model = mlflow.register_model(model_uri, "catalog.schema.RealEstateValueEstimator")
 

Thank you