Skip to content

Commit

Permalink
valid
Browse files Browse the repository at this point in the history
  • Loading branch information
latentvector committed Aug 19, 2024
1 parent 9585b93 commit ec1fc19
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 10 deletions.
34 changes: 33 additions & 1 deletion commune/sandbox.py
Original file line number Diff line number Diff line change
@@ -1 +1,33 @@
import commune as c
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.asymmetric import dh
from cryptography.hazmat.primitives.kdf.hkdf import HKDF
print('FAM')

# Generate some parameters. These can be reused.
parameters = dh.generate_parameters(generator=2, key_size=2048)
# Generate a private key for use in the exchange.
server_private_key = parameters.generate_private_key()
# In a real handshake the peer is a remote client. For this
# example we'll generate another local private key though. Note that in
# a DH handshake both peers must agree on a common set of parameters.
peer_private_key = parameters.generate_private_key()
shared_key = server_private_key.exchange(peer_private_key.public_key())
# Perform key derivation.
derived_key = HKDF(
algorithm=hashes.SHA256(),
length=32,
salt=None,
info=b'handshake data',
).derive(shared_key)
# And now we can demonstrate that the handshake performed in the
# opposite direction gives the same final value
same_shared_key = peer_private_key.exchange(
server_private_key.public_key()
)
same_derived_key = HKDF(
algorithm=hashes.SHA256(),
length=32,
salt=None,
info=b'handshake data',
).derive(same_shared_key)
derived_key == same_derived_key
19 changes: 10 additions & 9 deletions commune/vali/vali.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,12 @@ def __init__(self,
network= 'local', # for local subspace:test or test # for testnet subspace:main or main # for mainnet
netuid = 0, # (NOT LOCAL) the subnetwork uid or the netuid. This is a unique identifier for the subnetwork
search= None, # (OPTIONAL) the search string for the network
max_network_staleness= 10, # the maximum staleness of the network
# LOGGING
verbose= True, # the verbose mode for the worker
# EPOCH
max_network_staleness= 10, # the maximum staleness of the network # LOGGING
verbose= True, # the verbose mode for the worker # EPOCH
batch_size= 64,
queue_size= 128,
max_workers= None ,
score_fn = None,
#EVAL
score_fn = None, #EVAL
path= None, # the storage path for the module eval, if not null then the module eval is stored in this directory
alpha= 1.0, # alpha for score
timeout= 10, # timeout per evaluation of the module
Expand All @@ -36,7 +33,6 @@ def __init__(self,
timeout_info= 4, # (OPTIONAL) the timeout for the info worker
miner= False , # converts from a validator to a miner
max_history= 10, # the maximum history of the module (save last n interactions)

update=False,
**kwargs):
max_workers = max_workers or batch_size
Expand All @@ -49,14 +45,15 @@ def __init__(self,
# start the run loop
if self.config.run_loop:
c.thread(self.run_loop)

init_vali = __init__

def score(self, module):
a = 1
b = 2
c = a + b
return int(module.forward(a, b) == c)
return 1 - int(module.forward(a, b) - c)


def set_score_fn(self, score_fn: Union[Callable, str]):
"""
Set the score function for the validator
Expand Down Expand Up @@ -181,6 +178,10 @@ def run_epoch(cls, network='local', vali=None, run_loop=False, update=1, **kwarg
return self.epoch(df=1)

def epoch(self, df=True):
"""
The following runs an epoch for the validator
"""
if self.state.epochs > 0:
self.sync()
self.state.epochs += 1
Expand Down

0 comments on commit ec1fc19

Please sign in to comment.