Slurm¶
This contains the TorchX Slurm scheduler which can be used to run TorchX components on a Slurm cluster.
- class torchx.schedulers.slurm_scheduler.SlurmScheduler(session_name: str)[source]¶
Bases:
DirWorkspaceMixin,Scheduler[SlurmOpts]SlurmScheduler is a TorchX scheduling interface to slurm. TorchX expects that slurm CLI tools are locally installed and job accounting is enabled.
Each app def is scheduled using a heterogenous job via sbatch. Each replica of each role has a unique shell script generated with it’s resource allocations and args and then sbatch is used to launch all of them together.
Logs are available in combined form via
torchx log, the programmatic API as well as in the job launch directory asslurm-<jobid>-<role>-<replica_id>.out. If TorchX is running in a different directory than where the job was created the logs won’t be able to be found.Some of the config options passed to it are added as SBATCH arguments to each replica. See https://slurm.schedmd.com/sbatch.html#SECTION_OPTIONS for info on the arguments.
Slurm jobs inherit the currently active
condaorvirtualenvand run in the current working directory. This matches the behavior of thelocal_cwdscheduler.For more info see:
$ torchx run --scheduler slurm utils.echo --msg hello slurm://torchx_user/1234 $ torchx status slurm://torchx_user/1234 $ less slurm-1234.out ...
Config Options
usage: [account=ACCOUNT],[partition=PARTITION],[time=TIME],[comment=COMMENT],[constraint=CONSTRAINT],[mail-user=MAIL-USER],[mail-type=MAIL-TYPE],[job_dir=JOB_DIR],[qos=QOS] optional arguments: account=ACCOUNT (str, None) The account to use for the slurm job. partition=PARTITION (str, None) The partition to run the job in. time=TIME (str, None) The maximum time the job is allowed to run for. Formats: "minutes", "minutes:seconds", "hours:minutes:seconds", "days-hours", "days-hours:minutes" or "days-hours:minutes:seconds" comment=COMMENT (str, None) Comment to set on the slurm job. constraint=CONSTRAINT (str, None) Constraint to use for the slurm job. mail-user=MAIL-USER (str, None) User to mail on job end. mail-type=MAIL-TYPE (str, None) What events to mail users on. job_dir=JOB_DIR (str, None) The directory to place the job code and outputs. The directory must not exist and will be created. To enable log iteration, jobs will be tracked in ``.torchxslurmjobdirs``. qos=QOS (str, None) Quality of Service (QoS) to assign to the job.Compatibility
Feature
Scheduler Support
Fetch Logs
✔️
Distributed Jobs
✔️
Cancel Job
✔️
Describe Job
Partial support. SlurmScheduler will return job and replica status but does not provide the complete original AppSpec.
Workspaces / Patching
If ``job_dir`` is specified the DirWorkspaceMixin will create a new isolated directory with a snapshot of the workspace.
Mounts
❌
Elasticity
❌
If a partition has less than 1GB of RealMemory configured we disable memory requests to workaround https://github.com/aws/aws-parallelcluster/issues/2198.
- describe(app_id: str) torchx.schedulers.api.DescribeAppResponse | None[source]¶
Returns app description, or
Noneif it no longer exists.
- list(cfg: Optional[Mapping[str, str | int | float | bool | list[str] | dict[str, str] | None]] = None) List[ListAppResponse][source]¶
Lists jobs on this scheduler.
- log_iter(app_id: str, role_name: str, k: int = 0, regex: str | None = None, since: datetime.datetime | None = None, until: datetime.datetime | None = None, should_tail: bool = False, streams: torchx.schedulers.api.Stream | None = None) Iterable[str][source]¶
Returns an iterator over log lines for the
k-th replica ofrole_name.Important
Not all schedulers support log iteration, tailing, or time-based cursors. Check the specific scheduler docs.
Lines include trailing whitespace (
\n). Whenshould_tail=True, the iterator blocks until the app reaches a terminal state.- Parameters:
k – replica (node) index
regex – optional filter pattern
since – start cursor (scheduler-dependent)
until – end cursor (scheduler-dependent)
should_tail – if
True, follow output liketail -fstreams –
stdout,stderr, orcombined
- Raises:
NotImplementedError – if the scheduler does not support log iteration
- schedule(dryrun_info: AppDryRunInfo[SlurmBatchRequest]) str[source]¶
Submits a previously dry-run request. Returns the app_id.
- torchx.schedulers.slurm_scheduler.create_scheduler(session_name: str, **kwargs: Any) SlurmScheduler[source]¶
- class torchx.schedulers.slurm_scheduler.SlurmBatchRequest(cmd: list[str], replicas: dict[str, torchx.schedulers.slurm_scheduler.SlurmReplicaRequest], job_dir: str | None, max_retries: int)[source]¶
Holds parameters used to launch a slurm job via sbatch.
- class torchx.schedulers.slurm_scheduler.SlurmReplicaRequest(name: str, entrypoint: str, args: list[str], srun_opts: dict[str, str], sbatch_opts: dict[str, str | None], env: dict[str, str])[source]¶
Holds parameters for a single replica running on slurm and can be materialized down to a bash script.