日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

mlflow_在生产中设置MLflow

發布時間:2023/12/15 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mlflow_在生产中设置MLflow 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

mlflow

This is the first article in my MLflow tutorial series:

這是我的MLflow教程系列的第一篇文章:

  • Setup MLflow in Production (you are here!)

    在生產環境中設置MLflow (您在這里!)

  • MLflow: Basic logging functions

    MLflow:基本日志記錄功能

  • MLflow logging for TensorFlow

    TensorFlow的MLflow日志記錄

  • MLflow Projects

    MLflow項目

  • Retrieving the best model using Python API for MLflow

    使用適用于MLflow的Python API檢索最佳模型

  • Serving a model using MLflow

    使用MLflow服務模型

  • MLflow is an open-source platform for machine learning lifecycle management. Recently, I set up MLflow in production with a Postgres database as a Tracking Server and SFTP for the transfer of artifacts over the network. It took me about 2 weeks to get all the components right but this post would help you setup of MLflow in a production environment in about 10 minutes.

    MLflow是用于機器學習生命周期管理的開源平臺。 最近,我在生產中設置了MLflow,并使用Postgres數據庫作為Tracking Server和SFTP來通過網絡傳輸工件。 我花了大約2周的時間才能正確安裝所有組件,但是這篇文章將幫助您在大約10分鐘的生產環境中設置MLflow。

    要求 (Requirements)

    • Anaconda

      水蟒

    跟蹤服務器設置 (Tracking Server Setup)

    Tracking Server stores the metadata that you see in the MLflow UI. First, let’s create a new Conda environment:

    跟蹤服務器存儲您在MLflow UI中看到的元數據。 首先,讓我們創建一個新的Conda環境:

    conda create -n mlflow_env
    conda activate mlflow_env

    Install the MLflow and PySFTP libraries:

    安裝MLflow和PySFTP庫:

    conda install python
    pip install mlflow
    pip install pysftp

    Our Tracking Server uses a Postgres database as a backend for storing the metadata. So let’s install PostgreSQL:

    我們的Tracking Server使用Postgres數據庫作為后端來存儲元數據。 因此,讓我們安裝PostgreSQL:

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

    Next, we will create the admin user and a database for the Tracking Server

    接下來,我們將為跟蹤服務器創建管理員用戶和數據庫

    sudo -u postgres psql

    In the psql console:

    在psql控制臺中:

    CREATE DATABASE mlflow_db;
    CREATE USER mlflow_user WITH ENCRYPTED PASSWORD 'mlflow';
    GRANT ALL PRIVILEGES ON DATABASE mlflow_db TO mlflow_user;

    As we’ll need to interact with Postgres from Python, it is needed to install the psycopg2 library. However, to ensure a successful installation we need to install the GCC Linux package before:

    由于我們需要與Python中的Postgres進行交互,因此需要安裝psycopg2庫。 但是,為了確保安裝成功,我們需要在安裝GCC Linux軟件包之前:

    sudo apt install gcc
    pip install psycopg2-binary

    If you would like to connect to the PostgreSQL Server remotely or would like to give its access to the users. You can

    如果您想遠程連接到PostgreSQL服務器或希望將其訪問權限授予用戶。 您可以

    cd /var/lib/pgsql/data

    Then add the following line at the end of the postgresql.conf file.

    然后在postgresql.conf文件的末尾添加以下行。

    listen_addresses = '*'

    You can then specify a remote IP from which you want to allow connection to the PostgreSQL Server, by adding the following line at the end of the pg_hba.conf file

    然后,您可以通過在pg_hba.conf文件末尾添加以下行來指定要允許從其連接到PostgreSQL服務器的遠程IP。

    host all all 10.10.10.187/32 trust

    where 10.10.10.187/32 is the remote IP. To allow connection from any IP, use 0.0.0.0/0 instead. Then restart the PostgreSQL Server to apply the changes.

    其中10.10.10.187/32是遠程IP。 要允許來自任何IP的連接,請改用0.0.0.0/0 。 然后重新啟動PostgreSQL服務器以應用更改。

    service postgresql restart

    The next step is creating a directory for our Tracking Server to log the Machine Learning models and other artifacts. Remember that the Postgres database is only used for storing metadata regarding those models. This directory is called artifact URI.

    下一步是為Tracking Server創建一個目錄,以記錄機器學習模型和其他工件。 請記住,Postgres數據庫僅用于存儲有關那些模型的元數據。 此目錄稱為工件URI。

    mkdir ~/mlflow/mlruns

    Create a logging directory.

    創建一個日志目錄。

    mkdir ~/mlflow/mllogs

    You can run the Tracking Server with the following command. But as soon as you do Ctrl-C or exit the terminal the server stops.

    您可以使用以下命令運行Tracking Server。 但是,一旦您執行Ctrl-C或退出終端,服務器就會停止。

    mlflow server --backend-store-uri postgresql://mlflow_user:mlflow@localhost/mlflow_db --default-artifact-root sftp://mlflow_user@<hostname_of_server>:~/mlflow/mlruns -h 0.0.0.0 -p 8000

    If you want the Tracking server to be up and running after restarts and be resilient to failures, it is very useful to run it as a systemd service.

    如果您希望跟蹤服務器在重新啟動后能夠啟動并運行,并且能夠對故障進行恢復,那么將其作為systemd服務運行非常有用。

    You need to go into the /etc/systemd/system directory and create a new file called mlflow-tracking.service with the following content:

    您需要進入/ etc / systemd / system目錄,并創建一個名為mlflow-tracking.service的新文件,其內容如下:

    [Unit]
    Description=MLflow Tracking Server
    After=network.target[Service]
    Restart=on-failure
    RestartSec=30
    StandardOutput=file:/path_to_your_logging_folder/stdout.log
    StandardError=file:/path_to_your_logging_folder/stderr.log
    User=root
    ExecStart=/bin/bash -c 'PATH=/path_to_your_conda_installation/envs/mlflow_env/bin/:$PATH exec mlflow server --backend-store-uri postgresql://mlflow_user:mlflow@localhost/mlflow_db --default-artifact-root sftp://mlflow_user@<hostname_of_server>:~/mlflow/mlruns -h 0.0.0.0 -p 8000'[Install]
    WantedBy=multi-user.target

    Activate and enable the above service with the following commands:

    使用以下命令激活并啟用上述服務:

    sudo systemctl daemon-reload
    sudo systemctl enable mlflow-tracking
    sudo systemctl start mlflow-tracking

    Check that everything worked as expected with the following command:

    使用以下命令檢查一切是否按預期進行:

    sudo systemctl status mlflow-tracking

    You should see an output similar to this:

    您應該看到類似于以下的輸出:

    Systemd unit running系統單元運行

    Create user for the server named mlflow_user and make mlflow directory as the working directory for this user. Then create an ssh-key pair in the .ssh directory for the mlflow_user (/mlflow/.ssh in our case). Put the public key in the authorized_keys file and share the private key with the users.

    為名為mlflow_user的服務器創建用戶,并將mlflow目錄作為該用戶的工作目錄。 然后創建.ssh目錄中的SSH密鑰對的mlflow_user(/mlflow/.ssh在我們的例子)。 將公鑰放入authorized_keys文件中,并與用戶共享私鑰。

    Additionally, for the MLflow UI to be able to read the artifacts, copy the private key to /root/.ssh/ as well.

    另外,為了使MLflow UI能夠讀取工件,請將私鑰也復制到/root/.ssh/

    Next, we need to create the Host Key for the server manually using this command:

    接下來,我們需要使用以下命令為服務器手動創建主機密鑰:

    cd /root/.ssh
    ssh-keyscan -H <hostname_of_server> >> known_hosts

    You can now restart the machine and the MLflow Tracking Server will be up and running after this restart.

    您現在可以重新啟動計算機,并且重新啟動后MLflow Tracking Server將啟動并運行。

    在客戶端計算機上 (On the client machines)

    In order to start tracking everything under the production Tracking Server, it is necessary to set the following environment variable in your .bashrc.

    為了開始跟蹤生產跟蹤服務器下的所有內容,必須在.bashrc中設置以下環境變量。

    export MLFLOW_TRACKING_URI='http://<hostname_of_server>:8000'

    Do not forget to source your .bashrc file!

    不要忘記提供您的.bashrc文件!

    . ~/.bashrc

    Make sure you install pip packages for mlflow and pysftp in your environment (pysftp is required to facilitate the transfer of artifacts to the production server).

    確保在您的環境中安裝了用于mlflowpysftp的 pip軟件包(需要pysftp才能將工件傳輸到生產服務器)。

    pip install mlflow
    pip install pysftp

    To be able to authenticate the pysftp transfers, put the private key generated on the Production Server in the .ssh directory of your local machine . Then do

    為了能夠驗證pysftp傳輸,請將生產服務器上生成的私鑰放在本地計算機的.ssh目錄中。 然后做

    ssh <hostname_of_server>

    When prompted to save <hostname_of_server> as a known host, answer yes.

    當提示您將<hostname_of_server>保存為已知主機時,請回答yes

    You can access MLflow UI at http://<hostname_of_server>:8000

    您可以通過以下 網址訪問MLflow UI : http:// <hostname_of_server> :8000

    The Mlflow UIMlflow用戶界面

    Run a sample machine learning model from the internet to check whether MLflow can track the runs.

    從Internet運行示例機器學習模型以檢查MLflow是否可以跟蹤運行。

    mlflow run git@github.com:databricks/mlflow-example.git -P alpha=0.5

    In the next post, I’ll speak about basic MLflow logging functions

    在下一篇文章中 ,我將介紹基本的MLflow日志記錄功能

    翻譯自: https://towardsdatascience.com/setup-mlflow-in-production-d72aecde7fef

    mlflow

    總結

    以上是生活随笔為你收集整理的mlflow_在生产中设置MLflow的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。