有一个Github问题 https://github.com/mlflow/mlflow/issues/2350对此,以及贡献者dmatrix https://github.com/mlflow/mlflow/issues/2350#issuecomment-677922065很友善地提供了notebook https://github.com/dmatrix/google-colab/blob/master/mlflow_issue_2350.ipynb具有完整的解决方案,利用pyngrok
.
这是代码(旨在在 Colab 笔记本上运行),使用隐式重新发布到此处作者的许可 https://github.com/mlflow/mlflow/issues/2350#issuecomment-689657744:
!pip install mlflow --quiet
!pip install pyngrok --quiet
import mlflow
with mlflow.start_run(run_name="MLflow on Colab"):
mlflow.log_metric("m1", 2.0)
mlflow.log_param("p1", "mlflow-colab")
# run tracking UI in the background
get_ipython().system_raw("mlflow ui --port 5000 &") # run tracking UI in the background
# create remote tunnel using ngrok.com to allow local port access
# borrowed from https://colab.research.google.com/github/alfozan/MLflow-GBRT-demo/blob/master/MLflow-GBRT-demo.ipynb#scrollTo=4h3bKHMYUIG6
from pyngrok import ngrok
# Terminate open tunnels if exist
ngrok.kill()
# Setting the authtoken (optional)
# Get your authtoken from https://dashboard.ngrok.com/auth
NGROK_AUTH_TOKEN = ""
ngrok.set_auth_token(NGROK_AUTH_TOKEN)
# Open an HTTPs tunnel on port 5000 for http://localhost:5000
ngrok_tunnel = ngrok.connect(addr="5000", proto="http", bind_tls=True)
print("MLflow Tracking UI:", ngrok_tunnel.public_url)
其输出将是pyngrok
- 生成的 URL 如下:
MLflow Tracking UI: https://0a23d7a7d0c4.ngrok.io
单击它将进入 MLfLow GUI 屏幕。
(对原始代码稍加修改,感谢pyngrok
创造者,亚历克斯·莱尔德 https://stackoverflow.com/users/1128413/alexdlaird)
使用 MLflow 版本 1.10.0 和 1.11.0 进行测试。