torchrun job on 2 nodes with 8 GPUs each. The nodes find each other over a private subnet and exchange training data over an isolated InfiniBand partition. By the end, you’ll have trained nanoGPT on a small corpus of Shakespeare and generated text from it.
Before you start
Set up your account, a partition, a subnet, and a pool before you create any instances. A pool holds the allocation your instances run on. You need thesf CLI, logged in to your account. See the Quickstart to install it.
The examples use landsend, a SKU with 8 H100 GPUs per node: ID sku_4EzdPrHcTps, region europe-north1, zone a, on the InfiniBand fabric europe-north1-a.fab1. A fabric is the physical InfiniBand network that a SKU’s nodes connect to. To use another SKU with InfiniBand, replace these values with its own.
1
Enroll in the InfiniBand preview
Enroll your account so the
sf infiniband-partitions commands and the --infiniband-partition flag become available.2
Create a partition on your SKU's fabric
Create a partition named Only instances in the same partition can reach each other over InfiniBand. See Create a partition for the other options.
training on your SKU’s fabric.3
Create a subnet in your SKU's zone
Create a subnet named Note the subnet
training in your SKU’s region and zone.id in the output, which starts with snet_. You need it to delete the subnet later.Instances in the subnet reach each other over private IPv4 addresses. torchrun uses the subnet to start the job, and the NVIDIA Collective Communications Library (NCCL) sends the training traffic over InfiniBand.4
Write a startup script
SF Compute public images ship with no SSH key. This script adds your public keys to the See Cloud-init for other ways to configure an instance.
root user when the instance boots. The $(cat ...) lines run on your machine as you write the file. If you have none of these keys, create one with ssh-keygen -t ed25519 first.To use a key stored elsewhere, see SSH into an instance.5
Buy an allocation of 2 nodes
Create a pool named
training and buy an allocation of 2 nodes of your SKU for 4 hours. The 4 hours start as soon as the order fills, so buy last and start the next section right after. Your organization needs enough credits to cover the price.The sf buy command quotes the price and asks you to confirm before it charges your organization for the full 4 hours. To skip the prompt in a script, add --max-rate with the highest price per node-hour you accept, and --yes.Launch the job
Each instance runstorchrun with a node rank, a number from 0 that identifies it in the job. The rank 0 instance coordinates the job, and the job needs only that instance’s private subnet address.
1
Create one instance per node
Create 2 instances in the partition and the subnet. This loop names them Wait until both instances show SSH becomes available after the image downloads and the instance boots, which can take up to 10 minutes. See Instances. If
training-0 and training-1 and gives them the private addresses 10.1.0.10 and 10.1.0.11. --public-ipv4 gives each instance a public address for sf instances ssh to connect to.running in this list.sf instances ssh reports that SSH details aren’t available yet, wait a minute and retry.2
Find the subnet interface
Open one terminal per instance and connect as On each instance, print the interface that holds the instance’s subnet address.The first field,
root, the user the startup script added your key to. Start with training-0.ens1 here, is the interface name, which can differ on each instance.3
Set up nanoGPT on every instance
This guide trains nanoGPT, a small GPT model, on 1 MB of Shakespeare. Install uv, clone nanoGPT, install its packages, and prepare the dataset. Run these commands on each instance.
prepare.py downloads the text and writes train.bin and val.bin to data/shakespeare_char/. Each instance reads its own copy.4
Run torchrun on every instance
Start The
torchrun on each instance with its own node rank: 0 on training-0 and 1 on training-1. Replace ens1 with the instance’s subnet interface.NCCL_SOCKET_IFNAME sets the interface that NCCL uses to connect the instances at startup. The subnet interface is the one the other instance can reach. NCCL then sends the training data over InfiniBand.The flags after the config file change nanoGPT’s single-GPU defaults for 16 GPUs:--gradient_accumulation_steps=16: nanoGPT splits this value across the GPUs, so it must be a multiple of the GPU count--max_iters,--lr_decay_iters,--warmup_iters: shorten the run, since each step now covers 16 GPUs’ worth of data--eval_interval,--eval_iters: evaluate every 100 steps on 20 batches, so evaluation fits the short run
--nnodes instances have joined, then training starts. Each GPU prints the NCCL network line, and training-0 prints the loss every 100 steps.NET/IB line lists 1 InfiniBand device per GPU, so NCCL sends the job’s traffic over InfiniBand. Device names and their order vary by node. OOB (out-of-band) names the subnet interface that NCCL used to connect the instances.On 2 landsend nodes, the run takes about 40 seconds.If the job exits or hangs with no output, run the command again without the final grep to see the full log.5
Generate text from the model
training-0 saves the checkpoint to out-shakespeare-char/. Generate 300 characters from it on training-0.Clean up
Terminate the instances when the job ends, then delete the partition and the subnet. Run these commands on your machine, not on an instance.sf infiniband-partitions instances training no longer lists the instances.
sf CLI can’t delete subnets, so open Networks in the console and delete training.
To use the API instead, create an API token. Grant it a role that can delete subnets, such as admin. Then send a DELETE request with the subnet ID:
training pool stays after cleanup, so skip sf pools create on a rerun.
Terminating an instance doesn’t free its allocation. You paid for the 4 hours when the order filled, and the pool keeps the 2 nodes until they end.
To get credits back for allocation you don’t use, place a sell order on the pool. This example offers the 2 nodes for the next 2 hours at $10.00 per node-hour or more:
Next steps
Use these pages to manage the job’s resources:- InfiniBand partitions: fabrics, partitions, and link checks
- Subnets: private networks and addresses
- Instances: instance states, priority, and termination
- Pools: the allocation for the nodes in your job