Fate 的模型預測有 離線預測
和 線上預測
兩種方式,兩者的效果是一樣的,主要是使用方式、適用場景、高可用、效能等方面有很大差別;本文分享使用 Fate 基於 縱向邏輯迴歸
演演算法訓練出來的模型進行離線預測實踐。
- 基於上文 《隱私計算FATE-模型訓練》 中訓練出來的模型進行預測任務
- 關於 Fate 的基礎概覽和安裝部署可參考文章 《隱私計算FATE-關鍵概念與單機部署指南》
執行以下命令,進入 Fate 的容器中:
docker exec -it $(docker ps -aqf "name=standalone_fate") bash
首先我們需要獲取模型對應的 model_id
和 model_version
資訊,可以通過 job_id 執行以下命令獲取:
flow job config -j 202205070226373055640 -r guest -p 9999 --output-path /data/projects/fate/examples/my_test/
job_id 可以在 FATE Board 中檢視。
執行成功後會返回對應的模型資訊,以及在指定目錄下生成一個資料夾 job_202205070226373055640_config
{
"data": {
"job_id": "202205070226373055640",
"model_info": {
"model_id": "arbiter-10000#guest-9999#host-10000#model",
"model_version": "202205070226373055640"
},
"train_runtime_conf": {}
},
"retcode": 0,
"retmsg": "download successfully, please check /data/projects/fate/examples/my_test/job_202205070226373055640_config directory",
"directory": "/data/projects/fate/examples/my_test/job_202205070226373055640_config"
}
job_202205070226373055640_config
裡面包含4個檔案:
執行以下命令:
flow model deploy --model-id arbiter-10000#guest-9999#host-10000#model --model-version 202205070226373055640
分別通過 --model-id 與 --model-version 指定上面步驟查詢到的 model_id 和 model_version
部署成功後返回:
{
"data": {
"arbiter": {
"10000": 0
},
"detail": {
"arbiter": {
"10000": {
"retcode": 0,
"retmsg": "deploy model of role arbiter 10000 success"
}
},
"guest": {
"9999": {
"retcode": 0,
"retmsg": "deploy model of role guest 9999 success"
}
},
"host": {
"10000": {
"retcode": 0,
"retmsg": "deploy model of role host 10000 success"
}
}
},
"guest": {
"9999": 0
},
"host": {
"10000": 0
},
"model_id": "arbiter-10000#guest-9999#host-10000#model",
"model_version": "202205070730131040240"
},
"retcode": 0,
"retmsg": "success"
}
部署成功後返回一個新的 model_version
執行以下命令:
cp /data/projects/fate/examples/dsl/v2/hetero_logistic_regression/hetero_lr_normal_predict_conf.json /data/projects/fate/examples/my_test/
直接把 Fate 自帶的縱向邏輯迴歸演演算法預測設定樣例,複製到我們的
my_test
目錄下。
預測的組態檔主要設定三部分:
唯一需要修改的就是中間的 模型資訊 部分;需要注意的是這裡輸入的版本號是 模型部署 後返回的版本號,並且需要增加 job_type 為 predict 指定任務型別為預測任務。
執行以下命令:
flow job submit -c hetero_lr_normal_predict_conf.json
與模型訓練一樣也是使用 submit 命令,通過 -c 指定組態檔。
執行成功後返回:
{
"data": {
"board_url": "http://127.0.0.1:8080/index.html#/dashboard?job_id=202205070731385067720&role=guest&party_id=9999",
"code": 0,
"dsl_path": "/data/projects/fate/fateflow/jobs/202205070731385067720/job_dsl.json",
"job_id": "202205070731385067720",
"logs_directory": "/data/projects/fate/fateflow/logs/202205070731385067720",
"message": "success",
"model_info": {
"model_id": "arbiter-10000#guest-9999#host-10000#model",
"model_version": "202205070730131040240"
},
"pipeline_dsl_path": "/data/projects/fate/fateflow/jobs/202205070731385067720/pipeline_dsl.json",
"runtime_conf_on_party_path": "/data/projects/fate/fateflow/jobs/202205070731385067720/guest/9999/job_runtime_on_party_conf.json",
"runtime_conf_path": "/data/projects/fate/fateflow/jobs/202205070731385067720/job_runtime_conf.json",
"train_runtime_conf_path": "/data/projects/fate/fateflow/jobs/202205070731385067720/train_runtime_conf.json"
},
"jobId": "202205070731385067720",
"retcode": 0,
"retmsg": "success"
}
可以通過返回的 board_url
或者 job_id
去 FATE Board
裡檢視結果,但是圖形化介面裡最多隻能檢視 100 條記錄;
我們可以通過 output-data
命令,匯出指定元件的所有資料輸出:
flow tracking output-data -j 202205070731385067720 -r guest -p 9999 -cpn hetero_lr_0 -o /data/projects/fate/examples/my_test/predict
執行成功後返回:
{
"retcode": 0,
"directory": "/data/projects/fate/examples/my_test/predict/job_202205070731385067720_hetero_lr_0_guest_9999_output_data",
"retmsg": "Download successfully, please check /data/projects/fate/examples/my_test/predict/job_202205070731385067720_hetero_lr_0_guest_9999_output_data directory"
}
在目錄 /data/projects/fate/examples/my_test/predict/job_202205070731385067720_hetero_lr_0_guest_9999_output_data
中可以看到兩個檔案:
掃碼關注有驚喜!