Spread a Job over Workers¶
One exec job with a guest per node, each on its own worker of one zone. All nodes start together or not at all.
Requirements:
- An exec app, see Declare an Exec App
- Exec workers in one zone, see Set Up an Exec Worker
1. Set nodes¶
# flake.nix
passthru.gradient = {
nodes = 4;
devices = [ "gpu:h100:8" ];
args = [ "--master" "@gradient.cluster.master_addr@:@gradient.cluster.master_port@" ]; # (1)!
keepRunning = false; # (2)!
};
- Node 0 is the master. All nodes receive the master address and port.
-
A node failure doesn't stop the other nodes when the value is
true. -
Multi-node jobs need
network. The default for a missingnetworkistrue. Apps withnetwork = falsefail withnodes > 1 needs network. - Every worker needs
exec.allow.nodesof at leastnodes, plusexec.allow.network. - All nodes share one zone. Too few matching workers in one zone leave the job waiting with
needs N workers in one zone. - Lists and events show the job once, under node 0. All node statuses combine into the job status.
2. Read the Cluster Context¶
| Key | Variable | Value |
|---|---|---|
node_index |
GRADIENT_NODE_INDEX |
Index of this node, from 0 |
node_count |
GRADIENT_NODE_COUNT |
Number of nodes |
master_addr |
GRADIENT_MASTER_ADDR |
Guest address of node 0 |
master_port |
GRADIENT_MASTER_PORT |
Port for the master process |
peers |
GRADIENT_PEERS |
Every node as JSON, sorted by index, this node included |
attempt |
GRADIENT_ATTEMPT |
Attempt number, starting at 1 |
argsandenvaccept the keys as@gradient.cluster.<key>@.- The default for the master port is 29500. A value of 29500 outside the
exec.allow.portsrange of the master worker, or already present in the job'sports, can make the job use the lowest free port inexec.allow.portsinstead.
3. Connect the Workers¶
Nodes connect to each other on their guest addresses. The operator provides the network between the exec workers of a zone.
| Need | Setup |
|---|---|
| Own subnet | A distinct exec.subnet.v4 on every exec worker |
| Routes | A route to the subnet of every other exec worker, via that worker. Static routes or the LAN router both work |
| Forwarding | No drop rule for traffic between the LAN interface and exec.bridge |
| Ports | The exec.allow.ports ports open between the workers |
# configuration.nix of worker a, LAN address 192.168.1.11
services.gradient.worker.exec.subnet.v4 = "10.233.0.0/16";
networking.interfaces.eth0.ipv4.routes = [
{ address = "10.234.0.0"; prefixLength = 16; via = "192.168.1.12"; } # (1)!
];
-
Worker b with
exec.subnet.v4 = "10.234.0.0/16"and a route back to10.233.0.0/16. -
Worker NATs can hide a guest's source address. Peers see the address of the other worker as source.
- Rules in the guest filter drop new connections from guests to private networks that
exec.allow.allowedPrivateNetworksdoesn't list. List the guest subnets of all other exec workers there on each exec worker. Responses to connections from other workers pass through the filter, even when the source is the private address of another worker. See Limit the Guest Network for details. - Two workers on one subnet fail every node with
Two nodes have guest address <address>. Assign a unique exec.subnet.v4 to each exec worker.
4. Plan for Restarts¶
| Event | Result |
|---|---|
A node failed or timed out, without keepRunning |
The other nodes stop. Every node restarts from its last phase while retries remain, one retry per restart |
A node failed, with keepRunning = true |
The other nodes go on. The job ends failed after the last node, without a restart |
| A lost worker connection | Every node restarts from its last phase without a retry. A fourth loss fails the job |
| A server restart | Every node restarts from its last phase without a retry. Server restarts stay outside the limit of losses |
| An abort | Every node ends aborted. No restart |
- Workers apply caps to the
retriesof their own nodes. Jobs take the lowest of those capped values as their retry count. - Phases mark the restart point of each node, see Report Phases.
Warning
Nodes never survive a lost worker connection or a server restart. These cases stay the same with stopGuestsWithWorker = false. All nodes restart from their last phase.
Verify Deployment¶
- The job page shows a Node picker with one entry per node.
- Logs follow the selected node.
Next Steps¶
- Workers: zones
- Open a Terminal: node logins and the Node picker
- Report Phases and Upload Outputs: restart points