应用示例¶
这里包含了一些示例应用程序,展示了如何使用TorchX来运行各种类型的应用程序(例如单节点、分布式等)。 这些应用程序可以单独启动,也可以作为管道的一部分启动。需要注意的是,TorchX的任务是启动这些应用程序。你会发现这些应用程序的实现中没有导入任何TorchX的内容。
参见管道示例,了解如何在管道中使用这些组件。
预备知识¶
在运行示例之前,安装运行示例所需的TorchX及其依赖项:
`
$ pip install torchx
$ git clone https://github.com/pytorch/torchx.git
$ cd torchx/examples/apps
$ TORCHX_VERSION=$(torchx --version | sed 's/torchx-//')
$ git checkout v$TORCHX_VERSION
$ pip install -r dev-requirements.txt
`
计算世界大小示例¶
这是一个极简的“Hello World”风格的应用程序,使用PyTorch分布式计算世界大小。它是一个最小示例,因为它初始化了torch.distributed进程组,并执行了一次集体操作(all_reduce),这足以验证基础设施和调度器的设置。
此示例与dist.ddp兼容。要从CLI运行:
$ cd $torchx-git-repo-root/torchx/examples/apps
$ torchx run dist.ddp --script compute_world_size/main.py -j 1x2
数据预处理示例¶
这是一个简单的TorchX应用程序,它通过HTTP下载一些数据,使用torchvision对图像进行归一化处理,然后通过fsspec重新上传。
这个示例包含两个 Python 文件:一个是实际执行预处理的应用程序,另一个是组件定义文件,可以与 TorchX 一起使用以启动该应用程序。
闪电 + Classy Vision 训练器示例¶
这个例子包括使用 PyTorch Lightning 和 ClassyVision 进行模型训练和解释性应用程序。这些应用程序共享逻辑,因此被拆分成多个文件。
The trainer and interpret apps do not have any TorchX-isms and are simply ClassyVision (PyTorch) and Captum applications. TorchX helps you run these applications on various schedulers and localhost. The trainer app is a distributed data parallel style application and is launched with the dist.ddp built-in. The interpret app is a single node application and is launched as a regular python process with the utils.python built-in.
有关如何使用TorchX运行这些应用程序的说明,请参阅各自主模块中的文档:train.py 和 interpret.py。