Class ClusterLeader
java.lang.Object
smile.llm.cluster.ClusterLeader
- All Implemented Interfaces:
AutoCloseable
The control side of a multi-node model: the leader process owns the server and the engine, and every call that changes
model state (bind, prefill, decode step, finish...) is mirrored to the follower processes, which hold the other ranks
and execute the identical call so that the NCCL collectives of all ranks line up.
Wire format: leader to follower [int length][byte op][payload]; follower to leader
[byte status][long seq][int value] (status 0 ok, otherwise followed by a UTF error message). Messages of one
connection are numbered 1, 2, ... in send order; the follower acknowledges each after executing it.
If a follower fails or disconnects, the collectives of the other ranks would hang forever, so by default the leader
halts the JVM (SMILE_CLUSTER_FAIL_FAST=0 only logs).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceWrites the arguments of a message. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionvoidawaitAck(long n) Blocks until every follower has executed messagen; throws if one failed.voidThrows if a follower has failed.voidclose()intReturns the number of followers.longsend(int op, ClusterLeader.PayloadWriter payload) Sends one message to every follower (they execute it concurrently with the leader).static voidsetFailFast(boolean enabled) Whether a failed follower halts the JVM (the default: the other ranks would hang in a collective forever).static ClusterLeaderWaits for the followers to connect, assigns ranks (the leader owns ranks0 .. leaderRanks - 1, then the followers innodeIndexorder) and sends each follower its welcome: world size, first rank, the NCCL unique id andparams.static ClusterLeaderstart(int port, int followers, int leaderRanks, long timeoutMs, Map<String, String> params, byte[] uniqueId) Asstart(int, int, int, long, Map)with an explicit NCCL unique id (tests, or a launcher that made it).byte[]uniqueId()Returns the NCCL unique id shared with the followers.intvalueOf(int index, long n) intReturns the ranks of the whole communicator.
-
Field Details
-
OP_SHUTDOWN
public static final int OP_SHUTDOWNOp code of the shutdown message.- See Also:
-
-
Method Details
-
setFailFast
public static void setFailFast(boolean enabled) Whether a failed follower halts the JVM (the default: the other ranks would hang in a collective forever).- Parameters:
enabled-falseonly logs, for tests.
-
start
public static ClusterLeader start(int port, int followers, int leaderRanks, long timeoutMs, Map<String, String> params) throws IOExceptionWaits for the followers to connect, assigns ranks (the leader owns ranks0 .. leaderRanks - 1, then the followers innodeIndexorder) and sends each follower its welcome: world size, first rank, the NCCL unique id andparams.- Parameters:
port- TCP port to listen on.followers- number of follower processes to wait for.leaderRanks- ranks (GPUs) of the leader process.timeoutMs- how long to wait for all followers.params- settings every process must share (batch size, memory fraction...).- Returns:
- the connected cluster.
- Throws:
IOException- if a follower does not show up or the handshake fails.
-
start
public static ClusterLeader start(int port, int followers, int leaderRanks, long timeoutMs, Map<String, String> params, byte[] uniqueId) throws IOExceptionAsstart(int, int, int, long, Map)with an explicit NCCL unique id (tests, or a launcher that made it).- Parameters:
port- TCP port to listen on.followers- number of follower processes to wait for.leaderRanks- ranks (GPUs) of the leader process.timeoutMs- how long to wait for all followers.params- settings every process must share.uniqueId- the 128-byte NCCL unique id, ornullto create one.- Returns:
- the connected cluster.
- Throws:
IOException- if a follower does not show up or the handshake fails.
-
worldSize
public int worldSize()Returns the ranks of the whole communicator.- Returns:
- ranks of the whole communicator.
-
uniqueId
public byte[] uniqueId()Returns the NCCL unique id shared with the followers.- Returns:
- the NCCL unique id shared with the followers.
-
followers
public int followers()Returns the number of followers.- Returns:
- the number of followers.
-
send
Sends one message to every follower (they execute it concurrently with the leader).- Parameters:
op- op code (> 0); the follower's handler decides what it means.payload- writes the arguments, ornullfor none.- Returns:
- the message number, for
awaitAck(long)andvalueOf(int, long).
-
awaitAck
public void awaitAck(long n) Blocks until every follower has executed messagen; throws if one failed.- Parameters:
n- the message number fromsend(int, ClusterLeader.PayloadWriter).
-
valueOf
public int valueOf(int index, long n) - Parameters:
index- follower, in rank order.n- message number.- Returns:
- the value, or
-1when it returned none.
-
checkHealthy
public void checkHealthy()Throws if a follower has failed. -
close
public void close()- Specified by:
closein interfaceAutoCloseable
-