【 Cloud 】於 Azure Ubuntu VM 安裝 mlflow 與 Jupyter

內容

  • 學習目標
  • 前置準備作業
  • 開啟 Azure Ubuntu VM 的 Port
  • 安裝 mlflow
  • 安裝 PostgreSQL 與設定
  • 安裝 Jupyter 與設定
  • 測試與驗證

學習目標

  • 如何在 Azure Ubuntu VM 安裝 mlflowJupyter

前置準備作業

  • 已建立 Azure 帳號並能正常登入
  • 已建立 Azure Ubuntu VM

開啟 Azure Ubuntu VM 的 Port

Step 1. 開啟 mlflow 所使用的 5000 埠

  • 點選左側的 Networking > 再點選 Add inbound port rule > 輸入 5000 後再按 Add


Step 2. 開啟 Jupyter 所使用的 8888 埠

  • 點選左側的 Networking > 再點選 Add inbound port rule > 輸入 8888 後再按 Add

安裝 mlflow

Step 1. 登入到 Azure Ubuntu VM


Step 2. 安裝 pip

  • 於終端機輸入下方指令來進行更新

    sudo apt update
    

  • 於終端機輸入下方指令來安裝 pip

    sudo apt install -y python3-pip
    

  • 於終端機輸入下方指令來確認 pip 版本

    pip3 -V
    

  • 於終端機輸入下方指令來確認 python3 版本

    python3 -V
    


Step 3. 安裝 mlflow

  • 於終端機輸入下方指令

    pip3 install mlflow click==8.0.4
    

  • 確認 mlflow 版本 ( 請重新登入到 Azure Ubuntu VM )

    mlflow --version
    

安裝 PostgreSQL 與設定

Step 1. 安裝 PostgreSQL

  • 於終端機輸入下方指令

    sudo apt-get install -y postgresql postgresql-contrib postgresql-server-dev-all
    


Step 2. 連結到 PostgreSQL

  • 於終端機輸入下方指令

    sudo -u postgres psql
    


Step 3. 建立資料庫與使用者

  • 於終端機輸入下方指令來建立資料庫

    CREATE DATABASE mlflow;
    

  • 於終端機輸入下方指令來建立使用者與密碼

    • 本範例使用 mlflow 來建立使用者與使用 Qwer123456 來建立密碼
    CREATE USER mlflow WITH ENCRYPTED PASSWORD 'Qwer123456';
    

  • 於終端機輸入下方指令來設定權限

    GRANT ALL PRIVILEGES ON DATABASE mlflow TO mlflow;
    


Step 4. 確認使用者

  • 於終端機輸入下方指令

    \du
    


Step 5. 確認資料庫

  • 於終端機輸入下方指令

    \list
    


Step 6. 離開

  • 於終端機輸入下方指令

    \q
    


Step 7. 安裝 psycopg2

  • 於終端機輸入下方指令

    pip3 install psycopg2
    

啟動 mlflow

Step 1. 啟動

  • 於終端機輸入下方指令

    • 本範例使用 mlflow 來建立資料庫的使用者與使用 Qwer123456 來建立密碼
    mlflow server --backend-store-uri postgresql://mlflow:Qwer123456@localhost/mlflow --default-artifact-root file:/home/`whoami`/mlruns -h 0.0.0.0 -p 5000
    


Step 2. 透過瀏覽器開啟 mlflow 的 Dashboard

安裝 Jupyter 與設定

Step 1. 安裝

  • 於終端機輸入下方指令
    pip3 install jupyter
    pip3 install ipykernel
    

Step 2. 取得 sha1 樣式的密碼

  • 於終端機輸入下方指令來進入 python 命令模式

    python3
    

  • 於終端機輸入下方指令

    from notebook.auth import passwd
    

  • 於終端機輸入下方指令來取得 sha1

    • 本範例使用 Qwer1234 來建立密碼
    passwd('Qwer1234', 'sha1')
    

  • 於終端機輸入下方指令

    exit()
    


Step 3. 設定 Jupyter Notebook 登入密碼

  • 於終端機輸入下方指令來建立 Jupyter 的 Config

    jupyter notebook --generate-config
    

  • 於終端機輸入下方指令來修改設定檔

    vi .jupyter/jupyter_notebook_config.py
    
  • 修改 IP

    搜尋 /c.NotebookApp.ip
    
    修改成 c.NotebookApp.ip = '0.0.0.0'
    
    • 修改前
    • 修改後
  • 修改 browser

    搜尋 /c.NotebookApp.open_browser
    
    修改成 remove # False
    
    • 修改前

    • 修改後

  • 修改 Password,當修改完成後存檔離開

    搜尋 /c.NotebookApp.password
    
    修改成 Step 2. 取得 sha1 樣式的密碼
    
    • 修改前

    • 修改後


Step 4. 啟動 Jupyter

  • 於終端機輸入下方指令
    jupyter notebook
    

Step 5. 透過瀏覽器開啟 Jupyter 的 Dashboard

  • 於瀏覽器網址列輸入下方 URL 後再輸入所設定的密碼

  • 登入成功

  • 進入編輯頁面
    • 點選右上角的 New > 再點選 Python3 (ipykernel)

測試與驗證

Step 1. 建立名為 test 的實驗環境


Step 2. 建立 Log 與 Metric


Step 3. 回到 mlflow 的 Dashboard

GitHub

List of blogs