Skip to content

Commit

Permalink
subspace
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Apr 21, 2024
1 parent 381fabb commit 936d9f2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion commune/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def namespace(cls, search=None,
update:bool = False,
public:bool = True,
netuid=0,
max_age:int = 3600, **kwargs) -> dict:
max_age:int = None, **kwargs) -> dict:

network = network or 'local'
path = network
Expand Down
8 changes: 5 additions & 3 deletions commune/subspace/subspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -3333,7 +3333,7 @@ def my_total_stake(self, netuid='all', network = 'main', fmt='j', update=False):
def check_valis(self, **kwargs):
return self.check_servers(search='vali', **kwargs)

def check_servers(self, search='vali',update:bool=False, netuid=0, min_lag=100, remote=False, **kwargs):
def check_servers(self, search='vali',update:bool=False, netuid=0, min_lag=100, timeout=30, remote=False, **kwargs):
if remote:
kwargs = c.locals2kwargs(locals())
return self.remote_fn('check_servers', kwargs=kwargs)
Expand All @@ -3348,11 +3348,13 @@ def check_servers(self, search='vali',update:bool=False, netuid=0, min_lag=100,
port = int(stats['address'].split(':')[-1])
if not c.server_exists(module) or lag > min_lag:
c.print(f"Server {module} is not serving or has a lag of {lag} > {min_lag}")
response_batch[module] = c.submit(c.serve, kwargs=dict(module=module, network=f'subspace.{netuid}', port=port))
response_batch[module] = c.submit(c.serve,
kwargs=dict(module=module, network=f'subspace.{netuid}', port=port),
timeout=timeout)

futures = list(response_batch.values())
future2key = {f: k for k,f in response_batch.items()}
for f in c.as_completed(futures):
for f in c.as_completed(futures, timeout=timeout):
key = future2key[f]
c.print(f.result())
response_batch[key] = f.result()
Expand Down
8 changes: 6 additions & 2 deletions vali/vali.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,11 @@ def votes(self,

):
network = self.config.network
keys = ['name', 'w', 'staleness','latency', 'ss58_address'],
leaderboard = self.leaderboard(network=network, keys=keys, to_dict=True, n= self.config.max_votes)
keys = ['name', 'w', 'staleness','latency', 'ss58_address']
leaderboard = self.leaderboard(network=network,
keys=keys,
to_dict=True,
n=self.config.max_votes)
votes = {'keys' : [],'weights' : [],'uids': [], 'timestamp' : c.time() }
key2uid = self.subspace.key2uid() if hasattr(self, 'subspace') else {}
for info in leaderboard:
Expand Down Expand Up @@ -518,6 +521,7 @@ def leaderboard(self,
r = self.get(path, max_age=max_age)
if isinstance(r, dict) and 'ss58_address' in r:
r['staleness'] = c.time() - r.get('timestamp', 0)
c.print(keys)
df += [{k: r.get(k, None) for k in keys}]
else :
# removing the path as it is not a valid module and is too old
Expand Down

0 comments on commit 936d9f2

Please sign in to comment.