Multi-Machine Training
- class lightning_sdk.MMT(name, teamspace=None, org=None, user=None, *, _fetch_job=True, _num_machines=2)
Bases:
JobCompatibility interface for multi-machine jobs.
Multi-machine functionality is implemented by
lightning_sdk.job.Job.MMTis deprecated; useJobinstead.Fetch already existing jobs.
- Parameters:
name (
str) – the name of the job.teamspace (
Union[str,Teamspace,None]) – the teamspace the job is part of.org (
Union[str,Organization,None]) – the name of the organization owning theteamspacein case it is owned by an org. Deprecated — pass the owner as part ofteamspaceinstead, e.g.teamspace="owner/teamspace".user (
Union[str,User,None]) – the name of the user owning theteamspacein case it is owned directly by a user instead of an org. Deprecated — pass the owner as part ofteamspaceinstead, e.g.teamspace="owner/teamspace".name (str)
org (str | Organization | None)
_fetch_job (bool)
_num_machines (int)
- Raises:
ValueError – If the teamspace cannot be resolved from the provided arguments, or if the job is not found when
_fetch_job=True.PermissionError – If the user does not have access to jobs in the given teamspace.
- classmethod run(name, num_machines, machine, cloud=None, command=None, studio=None, image=None, teamspace=None, org=None, user=None, env=None, interruptible=False, image_credentials=None, cloud_account_auth=False, entrypoint=None, path_mappings=None, max_runtime=None, max_run_attempts=None, reuse_snapshot=True, placement_group_id=None, tags=None, keep_minutes=None)
Run async workloads using a docker image or a compute environment from your studio.
- Parameters:
name (
str) – The name of the job. Needs to be unique within the teamspace.machine (
Union[Machine,str]) – The machine type to run the job on.num_machines (
int) – The number of machines to run on. Defaults to one.command (
Optional[str]) – The command to run inside your job. Required if using a studio. Optional if using an image. If not provided for images, will run the container entrypoint and default command. Studio jobs run the command as a bash script withset -e, so the first command that fails ends the job with its exit code. That includes cleanup commands andEXITtraps that run afterexit 0.studio (
Union[Studio,str,None]) – The studio env to run the job with. Mutually exclusive with image. If bothstudioandimageare left unset and this code is running inside a Studio (detected via theLIGHTNING_CLOUD_SPACE_IDenv var), defaults to that Studio, provided its teamspace matches the resolvedteamspace.image (
Optional[str]) – The docker image to run the job with. Mutually exclusive with studio.teamspace (
Union[str,Teamspace,None]) – The teamspace the job should be associated with. Defaults to the current teamspace. Accepts a bare name or anowner/teamspaceslug.org (
Union[str,Organization,None]) – The organization owning the teamspace, if any. Defaults to the current organization. Deprecated — pass the owner as part ofteamspaceinstead, e.g.teamspace="owner/teamspace".user (
Union[str,User,None]) – The user owning the teamspace, if any. Defaults to the current user. Deprecated — pass the owner as part ofteamspaceinstead, e.g.teamspace="owner/teamspace".cloud (
Union[CloudProvider,str,None]) – Cloud provider or cloud account to run the job on.env (
Optional[Dict[str,str]]) – Environment variables to set inside the job.interruptible (
bool) – Whether the job should run on interruptible instances. Cheaper but can be preempted.image_credentials (
Optional[str]) – Credentials secret name used to pull a private image.cloud_account_auth (
bool) – Whether to authenticate with the cloud account to pull the image. Required if the registry is part of a cloud provider, such as ECR.entrypoint (
Optional[str]) – The entrypoint of your docker container. Defaults tosh -c. Set to an empty string to use the image’s pre-defined entrypoint with a command. Only applicable when submitting docker jobs.path_mappings (
Optional[Dict[str,str]]) – Maps container paths to data-connection paths in the form{"<CONTAINER_PATH>": "<CONNECTION_NAME>:<PATH>"}or{"<CONTAINER_PATH>": "<CONNECTION_NAME>"}for the root of a connection. Only applicable when submitting docker jobs.max_runtime (
Optional[int]) – How long, in seconds, to reserve a DWS (Dynamic Workload Scheduler) machine, such as some top-end GCP GPUs or Lightning baremetal. On GCP the job is stopped when the reservation ends. On Lightning baremetal the job keeps running afterwards and the machine becomes interruptible. For a hard time limit, wrap your command, e.g.timeout 7200 python train.py. Has no effect on interruptible (spot) machines.Nonemeans no reservation is requested.max_run_attempts (
Optional[int]) – Max number of run attempts for this job.Noneor0means unset (backend default).1means a single attempt (no retries).N > 1allows up toNattempts. For multi-machine jobs this is set at the multi-machine job level (not the per-machineJobSpec). When greater than1for a multi-machine job, theRECREATE_ALL_NODESfault tolerance strategy is set automatically on the multi-machine job body.reuse_snapshot (
bool) – Whether to reuse a Studio snapshot when multiple jobs for the same Studio are submitted. Turning this off may result in longer startup times. Defaults to True.scratch_disks – Optional mapping of scratch-disk mount paths to their sizes in GiB.
placement_group_id (
Optional[str]) – Optional placement group identifier for colocating the job.tags (
Optional[List[str]]) – Teamspace tag names to apply to the job. Tags that don’t exist in the teamspace yet are created, which requires permission to create tags. Names are normalised by the platform (lowercased, whitespace collapsed), sojob.tagsmay read back slightly differently from what was passed in.keep_minutes (
Optional[int]) – Minutes to keep the machine after the job stops.Noneor0releases the machine immediately.name (str)
num_machines (int)
cloud (CloudProvider | str | None)
command (str | None)
image (str | None)
org (str | Organization | None)
interruptible (bool)
image_credentials (str | None)
cloud_account_auth (bool)
entrypoint (str | None)
max_runtime (int | None)
max_run_attempts (int | None)
reuse_snapshot (bool)
placement_group_id (str | None)
keep_minutes (int | None)
- Returns:
The newly submitted Job instance.
- Return type:
- Raises:
ValueError – If required arguments are missing or mutually exclusive arguments are both provided.
RuntimeError – If image and studio are both provided.
- class lightning_sdk.mmt.MMTMachine(*args, **kwargs)
Bases:
ProtocolA single machine in a multi-machine job.
Was this page helpful?
Thanks for the feedback.