GCP 批量¶
这包含了TorchX GCP批处理调度器,可用于直接在GCP批处理上运行TorchX组件。
此调度器处于原型阶段,可能会在没有通知的情况下进行更改。
先决条件¶
你需要配置一个GCP项目,通过启用和设置来使用Batch。 参见 https://cloud.google.com/batch/docs/get-started#prerequisites
- class torchx.schedulers.gcp_batch_scheduler.GCPBatchScheduler(session_name: str, client: Optional[Any] = None)[source]¶
基础类:
Scheduler[GCPBatchOpts]GCPBatchScheduler 是 TorchX 与 GCP Batch 的调度接口。
$ pip install torchx[gcp_batch] $ torchx run --scheduler gcp_batch utils.echo --msg hello # This launches a job with app handle like gcp_batch://torchx/project:location:app_id1234 and prints it $ torchx status gcp_batch://torchx/project:location:app_id1234 ...
认证是通过使用gcloud凭证处理从环境中加载的。
配置选项
usage: [project=PROJECT],[location=LOCATION] optional arguments: project=PROJECT (str, None) Name of the GCP project. Defaults to the configured GCP project in the environment location=LOCATION (str, us-central1) Name of the location to schedule the job in. Defaults to us-central1
兼容性
功能
调度器支持
获取日志
✔️
分布式作业
✔️
取消任务
✔️
描述工作
✔️
工作区 / 补丁
❌
挂载
❌
弹性
❌
- 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的日志行。 当所有符合条件的日志行都被读取后,迭代器结束。如果调度程序支持基于时间的光标获取自定义时间范围内的日志行,则
since和until字段会被尊重,否则它们会被忽略。不指定since和until等同于获取所有可用的日志行。如果until为空,则迭代器的行为类似于tail -f,跟随日志输出直到作业达到终止状态。日志的确切定义取决于调度程序。一些调度程序可能将stderr或stdout视为日志,而其他调度程序可能从日志文件中读取日志。
行为和假设:
如果在一个不存在的应用程序上调用,会产生未定义行为 调用者应在调用此方法之前使用
exists(app_id)检查应用程序是否存在。不是有状态的,使用相同参数调用此方法两次会返回一个新的迭代器。之前的迭代进度会丢失。
并不总是支持日志尾部查看。并非所有调度器都支持实时日志迭代(例如,在应用程序运行时查看日志尾部)。请参考特定调度器的文档以了解迭代器的行为。
- 3.1 If the scheduler supports log-tailing, it should be controlled
通过
should_tail参数。
不保证日志的保留。当调用此方法时,底层调度程序可能已经清除了此应用程序的日志记录。如果是这样,此方法会引发任意异常。
如果
should_tail为 True,该方法仅在可访问的日志行完全耗尽且应用程序达到最终状态时引发StopIteration异常。例如,如果应用程序卡住并且不产生任何日志行,则迭代器会阻塞,直到应用程序最终被终止(无论是通过超时还是手动),此时它会引发StopIteration。如果
should_tail为 False,当没有更多日志时,该方法会引发StopIteration。不需要所有调度程序都支持。
一些调度器可能通过支持
__getitem__来支持行光标 (例如iter[50]跳转到第50条日志行)。- Whitespace is preserved, each new line should include
\n. To 支持交互式进度条,返回的行不需要包含
\n,但应在打印时不换行以正确处理\r回车符。
- Whitespace is preserved, each new line should include
- Parameters:
streams – 要选择的IO输出流。 选项之一:combined, stdout, stderr。 如果调度程序不支持所选的流,它将抛出一个ValueError。
- Returns:
一个
Iterator,用于遍历指定角色副本的日志行- Raises:
NotImplementedError – 如果调度程序不支持日志迭代
- schedule(dryrun_info: AppDryRunInfo[GCPBatchJob]) str[source]¶
与
submit相同,只是它接受一个AppDryRunInfo。 鼓励实现者实现此方法,而不是直接实现submit,因为submit可以通过以下方式轻松实现:dryrun_info = self.submit_dryrun(app, cfg) return schedule(dryrun_info)
- class torchx.schedulers.gcp_batch_scheduler.GCPBatchJob(name: str, project: str, location: str, job_def: 'batch_v1.Job')[source]¶