实用工具¶
这包含TorchX实用组件,这些组件是开箱即用的ready-to-use。这些组件简单地执行众所周知的二进制文件(例如cp),并旨在作为教程材料或工作流中具有意义的阶段之间的粘合操作。
- torchx.components.utils.echo(msg: str = 'hello world', image: str = 'ghcr.io/pytorch/torchx:0.5.0dev0', num_replicas: int = 1) AppDef[source]¶
将消息回显到标准输出(调用 echo)
- Parameters:
msg – 要回显的信息
图像 – 使用的图像
num_replicas – 运行的副本数量
- torchx.components.utils.touch(file: str, image: str = 'ghcr.io/pytorch/torchx:0.5.0dev0') AppDef[source]¶
触碰一个文件(调用 touch)
- Parameters:
文件 – 创建的文件
图像 – 要使用的图像
- torchx.components.utils.sh(*args: str, image: str = 'ghcr.io/pytorch/torchx:0.5.0dev0', num_replicas: int = 1, cpu: int = 1, gpu: int = 0, memMB: int = 1024, h: Optional[str] = None, env: Optional[Dict[str, str]] = None, max_retries: int = 0, mounts: Optional[List[str]] = None) AppDef[source]¶
通过 sh 运行提供的命令。目前 sh 不支持环境变量替换。
- Parameters:
args – 命令行参数
图像 – 使用的图像
num_replicas – 运行的副本数量
CPU – 每个副本的CPU数量
GPU – 每个副本的 GPU 数量
memMB – 每个副本中的CPU内存以MB为单位
h – 一个已注册的命名资源(如果指定,则优先于cpu、gpu、memMB)
env – 需要传递给运行的环境变量(例如 ENV1=v1,ENV2=v2,ENV3=v3)
max_retries – 允许的调度器重试次数
挂载点 – 挂载到工作环境/容器中的挂载点(例如 type=<bind/volume>,src=/host,dst=/job[,readonly])。 请参阅调度程序文档以获取更多信息。
- torchx.components.utils.copy(src: str, dst: str, image: str = 'ghcr.io/pytorch/torchx:0.5.0dev0') AppDef[source]¶
复制文件从源路径到目标路径。源路径和目标路径可以是任何有效的 fsspec URL。
这不支持递归复制或目录。
- Parameters:
src – 源 fsspec 文件位置
dst – 目标fsspec文件位置
图像 – 包含复制应用的图像
- torchx.components.utils.python(*args: str, m: Optional[str] = None, c: Optional[str] = None, script: Optional[str] = None, image: str = 'ghcr.io/pytorch/torchx:0.5.0dev0', name: str = 'torchx_utils_python', cpu: int = 1, gpu: int = 0, memMB: int = 1024, h: Optional[str] = None, num_replicas: int = 1) AppDef[source]¶
在指定的图像和主机上使用指定的模块、命令或脚本运行
python。使用--分隔组件参数和程序参数(例如:torchx run utils.python --m foo.main -- --args to --main)- Note: (cpu, gpu, memMB) parameters are mutually exclusive with
h(named resource) where h如果指定了资源需求设置,则优先考虑。 请参阅 注册命名资源。
- Parameters:
参数 – 传递给程序的参数,位于 sys.argv[1:] 中(在使用–c时被忽略)
m – 以脚本方式运行库模块
c – 作为字符串传递的程序(如果调度程序对参数长度有限制,则可能会出错)
脚本 – .py 脚本以运行
图像 – 要运行的图像
名称 – 工作的名称
CPU – 每个副本的CPU数量
GPU – 每个副本的 GPU 数量
memMB – 每个副本中的CPU内存以MB为单位
h – 一个已注册的命名资源(如果指定,则优先于cpu、gpu、memMB)
num_replicas – 运行的副本数量(每个副本都在自己的容器中)
- Returns:
- Note: (cpu, gpu, memMB) parameters are mutually exclusive with
- torchx.components.utils.booth(x1: float, x2: float, trial_idx: int = 0, tracker_base: str = '/tmp/torchx-util-booth', image: str = 'ghcr.io/pytorch/torchx:0.5.0dev0') AppDef[source]¶
评估 booth 函数,
f(x1, x2) = (x1 + 2*x2 - 7)^2 + (2*x1 + x2 - 5)^2。 输出结果可通过FsspecResultTracker(outdir)[trial_idx]访问- Parameters:
x1 – x1
x2 – x2
trial_idx – 如果不运行超参数优化,请忽略
tracker_base – 跟踪器基础输出目录的URI(例如 s3://foo/bar)
图像 – 包含展位应用程序的图像
- torchx.components.utils.binary(*args: str, entrypoint: str, name: str = 'torchx_utils_binary', num_replicas: int = 1, cpu: int = 1, gpu: int = 0, memMB: int = 1024, h: Optional[str] = None) AppDef[source]¶
测试组件
- Parameters:
参数 – 传递给程序的参数,位于 sys.argv[1:] 中(在使用–c时被忽略)
名称 – 工作的名称
num_replicas – 运行的副本数量(每个副本都在自己的容器中)
CPU – 每个副本的CPU数量
GPU – 每个副本的 GPU 数量
memMB – 每个副本中的CPU内存以MB为单位
h – 一个已注册的命名资源(如果指定,则优先于cpu、gpu、memMB)
- Returns: