Playbook · DGX Spark cluster
PyTorch's own tools run one program across both Sparks, mainly for training and fine-tuning.
PyTorch's distributed traffic has no sign-in and no encryption. PyTorch says anyone with network access to it can run code as your user. Use it only on a network you fully control.
Checked on 26 November 2026 against: PyTorch 2.15 torchrun and distributed documentation, PyTorch's security policy and NVIDIA's PyTorch fine-tuning playbooks. We have not yet run this playbook start to finish on our own hardware.
Watch, then follow
Decide, then configure. Before you run PyTorch on two DGX Sparks, here's what to decide.
The AI stack. We start at the bottom of the stack, with two machines that must run one job.
Share the model. With DDP, each Spark holds a full copy of the model. FSDP can shard it instead, so each holds part of the weights and training state.
Done, or your job. torchrun starts processes on its own Spark, and numbers them. DDP combines gradients. Your code must pick the GPU, divide the data, and save checkpoints.
Divide the samples. DDP doesn't divide your data. Use a distributed sampler with your data loader. Set the epoch each time round, or the shuffled order repeats. The batch size is per process, so two Sparks take twice as many samples each step.
It stays on its Spark. CPU work doesn't move between Sparks. Threads and data workers use their own Spark's processor. With one process on each, torchrun leaves the thread setting as it was. With more than one, and nothing set, it sets one thread each.
Data workers. Data loader workers start at zero, so the training process loads the data itself. Add workers in small steps. Each uses processor time and memory. In a container, give them enough shared memory.
Decide, then measure. The page lists every setting and its default. We haven't run this on hardware.
10 steps
Set up, check, stop. Now let's run a small check across both Sparks.
A private network. PyTorch's distributed traffic has no sign-in and no encryption. Anyone who can reach it can run code as your user, so use only a network you control.
Same container. Save the small check script on both Sparks. Open the same PyTorch container on each. It uses the Spark's own network, and your work folder. Set the head address to the first Spark, and name the cluster interface.
One command. Run the same torchrun command on both. It asks for two nodes, one process each. Start the first, then promptly the second.
Look for two. Each side should say a world size of two. And each should show a sum of two. If it waits, check the address, port, job name and link.
Start small. Try your own script on a small piece of data. Watch the GPU, processor and memory on both. Change one setting at a time, and compare the same number of steps. Test that you can resume from a checkpoint, and that both Sparks can read it.
Stopping loses work. Stopping loses work since the last checkpoint. Press control C on both, check the GPU is free, then leave each container. To undo, delete the check script. The container removes itself.
Check first. The written page has the commands, fixes and sources.
10 steps
Is this the one?
Training or fine-tuning across both Sparks, or your own program written for more than one machine.
Part of PyTorch. One launcher, torchrun, starts and watches the processes. Training libraries such as Accelerate build on the same base.
It is not a model server. The script must be written for distributed running. Both nodes must stay up, and communication can limit speed: PyTorch notes that four GPUs in one machine train faster than four machines with one GPU each.
Compare all five in the cluster method chooser.
Before you start
Two DGX Sparks on the same current DGX OS, with the cable link set up and tested as in the cluster setup guide. In the commands, my-spark is the first Spark, spark-two the second, and USER your user name. Replace words in capitals with your own values. Nothing on this page has been run by us on hardware.
Docker with GPU access on both Sparks, and the same PyTorch container tag on both. NVIDIA's playbooks use images from nvcr.io/nvidia/pytorch; take the tag the current playbook names. Passing the NCCL test in the cluster guide first saves time.
How it fits together
Decide first
Settings in the next four sections were checked on 27 November 2026 against the PyTorch 2.15 documentation, and where it says so, the 2.15.0 source. None of them has been run by us on DGX Spark hardware.
| Decision | Your choices | How to decide |
|---|---|---|
| How the model uses two GPUs | DistributedDataParallel (DDP), or FullyShardedDataParallel (FSDP) | With DDP each process holds its own full copy of the model, so the model and its training state must fit on one Spark. FSDP with full sharding splits parameters, gradients and optimizer state between the processes. Either one needs your script, or your training library, to set it up. |
| Backend | nccl or gloo | PyTorch says to use NCCL for training on CUDA GPUs, and Gloo for CPU training; Gloo is also its fallback if NCCL gives trouble on Ethernet. Use nccl for GPU training on two Sparks. |
| Processes on each Spark | --nproc-per-node | A DGX Spark has one GPU, and DDP expects one process for each GPU. So this page uses 1. |
| How the two meet | c10d or static rendezvous | PyTorch recommends c10d, which hands out ranks. With static, the default, you give each machine its own --node-rank. |
| Fixed or changing size | --nnodes=2 or a range such as 1:2 | Keep 2 unless your script can resume from a checkpoint with a different number of processes. When membership changes, all surviving workers are killed and a new group starts. |
| Restarts | --max-restarts | The default is 0. A restart only helps if your script loads its last checkpoint at start-up. |
| CPU threads and data workers | Two separate settings | See CPU settings. They are per process and per Spark. |
| Files | Code, data, checkpoints | Decide how both Sparks get the same code and data, and where checkpoints go so both can read them when resuming. |
Automatic or not
No CPU load moves from one Spark to the other. You start torchrun on each Spark. Each starts processes on its own machine, and each process, its CPU threads and its DataLoader workers use that Spark's processor. PyTorch shares data between the processes only where the program uses its distributed functions, directly or through something like DDP.
| Job | Done for you | What your code or you must do |
|---|---|---|
| Starting processes | torchrun starts and watches the workers on the machine where you run it | Start it on both Sparks, with the same job name and meeting point |
| Ranks | With c10d, torchrun sets RANK, LOCAL_RANK and WORLD_SIZE | Read them. Do not tie a Spark to a rank: PyTorch warns that ranks can change after a restart or membership change |
| Choosing the GPU | Nothing by itself | Use LOCAL_RANK as the GPU number, and wrap your model in DDP with it |
| Dividing the dataset | DDP does not divide your input. DistributedSampler divides the sample numbers when you use it | Give it to the DataLoader as sampler, without shuffle=True. Call set_epoch at the start of each epoch, before looping over the loader, or the shuffled order repeats |
| Batch size | Each process loads its own batches | batch_size is per process: with two processes, one step covers twice that many samples. Check your learning rate and loss: PyTorch notes that the scale of gradients depends on whether your loss averages or sums |
| Gradients | DDP all-reduces them during the backward pass | Build the same model on both before wrapping it, and do not change its parameters afterwards |
| Uneven data | Not by default | Give both the same number of batches, or use DDP’s join context manager |
| Preparing data on the CPU | DataLoader workers on the same Spark, if you set num_workers | Choose the number. One-off work such as tokenising a dataset is not shared between machines unless your code does it |
| Model memory | With DDP, no: a full copy each | Use FSDP or another sharding method if one copy does not fit |
| Code, datasets, caches | Not copied by these commands | Put the same versions on both Sparks, at paths your script can open |
| Checkpoints | Nothing is saved unless your code saves it | With DDP, write from one process. That file lands on that process’s Spark, so make it readable on both before you resume |
The sampler gives each process every second index. With its default drop_last=False it repeats a few samples when the dataset does not divide evenly; with True it leaves the tail out.
This shows the shape, in our own words. It is not a complete script: you write build_dataset, build_model and train_step, and replace the capitals. It does not load a checkpoint, so add that before you rely on restarts. We have not run it.
import os
import torch
import torch.distributed as dist
from torch.nn.parallel import DistributedDataParallel as DDP
from torch.utils.data import DataLoader
from torch.utils.data.distributed import DistributedSampler
def main():
local_rank = int(os.environ["LOCAL_RANK"])
torch.cuda.set_device(local_rank)
dist.init_process_group(backend="nccl")
dataset = build_dataset()
sampler = DistributedSampler(dataset)
loader = DataLoader(dataset, batch_size=BATCH_PER_PROCESS,
sampler=sampler, num_workers=NUM_WORKERS)
model = DDP(build_model().to(local_rank), device_ids=[local_rank])
optimizer = torch.optim.AdamW(model.parameters())
for epoch in range(EPOCHS):
sampler.set_epoch(epoch)
for batch in loader:
train_step(model, optimizer, batch, local_rank)
if dist.get_rank() == 0:
torch.save(model.module.state_dict(), "checkpoint.pt")
dist.destroy_process_group()
if __name__ == "__main__":
main()
This example overwrites checkpoint.pt after every epoch. Use a new folder, or your own file names, so you do not replace a checkpoint you need. A real resume also needs the optimizer state and your position in training.
When loading, PyTorch’s DDP tutorial passes a map_location so each process loads onto its own device. A training library such as Accelerate may do several of these jobs for you; read its documentation to see which.
From the DDP reference, the data loading reference, the multi-GPU tutorial, the DDP tutorial and the multi-node tutorial.
CPU settings
NVIDIA lists a 20-core Arm processor in DGX Spark, and 128 GB of memory shared by the processor and the GPU. Memory that data loading uses comes out of the same pool as the model’s.
| Setting | What it controls | Default | When to change it |
|---|---|---|---|
OMP_NUM_THREADS | OpenMP threads in each process | torchrun’s source: if you have not set it and --nproc-per-node is above 1, torchrun sets it to 1 and prints a warning. With 1, as here, torchrun leaves it as it was. | When timings or CPU use show too many or too few threads. Set it the same way on both Sparks and measure |
torch.set_num_threads(n) | Threads PyTorch uses inside one CPU operation, in that process | Chosen by PyTorch; print torch.get_num_threads() to see it | Call it near the start, before PyTorch has run any work |
num_workers | Separate processes that load data, for each DataLoader in each training process | 0: the training process loads the data itself | When the GPU waits for data. Raise it in steps and measure. Each worker uses CPU and memory |
prefetch_factor | Batches each worker loads ahead | None with no workers; 2 with workers | Lower it if waiting batches use too much memory; raise it only if measurement shows a gain |
persistent_workers | Whether workers stay alive after one pass through the data | False | If starting workers again each epoch costs time. They keep their memory |
pin_memory | Whether the loader puts batches in page-locked memory before returning them | False | Measure with and without. Memory on DGX Spark is shared, and we have not measured this there |
--ipc=host or --shm-size | Shared memory the container has for passing data between processes | Docker’s own shared memory is too small for multi-worker loading, PyTorch says | Keep one of the two. This page uses --ipc=host |
The When to change it column is our advice, not PyTorch’s.
PyTorch’s rule against too many threads: with N processors and M processes on one machine, PyTorch says that each should use at most N divided by M threads, rounded down. Apply it to each Spark on its own; the two processors are not added together.
Our advice: count your DataLoader workers as users of those processors too, and leave room for the system and anything else running. We give no thread or worker number: it depends on your data and your script.
Inside each DataLoader worker, PyTorch sets its own thread count to 1. That line is about PyTorch’s own threads; we have not checked what other libraries in your data code do. Workers get different PyTorch seeds, but other libraries’ random numbers may need seeding in worker_init_fn. PyTorch also warns that workers can come to use as much CPU memory as the parent process, for example when the dataset holds many Python objects.
To see what a container starts with, run this inside it on both Sparks:
python3 -c 'import os, torch; print(os.cpu_count(), torch.get_num_threads(), os.environ.get("OMP_NUM_THREADS"))'
To set the thread count for one run, type your number in place of the capitals, in front of the same torchrun command, on both:
OMP_NUM_THREADS=YOUR-THREADS torchrun --nnodes=2 --nproc-per-node=1 \
--rdzv-id=spark-train --rdzv-backend=c10d \
--rdzv-endpoint="$HEAD_IP:29400" \
YOUR-SCRIPT.py
Every setting
Defaults are from the PyTorch 2.15.0 torchrun source unless another page is named. --standalone is for jobs on a single machine; do not use it here.
| Setting | Default | What it controls and when to change it |
|---|---|---|
--nnodes | 1:1 | Number of machines, or a minimum and maximum. Set 2 |
--nproc-per-node | 1 | Processes on this machine; also takes gpu, cpu, xpu or auto. cpu starts one per counted processor, which is not what a one-GPU training job wants |
--rdzv-backend | static | How the machines find each other. This page sets c10d |
--rdzv-endpoint | empty | The meeting point as host and port. With c10d, the torchrun page uses 29400 if you give no port |
--rdzv-id | none | The job’s name. The same on both; give each job its own |
--rdzv-conf join_timeout | 600 seconds | Rendezvous page: time allowed for the meeting to complete. Raise it if the second Spark cannot be started in time |
--max-restarts | 0 | Times the worker group may be restarted before the job fails |
--monitor-interval | 0.1 seconds | How often torchrun looks at the workers’ state. We know no reason to change it here |
--node-rank | 0 | Only for static rendezvous |
--master-addr, --master-port | This machine; 29500 | Only for static rendezvous |
--log-dir, --redirects, --tee | No folder; no redirect; no copy | Save worker output to files, or to files and the screen. --tee 3 copies both normal and error output. Logs stay on each Spark |
init_process_group timeout | 10 minutes with NCCL, 30 with other backends | Distributed page. A long step by one process while the other waits can hit it. Find the cause before raising it |
NCCL_SOCKET_IFNAME, GLOO_SOCKET_IFNAME | Found automatically | Which network interface to use. Set them to the cluster interface, so you know which one is meant |
NCCL_DEBUG | Not set by this page | INFO prints how NCCL started, for troubleshooting |
torchrun also passes each worker LOCAL_WORLD_SIZE, GROUP_RANK, MASTER_ADDR, MASTER_PORT and TORCHELASTIC_RESTART_COUNT, among others.
Set up
In an empty folder on each Spark, save this as check_link.py. Each process starts with the number 1; adding them across the two should give 2.
import os
import socket
import torch
import torch.distributed as dist
local_rank = int(os.environ["LOCAL_RANK"])
torch.cuda.set_device(local_rank)
dist.init_process_group(backend="nccl")
value = torch.ones(1, device="cuda")
dist.all_reduce(value)
print(f"{socket.gethostname()} rank {dist.get_rank()} of "
f"{dist.get_world_size()}: sum = {value.item()}")
dist.destroy_process_group()
From that folder. ETH_IF is the cluster interface that is up. HEAD_IP is the first Spark's link address, on both.
export HEAD_IP="FIRST-SPARK-LINK-ADDRESS"
export ETH_IF="enp1s0f1np1"
export PT_IMAGE="nvcr.io/nvidia/pytorch:TAG-FROM-NVIDIA-PLAYBOOK"
docker run --rm -it --name pt-cluster \
--gpus all --network host --ipc host --ulimit memlock=-1 \
--device /dev/infiniband \
-e HEAD_IP \
-e NCCL_SOCKET_IFNAME="$ETH_IF" -e GLOO_SOCKET_IFNAME="$ETH_IF" \
-v "$PWD:/work" -w /work "$PT_IMAGE"
--device /dev/infiniband passes in the fast link's devices. Without them NCCL falls back to ordinary networking, which is much slower.
Host networking lets the container use the Spark's networks directly, and the folder you mount can be changed from inside it. Mount only your work folder, and use images and code you trust.
Start it on the first Spark, then promptly on the second. Both use identical arguments.
torchrun --nnodes=2 --nproc-per-node=1 \
--rdzv-id=spark-check --rdzv-backend=c10d \
--rdzv-endpoint="$HEAD_IP:29400" \
check_link.py
The torchrun page explains these: --nnodes is the number of machines, --nproc-per-node the processes on each, and the rendezvous options say where they meet. Do not give the two Sparks fixed rank numbers in your code; torchrun hands them out.
Check
| What you see | Meaning |
|---|---|
| Each terminal prints its host name, a rank of 2, and sum = 2.0 | Both processes joined and exchanged data. |
Set NCCL_DEBUG=INFO before the command | The log shows which interfaces and transport NCCL chose. Check they are the cluster ones. |
| It stops at start-up | One side never arrived. Check the address, the port, the job name and the ping between the Sparks. |
While your real script runs, watch each Spark from a second terminal: nvidia-smi shows the GPU, and top shows processor and memory use (press 1 to see each processor). Our advice: if the GPU often waits while data workers are busy, look at data loading; if many threads compete and throughput falls, try fewer. Change one setting at a time, and compare the same number of steps.
Then try your real script with a very small dataset and few steps. Save checkpoints, and test that you can resume from one, before a long run. Load only checkpoints your own jobs wrote: PyTorch warns that loading a distributed checkpoint can run code.
NVIDIA's playbooks
NVIDIA's current fine-tuning playbook uses Docker Swarm and Accelerate for two nodes. It changes the Docker settings on both Sparks and restarts Docker, which stops running containers.
Read any start script before you run it. On 26 November, the container start script in NVIDIA's earlier PyTorch fine-tuning playbook turned on SSH sign-in for the root user with a fixed, well-known password, and turned off host-key checks, in a container using the Spark's own network. Do not run it like that on any network others can reach. The commands on this page need no SSH server in the container.
Check the current files yourself; they may have changed since.
Stop and undo
Stopping a job loses work since its last checkpoint.
To stop: press Ctrl+C on both Sparks, then check that neither still shows the process in nvidia-smi. Leave each container with exit; --rm removes it. From another terminal:
docker stop pt-cluster
To undo: delete check_link.py and, if you want the disk space, the image with docker rmi. These steps changed no system settings. If you followed the Swarm playbook, use its own clean-up steps.
Problems
If a worker fails, torchrun stops the local group and, with --max-restarts set, can start it again. If a whole node's launcher is lost, PyTorch says it is up to whatever manages the job to stop or replace it. Do not assume a long run recovers by itself.
| What you see | What to try |
|---|---|
| Connection refused or time-out at the meeting point | Start the first Spark first; check the link address and that nothing else uses the port. |
| NCCL errors after joining | Run NVIDIA's NCCL test, and check the interface setting on both. |
| Both Sparks seem to train on the same samples, or every epoch has the same order | Check that the DataLoader uses DistributedSampler and that set_epoch is called each epoch. |
| A DataLoader worker is killed, or reports a shared memory error | Keep --ipc=host or give a larger --shm-size, check free memory, and try fewer workers. |
| Training stalls near the end of an epoch | One process may have run out of batches first. Make the counts equal, or use join. |
| Out of memory | Splitting depends on how your script shares the model. Lower the batch size or sequence length. |
More: cluster problems by symptom.
Next
Server AI Hub is our app for looking after a DGX Spark. You do not need it to follow this playbook. It is coming soon to the App Store and the Microsoft Store.
Sources
Read on 26 and 27 November 2026. These projects change often; if their pages differ from this one, follow them.
General guidance only, in our own words. Back up before you start; you use these steps at your own risk. NVIDIA, DGX, DGX Spark, ConnectX and CUDA are trademarks of NVIDIA Corporation; Kubernetes, K3s, Ray, PyTorch, vLLM, SGLang, NGINX, Docker and other names belong to their owners. 6ixLabs is not affiliated with or endorsed by NVIDIA or any of these projects.