torchx.components¶
此模块包含一组内置的TorchX组件。目录结构按组件类别进行组织。组件只是模板化的应用程序规范。可以将它们视为不同类型的作业定义的工厂方法。该模块中返回specs.AppDef的函数是我们所指的组件。
您可以在 torchx.components 模块中浏览组件库
或在我们的 文档页面 上。
组件可以通过torchx cli或torchx sdk直接使用。
# using via sdk
from torchx.runner import get_runner
get_runner().run_component("distributed.ddp", app_args=[], scheduler="local_cwd", ...)
# using via torchx-cli
>> torchx run --scheduler local_cwd distributed.ddp --param1 --param2
组件开发
- The addition of a new component is pretty straightforward and consists
以下是翻译后的中文简体文本: 以下步骤:
确定组件位置
创建组件作为函数
单元测试
确定组件位置。每个组件属于一个或另一个类别,并应相应地定位。例如,分布式组件的定义应位于distributed.py文件中。
- Create component as function. Each component represents a function that accepts
任意参数和返回值
specs.AppDef。
这个函数应该具有以下特性:
函数的所有参数都必须进行注释
- Current supported types:
基本类型:整数、浮点数、字符串
可选的原生类型:Optional[int],Optional[float],Optional[str]
字典:字典[原始键,原始值]
列表:List[原始值]
可选列表,可选字典
- The function should have well defined description in
https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html 格式
单元测试。编写使用torchx.specs.file_linter来验证组件结构的单元测试,类似于torchx.components.tests.distributed_test.py。
注意
上方图表仅作说明之用。并非所有框目前都已开箱即用。