联合模型注册中心¶
1. 说明¶
由 FATE 训练的模型会自动保存到本地并记录在 FATE-Flow 的数据库中,每个组件运行完成后保存的模型称为 Pipeline 模型,在组件运行时定时保存的模型称为 Checkpoint 模型。Checkpoint 模型也可以用于组件运行意外中断后,重试时的“断点续传”。
Checkpoint 模型的支持自 1.7.0 加入,默认是不保存的,如需启用,则要向 DSL 中加入 callback ModelCheckpoint
。
本地磁盘存储¶
-
Pipeline 模型存储于
model_local_cache/<party_model_id>/<model_version>/variables/data/<component_name>/<model_alias>
。 -
Checkpoint 模型存储于
model_local_cache/<party_model_id>/<model_version>/checkpoint/<component_name>/<step_index>#<step_name>
。
目录结构¶
tree model_local_cache/guest#9999#arbiter-10000#guest-9999#host-10000#model/202112181502241234200
model_local_cache/guest#9999#arbiter-10000#guest-9999#host-10000#model/202112181502241234200
├── checkpoint
│ ├── data_transform_0
│ ├── evaluation_0
│ ├── hetero_linr_0
│ │ ├── 0#step_name
│ │ │ ├── HeteroLinearRegressionMeta.json
│ │ │ ├── HeteroLinearRegressionMeta.pb
│ │ │ ├── HeteroLinearRegressionParam.json
│ │ │ ├── HeteroLinearRegressionParam.pb
│ │ │ └── database.yaml
│ │ ├── 1#step_name
│ │ │ ├── HeteroLinearRegressionMeta.json
│ │ │ ├── HeteroLinearRegressionMeta.pb
│ │ │ ├── HeteroLinearRegressionParam.json
│ │ │ ├── HeteroLinearRegressionParam.pb
│ │ │ └── database.yaml
│ │ ├── 2#step_name
│ │ │ ├── HeteroLinearRegressionMeta.json
│ │ │ ├── HeteroLinearRegressionMeta.pb
│ │ │ ├── HeteroLinearRegressionParam.json
│ │ │ ├── HeteroLinearRegressionParam.pb
│ │ │ └── database.yaml
│ │ ├── 3#step_name
│ │ │ ├── HeteroLinearRegressionMeta.json
│ │ │ ├── HeteroLinearRegressionMeta.pb
│ │ │ ├── HeteroLinearRegressionParam.json
│ │ │ ├── HeteroLinearRegressionParam.pb
│ │ │ └── database.yaml
│ │ └── 4#step_name
│ │ ├── HeteroLinearRegressionMeta.json
│ │ ├── HeteroLinearRegressionMeta.pb
│ │ ├── HeteroLinearRegressionParam.json
│ │ ├── HeteroLinearRegressionParam.pb
│ │ └── database.yaml
│ ├── hetero_linr_1
│ ├── intersection_0
│ └── reader_0
├── define
│ ├── define_meta.yaml
│ ├── proto
│ │ └── pipeline.proto
│ └── proto_generated_python
│ ├── __pycache__
│ │ └── pipeline_pb2.cpython-36.pyc
│ └── pipeline_pb2.py
├── run_parameters
│ ├── data_transform_0
│ │ └── run_parameters.json
│ ├── hetero_linr_0
│ │ └── run_parameters.json
│ ├── hetero_linr_1
│ │ └── run_parameters.json
│ └── pipeline
│ └── run_parameters.json
└── variables
├── data
│ ├── data_transform_0
│ │ └── model
│ │ ├── DataTransformMeta
│ │ ├── DataTransformMeta.json
│ │ ├── DataTransformParam
│ │ └── DataTransformParam.json
│ ├── hetero_linr_0
│ │ └── model
│ │ ├── HeteroLinearRegressionMeta
│ │ ├── HeteroLinearRegressionMeta.json
│ │ ├── HeteroLinearRegressionParam
│ │ └── HeteroLinearRegressionParam.json
│ ├── hetero_linr_1
│ │ └── model
│ │ ├── HeteroLinearRegressionMeta
│ │ ├── HeteroLinearRegressionMeta.json
│ │ ├── HeteroLinearRegressionParam
│ │ └── HeteroLinearRegressionParam.json
│ └── pipeline
│ └── pipeline
│ ├── Pipeline
│ └── Pipeline.json
└── index
32 directories, 47 files
checkpoint
此目录存储组件运行过程中,每轮迭代产生的模型,不是所有组件都支持 checkpoint。
以 checkpoint/hetero_linr_0/2#step_name
为例:
hetero_linr_0
是 component_name
;2
是 step_index
,即迭代次数;step_name
目前只做占位符,没有使用。
HeteroLinearRegressionMeta.json
, HeteroLinearRegressionMeta.pb
, HeteroLinearRegressionParam.json
, HeteroLinearRegressionParam.pb
都是训练产生的数据,可以理解为模型文件。database.yaml
主要记录上述文件的 hash 以作校验,还存储有 step_index
, step_name
, create_time
。
define
该目录储存作业的基本信息,在作业初始化时创建。pipeline
不是一个组件,而是代表整个作业。
define/proto/pipeline.proto
和 define/proto/pipeline_pb2.py
目前没有使用。
define/define_meta.yaml
记录组件列表,包括 component_name
, componet_module_name
, model_alias
。
run_parameters
此目录存储组件的配置信息,也称为 DSL。
run_parameters/pipeline/run_parameters.json
为一个空的 object {}
。
variables
此目录存储组件运行结束后产生的模型,与最后一轮迭代产生的模型一致。
以 variables/data/hetero_linr_0/model
为例:
hetero_linr_0
是 component_name
;model
是 model_alias
。
HeteroLinearRegressionMeta
, HeteroLinearRegressionMeta.json
, HeteroLinearRegressionParam
HeteroLinearRegressionParam.json
与 checkpoint
目录下的文件格式完全一致,除了 .pb
文件去掉了扩展名。
variables/data/pipeline/
存储作业的详细信息。
variables/index/
目前没有使用。
远端存储引擎¶
本地磁盘并不可靠,因此模型有丢失的风险,FATE-Flow 支持导出模型到指定存储引擎、从指定存储引擎导入以及自动发布模型时推送模型到引擎存储。
存储引擎支持腾讯云对象存储、MySQL 和 Redis, 具体请参考存储引擎配置
2. Model¶
load¶
向 Fate-Serving 加载 deploy
生成的模型。
flow model load -c examples/model/publish_load_model.json
flow model load -j <job_id>
选项
参数 | 短格式 | 长格式 | 可选参数 | 说明 |
---|---|---|---|---|
conf_path | -c |
--conf-path |
是 | 配置文件 |
job_id | -j |
--job-id |
是 | 任务 ID |
样例
{
"data": {
"detail": {
"guest": {
"9999": {
"retcode": 0,
"retmsg": "success"
}
},
"host": {
"10000": {
"retcode": 0,
"retmsg": "success"
}
}
},
"guest": {
"9999": 0
},
"host": {
"10000": 0
}
},
"jobId": "202111091122168817080",
"retcode": 0,
"retmsg": "success"
}
bind¶
向 Fate-Serving 绑定 deploy
生成的模型。
flow model bind -c examples/model/bind_model_service.json
flow model bind -c examples/model/bind_model_service.json -j <job_id>
选项
参数 | 短格式 | 长格式 | 可选参数 | 说明 |
---|---|---|---|---|
conf_path | -c |
--conf-path |
否 | 配置文件 |
job_id | -j |
--job-id |
是 | 任务 ID |
样例
{
"retcode": 0,
"retmsg": "service id is 123"
}
import¶
从本地或存储引擎中导入模型。
flow model import -c examples/model/import_model.json
flow model import -c examples/model/restore_model.json --from-database
选项
参数 | 短格式 | 长格式 | 可选参数 | 说明 |
---|---|---|---|---|
conf_path | -c |
--conf-path |
否 | 配置文件 |
from_database | --from-database |
是 | 从存储引擎中导入模型 |
样例
{
"data": {
"job_id": "202208261102212849780",
"model_id": "arbiter-10000#guest-9999#host-10000#model",
"model_version": "foobar",
"party_id": "9999",
"role": "guest"
},
"retcode": 0,
"retmsg": "success"
}
export¶
导出模型到本地或存储引擎中。
flow model export -c examples/model/export_model.json
flow model export -c examples/model/store_model.json --to-database
选项
参数 | 短格式 | 长格式 | 可选参数 | 说明 |
---|---|---|---|---|
conf_path | -c |
--conf-path |
否 | 配置文件 |
to_database | --to-database |
是 | 将模型导出到存储引擎中 |
样例
{
"data": {
"board_url": "http://127.0.0.1:8080/index.html#/dashboard?job_id=202111091124582110490&role=local&party_id=0",
"code": 0,
"dsl_path": "/root/Codes/FATE-Flow/jobs/202111091124582110490/job_dsl.json",
"job_id": "202111091124582110490",
"logs_directory": "/root/Codes/FATE-Flow/logs/202111091124582110490",
"message": "success",
"model_info": {
"model_id": "local-0#model",
"model_version": "202111091124582110490"
},
"pipeline_dsl_path": "/root/Codes/FATE-Flow/jobs/202111091124582110490/pipeline_dsl.json",
"runtime_conf_on_party_path": "/root/Codes/FATE-Flow/jobs/202111091124582110490/local/0/job_runtime_on_party_conf.json",
"runtime_conf_path": "/root/Codes/FATE-Flow/jobs/202111091124582110490/job_runtime_conf.json",
"train_runtime_conf_path": "/root/Codes/FATE-Flow/jobs/202111091124582110490/train_runtime_conf.json"
},
"jobId": "202111091124582110490",
"retcode": 0,
"retmsg": "success"
}
migrate¶
迁移模型。
flow model migrate -c examples/model/migrate_model.json
选项
参数 | 短格式 | 长格式 | 可选参数 | 说明 |
---|---|---|---|---|
conf_path | -c |
--conf-path |
否 | 配置文件 |
样例
{
"data": {
"arbiter": {
"10000": 0
},
"detail": {
"arbiter": {
"10000": {
"retcode": 0,
"retmsg": "Migrating model successfully. The configuration of model has been modified automatically. New model id is: arbiter-100#guest-99#host-100#model, model version is: 202111091127392613050. Model files can be found at '/root/Codes/FATE-Flow/temp/fate_flow/arbiter#100#arbiter-100#guest-99#host-100#model_202111091127392613050.zip'."
}
},
"guest": {
"9999": {
"retcode": 0,
"retmsg": "Migrating model successfully. The configuration of model has been modified automatically. New model id is: arbiter-100#guest-99#host-100#model, model version is: 202111091127392613050. Model files can be found at '/root/Codes/FATE-Flow/temp/fate_flow/guest#99#arbiter-100#guest-99#host-100#model_202111091127392613050.zip'."
}
},
"host": {
"10000": {
"retcode": 0,
"retmsg": "Migrating model successfully. The configuration of model has been modified automatically. New model id is: arbiter-100#guest-99#host-100#model, model version is: 202111091127392613050. Model files can be found at '/root/Codes/FATE-Flow/temp/fate_flow/host#100#arbiter-100#guest-99#host-100#model_202111091127392613050.zip'."
}
}
},
"guest": {
"9999": 0
},
"host": {
"10000": 0
}
},
"jobId": "202111091127392613050",
"retcode": 0,
"retmsg": "success"
}
tag-list¶
获取模型的标签列表。
flow model tag-list -j <job_id>
选项
参数 | 短格式 | 长格式 | 可选参数 | 说明 |
---|---|---|---|---|
job_id | -j |
--job_id |
否 | 任务 ID |
tag-model¶
从模型中添加或删除标签。
flow model tag-model -j <job_id> -t <tag_name>
flow model tag-model -j <job_id> -t <tag_name> --remove
选项
参数 | 短格式 | 长格式 | 可选参数 | 说明 |
---|---|---|---|---|
job_id | -j |
--job_id |
否 | 任务 ID |
tag_name | -t |
--tag-name |
否 | 标签名 |
remove | --remove |
是 | 移除指定的标签 |
deploy¶
配置预测 DSL。
flow model deploy --model-id <model_id> --model-version <model_version>
选项
参数 | 短格式 | 长格式 | 可选参数 | 说明 |
---|---|---|---|---|
model_id | --model-id |
否 | 模型 ID | |
model_version | --model-version |
否 | 模型版本 | |
cpn_list | --cpn-list |
是 | 组件列表 | |
cpn_path | --cpn-path |
是 | 从文件中读入组件列表 | |
dsl_path | --dsl-path |
是 | 预测 DSL 文件 | |
cpn_step_index | --cpn-step-index |
是 | 用指定的 Checkpoint 模型替换 Pipeline 模型 使用 : 分隔 component name 与 step index例如 --cpn-step-index cpn_a:123 |
|
cpn_step_name | --cpn-step-name |
是 | 用指定的 Checkpoint 模型替换 Pipeline 模型 使用 : 分隔 component name 与 step name例如 --cpn-step-name cpn_b:foobar |
样例
{
"retcode": 0,
"retmsg": "success",
"data": {
"model_id": "arbiter-9999#guest-10000#host-9999#model",
"model_version": "202111032227378766180",
"arbiter": {
"party_id": 9999
},
"guest": {
"party_id": 10000
},
"host": {
"party_id": 9999
},
"detail": {
"arbiter": {
"party_id": {
"retcode": 0,
"retmsg": "deploy model of role arbiter 9999 success"
}
},
"guest": {
"party_id": {
"retcode": 0,
"retmsg": "deploy model of role guest 10000 success"
}
},
"host": {
"party_id": {
"retcode": 0,
"retmsg": "deploy model of role host 9999 success"
}
}
}
}
}
get-predict-dsl¶
获取预测 DSL。
flow model get-predict-dsl --model-id <model_id> --model-version <model_version> -o ./examples/
选项
参数 | 短格式 | 长格式 | 可选参数 | 说明 |
---|---|---|---|---|
model_id | --model-id |
否 | 模型 ID | |
model_version | --model-version |
否 | 模型版本 | |
output_path | -o |
--output-path |
否 | 输出路径 |
get-predict-conf¶
获取模型预测模板。
flow model get-predict-conf --model-id <model_id> --model-version <model_version> -o ./examples/
选项
参数 | 短格式 | 长格式 | 可选参数 | 说明 |
---|---|---|---|---|
model_id | --model-id |
否 | 模型 ID | |
model_version | --model-version |
否 | 模型版本 | |
output_path | -o |
--output-path |
否 | 输出路径 |
get-model-info¶
获取模型信息。
flow model get-model-info --model-id <model_id> --model-version <model_version>
flow model get-model-info --model-id <model_id> --model-version <model_version> --detail
选项
参数 | 短格式 | 长格式 | 可选参数 | 说明 |
---|---|---|---|---|
model_id | --model-id |
否 | 模型 ID | |
model_version | --model-version |
否 | 模型版本 | |
role | -r |
--role |
是 | Party 角色 |
party_id | -p |
--party-id |
是 | Party ID |
detail | --detail |
是 | 展示详细信息 |
homo-convert¶
基于横向训练的模型,生成其他 ML 框架的模型文件。
flow model homo-convert -c examples/model/homo_convert_model.json
选项
参数 | 短格式 | 长格式 | 可选参数 | 说明 |
---|---|---|---|---|
conf_path | -c |
--conf-path |
否 | 配置文件 |
homo-deploy¶
将横向训练后使用 homo-convert
生成的模型部署到在线推理系统中,当前支持创建基于 KFServing 的推理服务。
flow model homo-deploy -c examples/model/homo_deploy_model.json
选项
参数 | 短格式 | 长格式 | 可选参数 | 说明 |
---|---|---|---|---|
conf_path | -c |
--conf-path |
否 | 配置文件 |
3. Checkpoint¶
list¶
获取 Checkpoint 模型列表。
flow checkpoint list --model-id <model_id> --model-version <model_version> --role <role> --party-id <party_id> --component-name <component_name>
选项
参数 | 短格式 | 长格式 | 可选参数 | 说明 |
---|---|---|---|---|
model_id | --model-id |
否 | 模型 ID | |
model_version | --model-version |
否 | 模型版本 | |
role | -r |
--role |
否 | Party 角色 |
party_id | -p |
--party-id |
否 | Party ID |
component_name | -cpn |
--component-name |
否 | 组件名 |
样例
{
"retcode": 0,
"retmsg": "success",
"data": [
{
"create_time": "2021-11-07T02:34:54.683015",
"step_index": 0,
"step_name": "step_name",
"models": {
"HeteroLogisticRegressionMeta": {
"buffer_name": "LRModelMeta",
"sha1": "6871508f6e6228341b18031b3623f99a53a87147"
},
"HeteroLogisticRegressionParam": {
"buffer_name": "LRModelParam",
"sha1": "e3cb636fc93675684bff27117943f5bfa87f3029"
}
}
}
]
}
get¶
获取 Checkpoint 模型信息。
flow checkpoint get --model-id <model_id> --model-version <model_version> --role <role> --party-id <party_id> --component-name <component_name> --step-index <step_index>
选项
参数 | 短格式 | 长格式 | 可选参数 | 说明 |
---|---|---|---|---|
model_id | --model-id |
否 | 模型 ID | |
model_version | --model-version |
否 | 模型版本 | |
role | -r |
--role |
否 | Party 角色 |
party_id | -p |
--party-id |
否 | Party ID |
component_name | -cpn |
--component-name |
否 | 组件名 |
step_index | --step-index |
是 | Step index,不可与 step_name 同时使用 | |
step_name | --step-name |
是 | Step name,不可与 step_index 同时使用 |
样例
{
"retcode": 0,
"retmsg": "success",
"data": {
"create_time": "2021-11-07T02:34:54.683015",
"step_index": 0,
"step_name": "step_name",
"models": {
"HeteroLogisticRegressionMeta": "CgJMMhEtQxzr4jYaPxkAAAAAAADwPyIHcm1zcHJvcDD///////////8BOTMzMzMzM8M/QApKBGRpZmZYAQ==",
"HeteroLogisticRegressionParam": "Ig0KAng3EW1qASu+uuO/Ig0KAng0EcNi7a65ReG/Ig0KAng4EbJbl4gvVea/Ig0KAng2EcZwlVZTkOu/Ig0KAngwEVpG8dCbGvG/Ig0KAng5ESJNTx5MLve/Ig0KAngzEZ88H9P8qfO/Ig0KAng1EVfWP8JJv/K/Ig0KAngxEVS0xVXoTem/Ig0KAngyEaApgW32Q/K/KSiiE8AukPs/MgJ4MDICeDEyAngyMgJ4MzICeDQyAng1MgJ4NjICeDcyAng4MgJ4OUj///////////8B"
}
}
}
4. 存储引擎配置¶
enable_model_store
¶
开启后,在调用 /model/load
时:如果模型文件在本地磁盘存在、但不在存储引擎中,则自动把模型文件上传至存储引擎;如果模型文件在存储引擎存在、但不在本地磁盘中,则自动把模型文件下载到本地磁盘。
此配置不影响 /model/store
和 /model/restore
。
model_store_address
¶
此配置定义使用的存储引擎。
腾讯云对象存储¶
storage: tencent_cos
# 请从腾讯云控制台获取下列配置
Region:
SecretId:
SecretKey:
Bucket:
MySQL¶
storage: mysql
database: fate_model
user: fate
password: fate
host: 127.0.0.1
port: 3306
# 可选的数据库连接参数
max_connections: 10
stale_timeout: 10
Redis¶
storage: redis
host: 127.0.0.1
port: 6379
db: 0
password:
# key 的超时时间,单位秒。默认 None,没有超时时间。
ex: