Fluiddocs
Run and watch

Train on several GPUs

Run one process per GPU on one machine or across a group of AWS EC2 or Google Compute Engine machines. Move the ranks together as one job.

Warnings and limits

  • --ranks N sets the total number of processes. The default is one machine. On AWS EC2 and Google Compute Engine (GCE), --nodes M distributes the ranks evenly across M GPU machines. N must be divisible by M.
  • The node count and rank count stay fixed through a move. Multi-node jobs support explicit live moves on on-demand EC2 GPU machines and the three GCE GPU group types. Each generation uses one provider and one machine type. The Spot policy can move a G2 Spot group on a preemption notice. A failed rank or a confirmed node loss before handoff ends the group. Periodic checkpoints, parking for later resume, and moves of jobs using point-to-point traffic or subgroups are single-machine features.
  • Each machine needs at least one GPU per local rank. Single-machine GPU jobs with several ranks run on AWS, Modal, Lambda Cloud or your own machine. GCE requires at least two machines for a GPU job with several ranks. A machine's GPUs must be known for a job of several ranks: when a cloud cannot say how many a machine has, the job is refused with a sentence that says so, and you can ask again. On your own machine, --on machine.NAME:gpu=MODEL needs at least N GPUs of that model, as the machine reported them.
  • On AWS the smallest machine with several GPUs has four. A job that asks for two is quoted a machine with four and pays for four.
  • Your cloud's quota is the first thing to check. On AWS it counts the whole machine's vCPUs, 48 for four GPUs, and a quota sized for one GPU runs none of them. See Which machines have several GPUs.
  • A machine that shows fewer GPUs than its type has is ended before the job starts, and Fluid tries the next offer. If a destination machine shows fewer GPUs than its local ranks need, the job fails before your script starts.
  • The ranks pause together between two exchanges of your script (an all_reduce, the backward of a DistributedDataParallel). A script that starts its own worker processes instead cannot pause: let Fluid start them with --ranks.
  • A timeout you give your process group (timeout= of init_process_group or new_group) is never used up by a pause: Fluid holds a rank it has stopped for at most a quarter of it, then lets the ranks run and tries again. With a timeout of a few seconds a pause takes more tries. Under one second the job cannot pause: Fluid refuses by name, with what to give instead (one second or more, or no timeout).
  • A single-machine job checkpoints itself while it runs. A rank that runs out of memory or is killed, or a machine that is lost, leaves that job suspended on its last checkpoint. See Checkpoints.
  • The out-of-memory rescue is for jobs of one process. See Out-of-memory rescue.
  • A rank that raises an error of its own ends the whole job at once.
  • A job paused within the first two steps after your script made its DistributedDataParallel can differ from an unmoved run in the last bits when it has more than two ranks. Paused any later, it goes on exactly as an unmoved run, on any number of ranks.
  • On one machine a script whose ranks talk in pairs (send, recv) or in a group made with new_group pauses where no message between them is under way, and its groups are made again where it lands. Fluid checks that such a job can pause and its events say when it cannot: a script whose ranks always have a message under way has no place to pause, and cannot move, suspend or checkpoint. Wait for an isend or irecv before the next step: a pause waits for a message that is under way, and a handle whose message has arrived moves with the job. Finding the place costs pause time: Fluid lets ranks run on one message at a time until none is under way, and each round stops a rank again. Measured on T4s over NCCL: 1 to 2 rounds for a master and its workers, 18 to 23 for three ranks that only send and receive, and 3.25 seconds for a try that finds no place.
  • Not carried, and refused by name with what to change: a group made by split_group or with pg_options, a DeviceMesh, DistributedDataParallel on a group of your own (keep the model on the default group), a running torch.distributed.rpc, and keys your script wrote to the rendezvous store.
  • --ranks 1 starts one process with the variables below set for a world of one, for a script written for torchrun that you run on one GPU. It is a job of one process in everything else, with the out-of-memory rescue. Without --ranks none of the variables are set.
  • When plans are on for the workspace, more than one rank needs the Team plan; a refusal with plan_feature says so.
  • On a multi-node job the ranks meet at the first node's private address. On a single machine the port normally listens only on loopback. Two scripts are the exception, and the job's log says so when it happens: one that asks for its store at an address other than 127.0.0.1 or localhost, and one on a torch too old to take Fluid's socket. Their port is open on every network interface, as under torchrun. Over NCCL this is not yet run on a GPU.

Start the ranks

Write the script as you would for torchrun: one process per GPU, with DistributedDataParallel or collectives of your own. Then let Fluid start the processes:

fluid run train.py --gpu L4 --ranks 4
fluid run train.py --gpu L4 --ranks 4 --on SPEC --project training -d

On a single GPU machine, --gpus defaults to the number of ranks. A single-machine job can also run ranks on CPUs.

Train across machines

For 32 ranks on four machines, ask for eight GPUs per machine. Preview the group on the provider you want.

fluid run train.py --nodes 4 --ranks 32 --gpus 8 --gpu A100 --providers aws --plan --json
fluid run train.py --nodes 4 --ranks 32 --gpus 8 --gpu L4 --providers gcp --regions us-central1 --no-spot --plan --json

Choose an exact spec from the quote. Launch with the same topology and requirements, adding --on SPEC --project training. The selected spec describes each of the four machines. In each offer, gpu_count and node_price_per_hour describe one machine. nodes, total_gpu_count and price_per_hour describe the whole group. A running job's where follows the same rule: fluid ps and fluid status show the group's hourly rate with its node count, and in --json where.price_per_hour is the group's rate, with nodes and node_price_per_hour for one machine. The selected region needs quota for all four machines at once. A move also needs capacity for the destination group while the source group still holds its machines.

GCE group discovery uses Standard provisioning by default. To request four L4 Spot machines in one zone, preview a zone-pinned g2-standard-96 spec ending in :spot with the same topology. Quote a G2 Spot group

On AWS, each group uses private addresses in its region's default VPC. An existing connection may need the updated AWS policy.

On GCE, select the quoted spec. Each GCE member has eight GPUs. Choose g2-standard-96 for 24 GB L4s, a2-highgpu-8g for 40 GB A100s or a2-ultragpu-8g for 80 GB A100s. To run without public IPs on the VMs, use a connection with --private-network and --rank-network NETWORK. The source and destination each need a Public NAT that serves the rank subnet's primary range in their region. The estimated compute cost covers every member. Standard quotes show boot disk, Local SSD and VM external IPv4 separately. A2 Ultra automatically attaches 3,000 GiB of billable Local SSD per VM. The Flex-start quote includes this scratch storage in its rate. Private members have a zero VM external IPv4 charge. The quote lists NAT rates and Google bills for actual gateway, address and traffic usage. The savings comparison is available for single-machine jobs. GCE rank network setup

When using MCP, set ranks: 32 and pass {"nodes": 4, "gpus": 8, "gpu": "A100", "providers": ["aws"]} as requirements. On either client you can omit the GPU count and it defaults to eight per machine. Use LOCAL_RANK to select a GPU on each machine and RANK to identify a process across the job.

To check a move, read job.runtime_groups in fluid status JOB --json. Each generation lists its group ID, whether it is authoritative, and the members. A member's runtime_id identifies its machine, while rank_start and local_ranks give its range of global ranks. When the job ends, download each member's output to verify its results.

Each rank gets the environment torchrun sets:

VariableValue
RANK, WORLD_SIZEthe process number across the job (from 0) and total number of ranks
LOCAL_RANK, LOCAL_WORLD_SIZEthe process number on this machine (from 0) and the number of processes on it
GROUP_RANKthe machine's index in the group, from 0
MASTER_ADDR, MASTER_PORTthe rendezvous address and port shared by all ranks
OMP_NUM_THREADS1, unless you set it
GLOO_SOCKET_IFNAME, NCCL_SOCKET_IFNAMEdefault to loopback for a single-machine run. Multi-node ranks communicate across the private network
CUDA_DEVICE_ORDERPCI_BUS_ID, unless you set it: GPU k is the one nvidia-smi lists as k

Lightning and Accelerate read LOCAL_RANK and do not start processes of their own when it is set. Each process sees the GPUs on its own machine and picks its device with LOCAL_RANK.

Libraries on several GPUs

What a library trains over several processes moves when Fluid starts them. Verified on CPUs, with two ranks.

Your script usesWith --ranks N
PyTorch Lightning with strategy="ddp", Lightning Fabric on several devicesMoves. Lightning finds the ranks and starts no process itself.
The Hugging Face TrainerMoves. The trainer reads the ranks' environment, as under torchrun.
A streaming dataset split by rank (split_dataset_by_node, shard)Moves. Each rank goes on at its own row.
TensorBoard, MLflow or offline Weights & Biases, written by every rankMoves. Each rank's writer or run goes on.
TensorFlow's MultiWorkerMirroredStrategy, jax.distributedDoes not pause. The workers meet over the library's own servers, which Fluid does not carry. The job runs, and its events say so.

Without --ranks, a library that starts the other processes itself (Lightning's DDP, accelerate launch, torchrun inside the job) runs and does not pause. A pause point says so, with the number of ranks to ask for.

Several devices in one process are another matter: a tf.distribute strategy, keras.distribution and a JAX mesh do not pause. See Libraries and frameworks.

Give each rank its GPU

Pick the rank's GPU the way you already do. Each of these moves with the rank, and after a move the rank is on the GPU of the same number:

  • torch.cuda.set_device(local_rank), then .cuda() and device="cuda".
  • device = torch.device("cuda", local_rank), then .to(device).
  • DistributedDataParallel(model, device_ids=[local_rank]).
  • os.environ["CUDA_VISIBLE_DEVICES"] = os.environ["LOCAL_RANK"] before importing torch, then cuda:0. A GPU you name by id (GPU-...) is carried as the number its machine has for it, since no other machine has a GPU of that id. A part of a GPU (MIG-...) has no number, so such a job cannot move. On a sandboxed machine (a Modal sandbox) Fluid starts the ranks with NCCL_CUMEM_HOST_ENABLE=0, which ranks that each see one GPU need there to reach each other over NCCL. A value you set yourself is kept.
  • with torch.cuda.device(local_rank): around the training loop.
  • init_process_group("nccl", device_id=device).
  • Mixed precision with torch.autocast and a GradScaler on the rank's device.
  • A rank that also exchanges tensors on the CPU: name a backend for each kind, init_process_group("cpu:gloo,cuda:nccl").

These are tried on CPUs, where a script has no GPU to pick, and are not yet run on a GPU. A rank that takes the GPU of its LOCAL_RANK, as a script for torchrun, the Hugging Face Trainer and Lightning's DDP strategy do, was run on four T4 GPUs over NCCL, with two and with four ranks: see On an NVIDIA GPU.

On each machine, the setup command (PORTAL_SETUP) runs once and its local ranks share a working directory. To exchange data across machines, use distributed collectives. Use the job log to read output from the ranks.

Which machines have several GPUs

ProviderGPUs on one machineWhat its quota counts
AWS EC24 or 8: T4 (4), A10G, L4 and L40S (4 or 8), A100 40 GB (8), H100 (8)the machine's vCPUs per region, for spot and for on-demand: 48 for four GPUs of a G family, 96 for a 24xlarge and for p4d, 192 for eight
Modal1 to 8 of one modelyour workspace's GPU limits
Lambda Cloudwhat Lambda lists, up to 8your account's instance limit
Your own machinewhat it hasnothing
Google Compute Engine8 GPUs per member of a multi-node group. L4 24 GB, A100 40 GB or A100 80 GBGPU quota for the selected model and applicable family CPU quota
Azure VMs, Azure Container Appsnot available yet

Read the quotes for the job before you start it:

fluid prices --gpu L4 --gpus 4 --json

An offer your quota cannot fit is listed as unavailable. It names the quota and the number to ask your cloud for, for example "g5.12xlarge needs 48 vCPUs of 'Running On-Demand G and VT instances' (L-DB2E81BA) in us-east-1. Your limit is 4. Ask AWS to raise it to 48." Fluid never asks for quota itself.

A machine with several GPUs gets a larger disk than one with a single GPU, so a checkpoint as large as everything its GPUs hold fits when the job is restored. See AWS.

How the job moves

An explicit live move pauses and restores the whole job:

  1. Fluid reads how many exchanges each rank has completed and names a count just ahead of all of them.
  2. Each rank pauses at its first pause point once it has made that many. No exchange is in flight then.
  3. Every rank saves its own state. The job has one checkpoint, with each rank's share in it.
  4. On the destination every rank restores at the same time, and the ranks form their process group again before their state is loaded.
  5. Fluid compares each rank's restored state with what that rank saved. One difference stops the move.

If the ranks cannot all pause in one place, Fluid lets them run on and tries again a little later. The job's events say so.

A move to a smaller GPU is checked against the most memory PyTorch reserved on each GPU, with what the GPU held beside it, plus 10%. Each destination machine needs enough GPUs for its local ranks. On a different GPU model the job's events say so: results after such a move can differ in the last bits.

Checkpoints

A single-machine job of several ranks checkpoints itself while it runs. The ranks pause between two exchanges, their state is written to storage, and they run on.

  • The first checkpoint comes about ten minutes after the job starts or lands on a machine.
  • After that Fluid sets the time between checkpoints from what one costs, so that they take at most 2% of the run time. It is never under ten minutes and never over two hours. --checkpoint-every MIN sets it yourself, one minute at the least.
  • What one costs is the pause and, where the bytes leave their cloud for the store, what sending them costs. Where sending one costs five cents or more and you set no interval, the first checkpoint waits until that is within the 2%, and the job's events say when it comes and why. No checkpoint is taken that the job's budget does not have left.
  • The cost never keeps a job without a checkpoint for long. The first comes within 30 minutes whatever it costs, and the next are at most two hours apart, because the time between two checkpoints is the most work one failure loses. Where that makes checkpoints cost more than the 2%, the job's events say what they come to. Both limits are settings: --policy checkpoint.first_within_min=N and --policy checkpoint.max_every_min=N, ten minutes at the least.
  • The plan of a launch says what sending a checkpoint from the chosen machine costs: a GB, for a state as large as all its GPUs' memory, how often, and an hour. The run's page and fluid status JOB say what one costs on its route and an hour while the job runs.
  • Before the first checkpoint Fluid reckons how long one will pause the ranks from the size of the job's state: about a second for every 2 GB. Where that pause would be more than the 2%, the first checkpoint also waits, and the job's events and its page say when it comes and why. After the first one the job's own measured pause is used.
  • A checkpoint needs room on the machine's disk for all of it: the size of the job's state. Where the disk has less free, no checkpoint is begun and the ranks are not paused. The job's events and its page say so, with how much is needed and how much is free. Move the job to a machine with a larger disk to have checkpoints again. The job's events say how, for the machine it runs on: disk_gb in the spec sets the disk on AWS EC2, Azure VMs and Google Cloud; an AWS Fargate task's disk grows with its memory_gb; on your own machine, free disk there; Modal, Lambda Cloud and Azure Container Apps set the disk themselves, so move to a machine whose spec names its disk. Fluid sizes the disk of a machine with several GPUs for this by itself. If you name a smaller disk_gb, or your own machine is short of free disk, the plan of the launch says so before anything starts.
  • A program whose ranks always have a message under way has no place to pause. Fluid tells the job once that it cannot be checkpointed, moved or suspended, and why. It then tries no checkpoint at the interval, since each try slows the ranks for some seconds and cannot be taken. The job's page and fluid status JOB say so. A checkpoint is taken as soon as a place is found, and Fluid tries one all the same every 6 hours. Until then no machine is started to move the job, off Spot or to a cheaper one, since the move could not pause it.
  • --no-checkpoint turns them off. A rank or machine failure then ends the job with its work lost.
  • For every job of the workspace, an Owner sets the interval, both limits and whether jobs checkpoint at all in the console: Settings, Policies, Checkpoint. A value under its least is refused there with the reason.
  • One checkpoint is kept. The next replaces it once it is complete.
  • fluid status JOB and the run's page in the console show the last checkpoint, its size, how long the ranks paused, when the next is due and the time between them.
  • Before the first checkpoint both say "no checkpoint yet" and when the first comes. Until then a rank or machine failure ends the job with its work lost.
What happensWhat Fluid does
A rank runs out of memoryThe job is suspended on its last checkpoint. Resume it on larger GPUs.
A rank is killedThe job is suspended on its last checkpoint.
A rank gives up waitingThe library stops a rank that waited too long for the others: over NCCL it ends the rank after ten minutes, over gloo it raises its timeout after thirty. The job is suspended on its last checkpoint. The event says which rank gave up waiting and what the other ranks were seen in: look at the quiet one.
The machine is lost without a noticeThe job is suspended on its last checkpoint. The event says at least how much work runs again.
The ranks hangAfter the idle time (30 minutes, idle.after_min) Fluid tries to suspend the job. If the ranks cannot pause, it is suspended on its last checkpoint. fluid suspend JOB --last-checkpoint does this at once.
Your script raises an errorThe job fails. A resume would meet the same error.
Any of these before the first checkpointThe job fails.

A checkpoint that is not taken leaves the job running with the checkpoint it had. Fluid tries again later, each time after a longer wait, so that the tries pause the job for no more than the 2% where it can, and never more than two hours after the last try. It never stops trying. After five tries in a row it says once that the checkpoints are failing, why, and what would help, and the run's page says "Failing" with the time of the next try. The first checkpoint that is kept says so too.

Some reasons do not pass by themselves. If the script holds a value that no checkpoint can capture, Fluid says so after two tries and tries again when its capture check reads differently, and every six hours all the same.

The work since the last checkpoint runs again after a resume. The event says the checkpoint's time and how much work that is. Fluid does not resume the job by itself: you choose when and where.

The console and fluid status JOB say the same things of a job suspended this way, in the same words:

  • What happened, with what is known of it: which rank, which GPU and its memory, the signal, how long the ranks hung, or that the machine was reclaimed on a notice too short for a save.
  • How much work runs again after a resume. For a lost machine it is "at least" that much.
  • What to do. After out of memory on a GPU, a resume that names no machine asks for GPUs with more memory by itself.

The Runs list and fluid ps say the failure in a few words after the state, for example "suspended (out of memory)".

If the same failure comes again after a resume, the event says so: which time it is in the job's life, whether a new checkpoint was taken in between, and what the ones before cost in work that ran again. A resume made the same way will end the same way. Where the ranks stop answering each other, or a rank is ended by a signal of its own, the event says that the script is the likely reason. Change something first. After out of memory, resume on GPUs with more memory. After a crash or a hang, fix the script and run the job again.

Sometimes a job cannot be resumed at once. If its last machine can no longer be asked (your own machine that left the workspace, for example), Fluid has no proof that the job stopped there. The machine's lease ends whatever still runs on it within a day. Until then a resume stays suspended, so that the job never runs twice. The console and fluid status JOB say the time from which it can be resumed and why.

If storage cannot be read at the moment of the failure, Fluid cannot check that the checkpoint is whole. It still suspends the job and ends the machine, so nothing is billed while you decide. The event and fluid status JOB say the checkpoint is not confirmed. A resume reads it first. If it is whole the job goes on from it. If it is not, the resume fails the job and says so.

Ranks that hang keep their GPUs busy, so GPU use does not show a hang. Fluid looks at each rank instead. A rank that waits for the others inside an exchange is waiting, whatever its GPU shows. A rank that is not inside an exchange and works, in one long call, in processes it started or writing a file, is working. The ranks are taken for hung only when, for the whole idle time, every rank either waited or did no work at all. The event then says what each rank was seen in, for example rank 0 inside all_reduce for 31 min, rank 1 outside an exchange and not working for 31 min. If your ranks were at work, give them longer: --policy idle.after_min=60. For a job of several ranks the idle time is one minute at the least: a shorter one is refused, since Fluid tells a hang from work by a look every few seconds.

When a rank runs out of memory

The ranks end, with an error that names the rank. The other ranks wait inside an exchange for the one that failed, and Fluid cannot capture them there. So the job goes back to its last checkpoint and is suspended on it.

Resume it on GPUs with more memory, for example fluid resume JOB --gpu 24G --gpus 2, or use a smaller batch. A resume on GPUs that are no larger is refused before any machine is started for it, with the size to choose. Fluid compares the memory a GPU has to use, which is a little less than the size a cloud lists: a 16 GB T4 has 15 GiB.

If none of your connections has larger GPUs, the refusal says so and names the largest on offer. Then connect a cloud whose GPUs are larger and resume the job there, or run the script again as a new run with a smaller batch. On GPUs of the same size the job would run out again at the same step.

Before the first checkpoint the job fails, and you run it again.

What moves with a rank

Everything a job of one process carries, for each rank, and:

  • the process group, as its backend, size and rank, formed again where the job lands, bound to the rank's GPU if you bound it;
  • the rank's current GPU, the GPUs it chose to see, and the random generators of the GPUs it uses;
  • a DistributedDataParallel model, rebuilt over the restored module;
  • a DistributedSampler and its epoch, with the loader's position.

Also carried: the groups your script made with new_group, made again in the order it made them, with a group you destroyed and still hold in a variable; and the handle of an isend, an irecv or a collective with async_op once it has completed. Such a handle answers what it answered before the move. It refuses three calls by name, because they are about the library's own object and not about the exchange: block_current_stream(), get_future_result() and boxed(). Not carried: a message that is under way (a pause waits until it has arrived), and what your script wrote to the rendezvous store.

On this page