AWS Batch¶
這包含 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)[來源]¶
基礎:
DockerWorkspaceMixin
,Scheduler
[AWSBatchOpts
]AWSBatchScheduler 是 AWS Batch 的 TorchX 排程介面。
$ 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=<host path>,dst=<container path>[,readonly]
efs 磁碟區:
type=volume,src=<efs id>,dst=<container path>[,readonly]
裝置:
type=device,src=/dev/infiniband/uverbs0,[dst=<container path>][,perm=rwm]
如需詳細資訊,請參閱
torchx.specs.parse_mounts()
。對於其他檔案系統,例如 FSx,您可以將它們掛載到主機上,並將它們繫結掛載到您的作業中: https://repost.aws/knowledge-center/batch-fsx-lustre-file-system-mount
對於 Elastic Fabric Adapter (EFA),您需要使用裝置掛載來將它們掛載到容器中: https://docs.aws.amazon.com/batch/latest/userguide/efa.html
相容性
功能
排程器支援
擷取日誌
✔️
分散式作業
✔️
取消作業
✔️
描述作業
部分支援。AWSBatchScheduler 將傳回作業和複本狀態,但不提供完整的原始 AppSpec。
工作區 / 修補程式
✔️
掛載
✔️
彈性
❌
- describe(app_id: str) Optional[DescribeAppResponse] [來源]¶
描述指定的應用程式。
- 傳回值:
AppDef 描述或
None
(如果應用程式不存在)。
- list() List[ListAppResponse] [來源]¶
對於在排程器上啟動的應用程式,此 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] [原始碼]¶
傳回一個迭代器,指向
``role
的第 `k`` 個複本 的日誌行。當讀取完所有符合條件的日誌行時,迭代器就會結束。如果排程器支援基於時間的游標來擷取自訂時間範圍內的日誌行,則會採用
since
和until
欄位,否則會忽略它們。未指定since
和until
等同於取得所有可用的日誌行。如果until
為空,則迭代器的行為類似於tail -f
,會持續追蹤日誌輸出,直到作業達到終止狀態。日誌的確切定義會因排程器而異。某些排程器可能會將 stderr 或 stdout 視為日誌,而其他排程器可能會從日誌檔案中讀取日誌。
行為和假設
如果對不存在的應用程式呼叫此方法,則會產生未定義的行為。呼叫者應在呼叫此方法之前,使用
exists(app_id)
檢查應用程式是否存在。不是狀態性的,使用相同的參數呼叫此方法兩次會傳回一個新的迭代器。先前的迭代進度會遺失。
不支援日誌追蹤。並非所有排程器都支援即時日誌迭代(例如,在應用程式執行時追蹤日誌)。迭代器的行為請參閱特定排程器的文件。
- 3.1 如果排程器支援日誌追蹤,則應由
should_tail
參數控制。
不保證日誌保留。當呼叫此方法時,基礎排程器可能已清除此應用程式的日誌記錄。如果是這樣,此方法會引發任意例外狀況。
如果
should_tail
為 True,則只有當可存取的日誌行已完全耗盡且應用程式已達到最終狀態時,此方法才會引發StopIteration
例外狀況。例如,如果應用程式卡住且未產生任何日誌行,則迭代器會封鎖,直到應用程式最終被終止(透過逾時或手動),此時會引發StopIteration
。如果
should_tail
為 False,則當沒有更多日誌時,此方法會引發StopIteration
。並非所有排程器都需要支援。
某些排程器可以透過支援
__getitem__
來支援行游標(例如,iter[50]
會搜尋到第 50 個日誌行)。- 會保留空格,每個新行都應包含
\n
。若要 支援互動式進度條,傳回的行不需要包含
\n
,但接著應在不換行的情況下列印,以便正確處理\r
歸位字元。
- 會保留空格,每個新行都應包含
- 參數:
streams – 要選擇的 IO 輸出串流。選項包括:combined、stdout、stderr。如果排程器不支援所選的串流,則會擲出 ValueError。
- 傳回值:
指定角色複本之日誌行的
Iterator
- 引發:
NotImplementedError – 如果排程器不支援日誌迭代
- 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]])[原始碼]¶