Shortcuts

工具

这包含了TorchX实用组件,这些组件是开箱即用的。这些组件只是执行众所周知的二进制文件(例如cp),并且旨在用作教程材料或工作流程中有意义阶段之间的粘合操作。

torchx.components.utils.echo(msg: str = 'hello world', image: str = 'ghcr.io/pytorch/torchx:0.7.0', num_replicas: int = 1) AppDef[source]

将消息回显到标准输出(调用echo)

Parameters:
  • msg – 要回显的消息

  • image – 要使用的图像

  • num_replicas – 要运行的副本数量

torchx.components.utils.touch(file: str, image: str = 'ghcr.io/pytorch/torchx:0.7.0') AppDef[source]

触摸一个文件(调用touch)

Parameters:
  • file – 要创建的文件

  • image – 要使用的图像

torchx.components.utils.sh(*args: str, image: str = 'ghcr.io/pytorch/torchx:0.7.0', 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 – bash 参数

  • image – 要使用的图像

  • num_replicas – 要运行的副本数量

  • cpu – 每个副本的CPU数量

  • gpu – 每个副本的GPU数量

  • memMB – 每个副本的CPU内存,单位为MB

  • h – 一个已注册的命名资源(如果指定,则优先于 cpu、gpu、memMB)

  • env – 要传递给运行的环境变量(例如 ENV1=v1,ENV2=v2,ENV3=v3)

  • max_retries – 允许的调度程序重试次数

  • mounts – 挂载到工作环境/容器中的挂载点(例如 type=,src=/host,dst=/job[,readonly])。 有关更多信息,请参阅调度程序文档。

torchx.components.utils.copy(src: str, dst: str, image: str = 'ghcr.io/pytorch/torchx:0.7.0') AppDef[source]

copy 将文件从 src 复制到 dst。src 和 dst 可以是任何有效的 fsspec URL。

这不支持递归复制或目录。

Parameters:
  • src – 源 fsspec 文件位置

  • dst – 目标 fsspec 文件位置

  • image – 包含复制应用程序的图像

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.7.0', 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 如果指定了设置资源需求,则优先考虑。 参见 registering named resources

Parameters:
  • args – 传递给程序的参数,位于 sys.argv[1:] 中(使用 –c 时忽略)

  • m – 将库模块作为脚本运行

  • c – 作为字符串传递的程序(如果调度程序对参数有长度限制,可能会出错)

  • script – 要运行的 .py 脚本

  • image – 要运行的图像

  • name – 作业的名称

  • cpu – 每个副本的CPU数量

  • gpu – 每个副本的GPU数量

  • memMB – 每个副本的CPU内存,单位为MB

  • h – 一个已注册的命名资源(如果指定,则优先于 cpu、gpu、memMB)

  • num_replicas – 运行的副本数量(每个副本在自己的容器中运行)

Returns:

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.7.0') 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 – 如果不运行hpo则忽略

  • tracker_base – 跟踪器基础输出目录的URI(例如 s3://foo/bar)

  • image – 包含展位应用程序的图像

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:
  • args – 传递给程序的参数,位于 sys.argv[1:] 中(使用 –c 时忽略)

  • name – 作业的名称

  • num_replicas – 运行的副本数量(每个副本在自己的容器中运行)

  • cpu – 每个副本的CPU数量

  • gpu – 每个副本的GPU数量

  • memMB – 每个副本的CPU内存,单位为MB

  • h – 一个已注册的命名资源(如果指定,则优先于cpu、gpu、memMB)

Returns: