Shortcuts

AWS批处理

这包含了TorchX AWS Batch调度器,可用于直接在AWS Batch上运行TorchX组件。

此调度器处于原型阶段,可能会在没有通知的情况下进行更改。

先决条件

您需要创建一个配置为多节点并行作业的AWS Batch队列。

请参阅 https://docs.aws.amazon.com/batch/latest/userguide/Batch_GetStarted.html 了解如何设置作业队列和计算环境。对于多节点并行作业,需要由EC2支持。

查看 https://docs.aws.amazon.com/batch/latest/userguide/multi-node-parallel-jobs.html 以获取有关分布式作业的更多信息。

如果你想使用工作空间和容器修补,你还需要配置一个docker注册表来存储带有你更改的修补容器,例如AWS ECR。

请参阅 https://docs.aws.amazon.com/AmazonECR/latest/userguide/getting-started-cli.html#cli-create-repository 了解如何创建镜像仓库。

class torchx.schedulers.aws_batch_scheduler.AWSBatchScheduler(session_name: str, client: Optional[Any] = None, log_client: Optional[Any] = None, docker_client: Optional[DockerClient] = None)[source]

基础类: DockerWorkspaceMixin, Scheduler[AWSBatchOpts]

AWSBatchScheduler 是 TorchX 的 AWS Batch 调度接口。

$ pip install torchx[kubernetes]
$ torchx run --scheduler aws_batch --scheduler_args queue=torchx utils.echo --image alpine:latest --msg hello
aws_batch://torchx_user/1234
$ torchx status aws_batch://torchx_user/1234
...

身份验证是通过使用boto3凭据处理从环境中加载的。

配置选项

    usage:
        queue=QUEUE,[user=USER],[privileged=PRIVILEGED],[share_id=SHARE_ID],[priority=PRIORITY],[job_role_arn=JOB_ROLE_ARN],[execution_role_arn=EXECUTION_ROLE_ARN],[image_repo=IMAGE_REPO],[quiet=QUIET]

    required arguments:
        queue=QUEUE (str)
            queue to schedule job in

    optional arguments:
        user=USER (str, ec2-user)
            The username to tag the job with. `getpass.getuser()` if not specified.
        privileged=PRIVILEGED (bool, False)
            If true runs the container with elevated permissions. Equivalent to running with `docker run --privileged`.
        share_id=SHARE_ID (str, None)
            The share identifier for the job. This must be set if and only if the job queue has a scheduling policy.
        priority=PRIORITY (int, 0)
            The scheduling priority for the job within the context of share_id. Higher number (between 0 and 9999) means higher priority. This will only take effect if the job queue has a scheduling policy.
        job_role_arn=JOB_ROLE_ARN (str, None)
            The Amazon Resource Name (ARN) of the IAM role that the container can assume for AWS permissions.
        execution_role_arn=EXECUTION_ROLE_ARN (str, None)
            The Amazon Resource Name (ARN) of the IAM role that the ECS agent can assume for AWS permissions.
        image_repo=IMAGE_REPO (str, None)
            (remote jobs) the image repository to use when pushing patched images, must have push access. Ex: example.com/your/container
        quiet=QUIET (bool, False)
            whether to suppress verbose output for image building. Defaults to ``False``.

挂载

该类支持绑定挂载主机目录、efs卷和主机设备。

  • 绑定挂载:type=bind,src= path>,dst= path>[,readonly]

  • efs 卷: type=volume,src= id>,dst= path>[,readonly]

  • 设备: type=device,src=/dev/infiniband/uverbs0,[dst=<容器 路径>][,perm=rwm]

查看 torchx.specs.parse_mounts() 获取更多信息。

对于其他文件系统,如FSx,您可以将它们挂载到主机上,并将它们绑定挂载到您的作业中:https://repost.aws/knowledge-center/batch-fsx-lustre-file-system-mount

对于弹性结构适配器(EFA),您需要使用设备挂载将其挂载到容器中:https://docs.aws.amazon.com/batch/latest/userguide/efa.html

兼容性

功能

调度程序支持

获取日志

✔️

分布式作业

✔️

取消任务

✔️

描述工作

部分支持。AWSBatchScheduler 将返回作业和副本状态,但不提供完整的原始 AppSpec。

工作区 / 补丁

✔️

挂载

✔️

弹性

describe(app_id: str) Optional[DescribeAppResponse][source]

描述指定的应用程序。

Returns:

AppDef 描述或如果应用程序不存在则为 None

list() List[ListAppResponse][source]

对于在调度程序上启动的应用程序,此API返回一个ListAppResponse对象列表,每个对象都包含应用程序ID及其状态。 注意:此API处于原型阶段,可能会发生变化。

log_iter(app_id: str, role_name: str, k: int = 0, regex: Optional[str] = None, since: Optional[datetime] = None, until: Optional[datetime] = None, should_tail: bool = False, streams: Optional[Stream] = None) Iterable[str][source]

返回一个迭代器,用于遍历k``th replica of the ``role的日志行。 当所有符合条件的日志行都被读取后,迭代器结束。

如果调度程序支持基于时间的光标获取自定义时间范围内的日志行,则sinceuntil字段会被尊重,否则它们会被忽略。不指定sinceuntil等同于获取所有可用的日志行。如果until为空,则迭代器的行为类似于tail -f,跟随日志输出直到作业达到终止状态。

日志的确切定义取决于调度程序。一些调度程序可能将stderr或stdout视为日志,而其他调度程序可能从日志文件中读取日志。

行为和假设:

  1. 如果在一个不存在的应用程序上调用,会产生未定义行为 调用者应在调用此方法之前使用exists(app_id)检查应用程序是否存在。

  2. 不是有状态的,使用相同参数调用此方法两次会返回一个新的迭代器。之前的迭代进度会丢失。

  3. 并不总是支持日志尾部查看。并非所有调度器都支持实时日志迭代(例如,在应用程序运行时查看日志尾部)。请参考特定调度器的文档以了解迭代器的行为。

3.1 If the scheduler supports log-tailing, it should be controlled

通过 should_tail 参数。

  1. 不保证日志的保留。当调用此方法时,底层调度程序可能已经清除了此应用程序的日志记录。如果是这样,此方法会引发任意异常。

  2. 如果 should_tail 为 True,该方法仅在可访问的日志行完全耗尽且应用程序达到最终状态时引发 StopIteration 异常。例如,如果应用程序卡住并且不产生任何日志行,则迭代器会阻塞,直到应用程序最终被终止(无论是通过超时还是手动),此时它会引发 StopIteration

    如果 should_tail 为 False,当没有更多日志时,该方法会引发 StopIteration

  3. 不需要所有调度程序都支持。

  4. 一些调度器可能通过支持__getitem__来支持行光标 (例如iter[50]跳转到第50条日志行)。

  5. Whitespace is preserved, each new line should include \n. To

    支持交互式进度条,返回的行不需要包含\n,但应在打印时不换行以正确处理\r回车符。

Parameters:

streams – 要选择的IO输出流。 选项之一:combined, stdout, stderr。 如果调度程序不支持所选的流,它将抛出一个ValueError。

Returns:

一个Iterator,用于遍历指定角色副本的日志行

Raises:

NotImplementedError – 如果调度程序不支持日志迭代

schedule(dryrun_info: AppDryRunInfo[BatchJob]) str[source]

submit相同,只是它接受一个AppDryRunInfo。 鼓励实现者实现此方法,而不是直接实现submit,因为submit可以通过以下方式轻松实现:

dryrun_info = self.submit_dryrun(app, cfg)
return schedule(dryrun_info)
class torchx.schedulers.aws_batch_scheduler.BatchJob(name: str, queue: str, share_id: Union[str, NoneType], job_def: Dict[str, object], images_to_push: Dict[str, Tuple[str, str]])[source]

参考

torchx.schedulers.aws_batch_scheduler.create_scheduler(session_name: str, client: Optional[Any] = None, log_client: Optional[Any] = None, docker_client: Optional[DockerClient] = None, **kwargs: object) AWSBatchScheduler[source]