GCP 批处理¶
这包含 TorchX 的 GCP Batch 调度程序,可以用于在 GCP Batch 上直接运行 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 是一个连接到 GCP Batch 的 TorchX 调度接口。
$ 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:
应用程序定义描述或
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一样,跟随日志输出直到作业达到终端状态。日志的确切定义取决于调度程序的具体设置。有些调度程序可能会将标准错误或标准输出视为日志,而其他调度程序则可能从日志文件中读取日志。
行为和假设:
如果在不存在的应用程序上调用此方法,会产生未定义行为。 调用者应在调用此方法之前使用
exists(app_id)检查应用程序是否存在。不是有状态的,用相同的参数调用此方法两次 会返回一个新的迭代器。之前的迭代 进度会丢失。
不一定始终支持日志追尾功能。并非所有调度器都支持实时日志迭代(例如,在应用程序运行时追尾日志)。有关迭代器的行为,请参阅特定调度器的文档。
- 3.1 If the scheduler supports log-tailing, it should be controlled
by
should_tailparameter.
不保证日志保留。调用此方法时,底层调度程序可能已经清除了该应用程序的日志记录。如果是这样的话,此方法将引发任意异常。
如果
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:
流 – 要选择的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]¶
参考¶
- torchx.schedulers.gcp_batch_scheduler.create_scheduler(session_name: str, **kwargs: object) GCPBatchScheduler[source]¶