Routing
The built-in routing system allows clients to dynamically discover and communicate with subnet nodes capable of handling tasks (e.g., inference, validation, uploads).
How It Works
See how to use for an example on how to start a client node.
The
Router
periodically queries the DHT Records for available nodes.These nodes can be stored under role-specific keys (e.g.,
"hoster"
), allowing the router to filter based on function.
The router then keeps an up-to-date list of reachable peers that can be called for application-level RPC tasks.
Customizing Node Discovery
To tailor this to your own subnet:
Modify
get_node_infos(...)
to fetch nodes based on your custom UID (e.g.,"trainer"
,"validator"
,"relayer"
)Use metadata to prioritize nodes
Extend the ping logic to measure latency, uptime, or region
Periodical Routing Updates:
In this example from the Inference Example, each node that hosts the model is stored in the DHT Records using "hoster" as the key. The client can then utilize this list
In this function, update the get_node_infos
to gather every node that should be able to be called to perform the tasks of a subnet.
def _update(self):
"""
Perform an immediate and synchronous refresh, may take time
"""
hoster_infos = get_node_infos(
self.dht,
uid="hoster",
latest=True
)
with self.lock_changes:
self.state.remote_servers_infos.update_(hoster_infos)
all_servers = [server.peer_id for server in hoster_infos]
self.ping_aggregator.ping(list(all_servers), wait_timeout=self.config.ping_timeout)
self.ready.set()
Last updated