运行基于组件的ml管道的引擎
ml-comp的Python项目详细描述
自述文件
mlcomp
模块设计用于处理和执行复杂的管道,这些管道由一个或多个链接在一起的组件组成,这样前一个组件的输出将成为下一个组件的输入。每个管道都有特定的用途,例如训练模型或生成推论。
单个管道可能包含来自不同语言(如python、r和java)的组件。
快速启动
步骤
创建管道。打开任何文本编辑器并复制以下管道说明:
{ "name": "Simple MCenter runner test", "engineType": "Generic", "pipe": [ { "name": "Source String", "id": 1, "type": "string-source", "parents": [], "arguments": { "value": "Hello World: testing string source and sink" } }, { "name": "Sink String", "id": 2, "type": "string-sink", "parents": [{"parent": 1, "output": 0}], "arguments": { "expected-value": "Hello World: testing string source and sink" } } ] }
克隆
mlpiper
回购https://github.com/mlpiper/mlpiper/成分
string-source
和string-sink
可以在回购路径https://github.com/mlpiper/mlpiper/tree/master/reflex-algos/components/Python一旦安装了
ml-comp
python包,就可以使用mlpiper
命令行工具来执行上面的管道和其中描述的组件。使用以下命令运行上面的示例:mlpiper run -f ~/<pipeline description file> -r <path to mlpiper repo>/reflex-algos/components/Python/ -d <deployment dir>
使用--force选项覆盖部署目录。
如何构造组件
步骤
创建一个目录,其名称对应于组件的名称(例如,源字符串)
在此目录中创建一个
component.json
文件(json格式),并确保填写以下所有字段:{ "engineType": "Generic", "language": "Python", "userStandalone": false, "name": "<Component name (e.g., string_source)>", "label": "<A lable that is displayed in the UI>", "version": "<Component's version (e.g., 1.0.0)>", "group": "<One of the valid groups (e.g., "Connectors")>, "program": "<The Python component main script (e.g., string_source.py)>", "componentClass": "<The component class name (e.g., StringSource) "useMLStats": <true|false - (whether the components uses MLStats)>, "inputInfo": [ { "description": "<Description>", "label": "<Lable name>", "defaultComponent": "", "type": "<A type used to verify matching connected legs>, "group": "<data|model|prediction|statistics|other>" }, {...} ], "outputInfo": [ <Same as inputInfo above> ], "arguments": [ { "key": "<Unique argument key name>", "type": "int|long|float|str|bool", "label": "<A label that is displayed in the UI>", "description": "<Description>", "optional": <true|false> } ] }
创建包含组件类名的主组件脚本。 此类应继承自'component'基类,该基类取自
parallelm.components.component
。类必须实现materialize
函数,使用这个原型:def _materialize(self, parent_data_objs, user_data)
。 下面是一个完整的自包含示例:from parallelm.components import ConnectableComponent from parallelm.mlops import mlops class StringSource(ConnectableComponent): def __init__(self, engine): super(self.__class__, self).__init__(engine) def _materialize(self, parent_data_objs, user_data): self._logger.info("Inside string source component") str_value = self._params.get('value', "default-string-value") mlops.set_stat("Specific stat title", 1.0) mlops.set_stat("Specific stat title", 2.0) return [str_value]
注意:
- 组件可以使用
self._logger
对象打印日志。 - 组件可以通过
self._params
字典访问管道参数。 _materialize
函数应该返回一个对象列表,否则不返回任何对象。 此返回值将用作下一个组件的输入 在管道链中。
- 组件可以使用
将组件的主程序(.py)及其json放在目录中 描述文件和任何其他需要的文件。
如何构建管道
步骤
打开任何文本编辑器并复制以下管道说明:
{ "name": "Simple MCenter runner test", "engineType": "Generic", "pipe": [ { "name": "Source String", "id": 1, "type": "string-source", "parents": [], "arguments": { "value": "Hello World: testing string source and sink" } }, { "name": "Sink String", "id": 2, "type": "string-sink", "parents": [{"parent": 1, "output": 0}], "arguments": { "expected-value": "Hello World: testing string source and sink" } } ] }
注意:
- 假设您已经构造了两个组件,它们的名称
分别是:
string-source
和string-sink
string-source
组件的输出(从_materialize
函数)应该成为string-sink
的输入。 组件(对_materialize
函数的输入)
- 假设您已经构造了两个组件,它们的名称
分别是:
用任何所需的名称保存它
如何测试
一旦安装了ml-comp
python包,就可以使用mlpiper
命令行工具
并可用于执行上述管道及其描述的组件。
有三个主要命令可以使用如下:
deploy-将管道和提供的组件部署到给定的 目录。一旦部署,就可以直接从 给定的目录。
run-部署并执行管道。
run deployment-执行已部署的管道。
示例:
准备部署。生成的目录将被复制到Docker容器中并运行 那里:
mlpiper deploy -f p1.json -r ~/dev/components -d /tmp/pp
部署并运行。对开发和调试有用:
mlpiper run -f p1.json -r ~/dev/components -d /tmp/pp
使用--force选项覆盖部署目录
运行部署。通常是非交互式的,由另一个脚本调用:
mlpiper run-deployment --deployment-dir /tmp/pp