目录

配置

TorchX 定义了插件点,供您配置 TorchX 以最佳支持您的基础设施设置。大部分配置是通过 Python 的 entry points<https://packaging.python.org/specifications/entry-points/> 完成的。

下面描述的入口点可以在你的项目的setup.py 文件中指定为

from setuptools import setup

setup(
   name="project foobar",
   entry_points={
       "$ep_group_name" : [
           "$ep_name = $module:$function"
       ],
   }
)

注册自定义调度器

你可以通过实现 .. py::class torchx.schedulers.Scheduler 接口来实现自定义调度器。一旦你实现了这个接口,就可以通过以下入口点注册这个自定义调度器。

[torchx.schedulers]
$sched_name = my.custom.scheduler:create_scheduler

函数 create_scheduler 应该具有以下函数签名:

from torchx.schedulers import Scheduler

def create_scheduler(session_name: str, **kwargs: Any) -> Scheduler:
    return MyScheduler(session_name, **kwargs)

注册命名资源

命名资源是一组预定义的资源规格,并被赋予一个字符串名称。这在你的集群拥有一组固定的实例类型时特别有用。例如,如果你在 AWS 上的深度学习训练 Kubernetes 集群仅由 p3.16xlarge(64 个虚拟 CPU、8 张 GPU、488GB)组成,那么你可能希望为容器枚举以下 T 恤尺码的资源规格:

{
   "gpu_x_1" : "Resource(cpu=8,  gpu=1, memMB=61*GB),
   "gpu_x_2" : "Resource(cpu=16, gpu=2, memMB=122*GB),
   "gpu_x_4" : "Resource(cpu=32, gpu=4, memMB=244*GB),
   "gpu_x_8" : "Resource(cpu=64, gpu=8, memMB=488*GB),
}

并且参考通过字符串名称引用的资源。

Torchx 支持通过字符串表示自定义资源定义和引用。

[torchx.schedulers]
gpu_x_2 = my_module.resources:gpu_x_2

之后的命名资源可以以以下方式使用:

# my_module.component
from torchx.specs import AppDef, Role
from torchx.components.base import torch_dist_role

app = AppDef(name="test_app", roles=[torch_dist_role(.., resource="gpu_x_2", ...)])

注册自定义组件

可以使用torchx CLI编写并注册一组自定义组件作为CLI的内置组件。这使得可以根据团队或组织的需求定制一组最相关的组件,并将其作为CLI builtin 支持。这样,当用户运行

$ torchx builtins

可以注册自定义组件的端点如下:

[torchx.components]
custom_component = my_module.components:my_component

可以按照以下方式执行自定义组件:

$ torchx run --scheduler local --scheduler_args image_fetcher=...,root_dir=/tmp custom_component -- --name "test app"

文档

访问 PyTorch 的全面开发人员文档

查看文档

教程

获取面向初学者和高级开发人员的深入教程

查看教程

资源

查找开发资源并解答您的问题

查看资源