简体   繁体   中英

Unable to run mlflow ui in Jupyter

I am new to MLflow. I was trying to use it in Jupyter. As part of the quickstart, I ran the following code:

import os
from mlflow import log_metric, log_param, log_artifact

if __name__ == "__main__":
    # Log a parameter (key-value pair)
    log_param("param1", 5)

    # Log a metric; metrics can be updated throughout the run
    log_metric("foo", 1)
    log_metric("foo", 2)
    log_metric("foo", 3)

    # Log an artifact (output file)
    with open("output.txt", "w") as f:
        f.write("Hello world!")
    log_artifact("output.txt")

which ran without any problems. However when I then typed in mlflow ui, I got the error: invalid syntax. What could I be doing wrong?

The Documentation in MLFlow Quickstart assumes that you saved this code as a Python .py script and run it in Terminal (or other command-line interpreter). When you run the script, either in Terminal or in Jupyter, a folder named mlruns is automatically created.

"By default, wherever you run your program, the tracking API writes data into files into an mlruns directory. You can then run MLflow's Tracking UI"

If you want to run MLflow's Tracking UI from the Notebook, you should write !mlflow ui instead of mlflow ui . You get a syntax error because it is not a valid Python syntax. If you run !mlflow ui from the Notebook you can still view the Tracking UI at http://localhost:5000 . In this case, however, you will not be able to run any other cell, since the current cell keeps running.

You should better use Terminal, and run the code mlflow ui in the same current working directory as the one that contains your Notebook and the mlruns folder.

Maybe a short step by step list for Beginners like me: if you want to run the mlflow ui locally on Jupiter Notebook.

  1. run your model in mlflow.start_run()
  2. open anaconda prompt PowerShell and run mlflow ui , it will return an answer telling you that the ui now runs locally on the local Server 5000
  3. run !mlflow ui as explained in the answer above, the cell should run constantly as said above
  4. Now open the link: http://localhost:5000 , as explained above

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM