In the context of Torch Distributed Elastic we use the term rendezvous to
refer to a particular functionality that combines a distributed
synchronization primitive with peer discovery.
It is used by Torch Distributed Elastic to gather participants of a training
job (i.e. nodes) such that they all agree on the same list of participants and
everyone’s roles, as well as make a consistent collective decision on when
training can begin/resume.
Torch Distributed Elastic rendezvous provides the following critical
functionalities:
Barrier:
Nodes performing rendezvous will all block until the rendezvous is considered
complete - this happens when at least min total number of nodes have joined
the rendezvous barrier (for the same job). This also implies the barrier is not
necessarily of fixed size.
There’s an additional small waiting time after reaching min number of
nodes - this is used to ensure the rendezvous is not completed “too quickly”
(which could potentially exclude additional nodes attempting to join at
approximately the same time).
If number of nodes is gathered at the barrier, the rendezvous is
completed immediately.
max
There’s also an overall timeout which causes the rendezvous to fail if min
number of nodes is never reached - this is meant to be a simple fail-safe to
help release partially allocated job resources, in case there’s a problem with
the resource manager, and is meant to be interpreted as non-retryable.
Exclusivity:
A simple distributed barrier would not be sufficient, as we also need to ensure
that only one group of nodes exists at any given time (for a given job). In
other words, new nodes (i.e. joining late) should not be able to form a parallel
independent group of workers for the same job.
Torch Distributed Elastic rendezvous ensures that if a group of nodes has
already completed a rendezvous (and hence might already be training), then
additional “late” nodes attempting to rendezvous will only announce themselves
as waiting, and will have to wait until the (previously completed) existing
rendezvous is destroyed first.
Consistency:
When a rendezvous is completed, all its members will agree on the job membership
and everyone’s role in it. This role is represented using an integer, called
rank, that is between 0 and world size.
Note that ranks are not stable, in the sense that the same node can be
assigned a different rank in the next (re-)rendezvous.
Fault-tolerance:
Torch Distributed Elastic rendezvous is designed to tolerate node failures
during the rendezvous process. Should a process crash (or lose network
connectivity, etc), between joining the rendezvous and it being completed, then
a re-rendezvous with remaining healthy nodes will happen automatically.
A node can also fail after it has completed (or has been observed by other
nodes to have completed) the rendezvous - this scenario will be handled by the
Torch Distributed Elastic train_loop instead (where it will also trigger a
re-rendezvous).
Shared key-value store:
When the rendezvous is completed, a shared key-value store is created and
returned. This store implements a torch.distributed.Store API (see
distributed communication docs).
This store is only shared by the members of the completed rendezvous. It
is intended to be used by Torch Distributed Elastic to exchange information
necessary to initialize job control and data-planes.
Waiting workers and rendezvous closing:
Torch Distributed Elastic rendezvous handler object provides additional
functionalities, which are technically not part of the rendezvous process:
Querying how many workers arrived late at the barrier, who can participate in
next rendezvous.
Setting the rendezvous closed to signal all nodes not to participate in
next rendezvous.
DynamicRendezvousHandler:
Torch Distributed Elastic comes with the DynamicRendezvousHandler
class that implements the rendezvous mechanism described above. It is a backend-
agnostic type that expects a particular RendezvousBackend instance
to be specified during construction.
Torch distributed users can either implement their own backend type or use one
of the following implementations that come with PyTorch:
C10dRendezvousBackend: Uses a C10d store (by default
TCPStore) as the rendezvous backend. The main advantage of using a C10d
store is that it requires no 3rd-party dependency (such as etcd) to establish
a rendezvous.
The run id is a user-defined id that uniquely identifies an instance of
a distributed application. It typically maps to a job id and is used to
allow nodes to join the correct distributed application.
A closed rendezvous means all future attempts to re-rendezvous within
same job will fail.
is_closed() and set_closed() have semantics of eventual
propagation and should not be used for synchronization. The intention is
that if at least one node decides the job is finished, it will close the
rendezvous, and other nodes will soon observe this and stop running as
well.
Blocks until the rendezvous is complete and the current process is
included in the formed worker group, or a timeout occurs, or the
rendezvous was marked closed.
– The connection to the rendezvous backend has failed.
abstractnum_nodes_waiting()
Return the number of nodes who arrived late at the rendezvous
barrier, hence were not included in the current worker group.
Callers should periodically call this method to check whether new
nodes are waiting to join the job and if so admit them by calling
next_rendezvous() (re-rendezvous).
Indicates that store reference returned by next_rendezvous() can be shared with user
applications and will be available during application lifecycle.
Rendezvous handler impl will share store details as instance of RendezvousStoreInfo.
Applications as a convention use MASTER_ADDR/MASTER_PORT env variables to lookup the store.
Implement a c10 Store interface by piggybacking on the rendezvous etcd instance.
This is the store object returned by EtcdRendezvous.
Etcd Server
The EtcdServer is a convenience class that makes it easy for you to
start and stop an etcd server on a subprocess. This is useful for testing
or single-node (multi-worker) deployments where manually setting up an
etcd server on the side is cumbersome.
If the specified token matches the fencing token stored in the
backend, the state will be updated. The new state will be returned
to the caller along with its fencing token.
If the specified token does not match the fencing token stored
in the backend, the state won’t be updated; instead the existing
state along with its fencing token will be returned to the caller.
If the specified token is None, the new state will be set
only if there is no existing state in the backend. Either the new
state or the existing state along with its fencing token will be
returned to the caller.
token (Any | None) – An optional fencing token that was retrieved by a previous call
to get_state() or set_state().
Returns:
A tuple of the serialized rendezvous state, its fencing token, and
a boolean value indicating whether our set attempt succeeded.
Raises
timedelta
|
None
last_call (timedelta | None) – An additional wait amount before completing the rendezvous once the
rendezvous has the minimum number of required participants.
close (timedelta | None) – The time within which the rendezvous is expected to close after a
call to RendezvousHandler.set_closed() or
RendezvousHandler.shutdown().
heartbeat (timedelta | None) – The time within which a keep-alive heartbeat is expected to
complete.
A boolean value indicating whether this backend instance
will host the C10d store. If not specified it will be
inferred heuristically by matching the hostname or the IP
address of this machine against the specified rendezvous
endpoint. Defaults to None.
Note that this configuration option only applies to
torch.distributed.TCPStore. In normal
circumstances you can safely skip it; the only time when
it is needed is if its value cannot be correctly
determined (e.g. the rendezvous endpoint has a CNAME as
the hostname or does not match the FQDN of the machine).
Implements a
torch.distributed.elastic.rendezvous.RendezvousHandler interface
backed by
torch.distributed.elastic.rendezvous.etcd_rendezvous.EtcdRendezvous.
EtcdRendezvousHandler uses a URL to configure the type of rendezvous to
use and to pass implementation specific configurations to the rendezvous
module. The basic etcd rendezvous configuration URL looks like the following
etcd://<etcd_address>:<port>/<job_id>?min_workers=<min_workers>&max_workers=<max_workers> # noqa: W605
-- example --
etcd://localhost:2379/1234?min_workers=1&max_workers=3
The URL above is interpreted as follows:
Use the rendezvous handler that is registered with the etcd
scheme
The etcd endpoint to use is localhost:2379
job_id==1234 is used as the prefix in etcd (this allows one to
share a common etcd server for multiple jobs so long as the
job_ids are guaranteed to be unique). Note that the job id can be
any string (e.g. does not need to be a number) as long as it is
unique.
min_workers=1 and max_workers=3 specifies a range for
membership size - Torch Distributed Elastic starts running the job as
long as the cluster size is greater than or equal to min_workers
and admits up to max_workers into the cluster.
Below are a full list of the parameters that can be passed to etcd
rendezvous:
Parameter
Description
min_workers
minimum number of
workers for the
rendezvous to be valid
max_workers
maximum number of
workers to admit
timeout
total timeout within
which next_rendezvous is
expected to succeed
(default 600s)
add(key, num)
Atomically increment a value by an integer amount.
The integer is represented as a string using base 10. If key is not present,
a default value of 0 will be assumed.
Both key and value may be either Python str or bytes.
wait(keys, override_timeout=None)
Wait until all of the keys are published, or until timeout.
Raises:
LookupError - if timeout occurs –
Note
tested on etcd server v3.4.3.
Starts and stops a local standalone etcd server on a random free
port. Useful for single node, multi-worker launches or testing,
where a sidecar etcd server is more convenient than having to
separately setup an etcd server.
This class registers a termination handler to shutdown the etcd
subprocess on exit. This termination handler is NOT a substitute for
calling the stop() method.
The following fallback mechanism is used to find the etcd binary:
Uses env var TORCHELASTIC_ETCD_BINARY_PATH
Uses <thisfileroot>/bin/etcd if one exists
Uses etcd from PATH
Usage
server=EtcdServer("/usr/bin/etcd",2379,"/tmp/default.etcd")server.start()client=server.get_client()# use clientserver.stop()
Parameters:
etcd_binary_path – path of etcd server binary (see above for fallback path)