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
中可以看到两个文件:
扫码关注有惊喜!