Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions template/base/neuron.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ def __init__(self, config=None):
)
self.step = 0

self._last_updated_block = self.metagraph.last_update[self.uid]

@abstractmethod
async def forward(self, synapse: bt.Synapse) -> bt.Synapse:
...
Expand All @@ -125,9 +127,11 @@ def sync(self):

if self.should_sync_metagraph():
self.resync_metagraph()
self._last_updated_block = self.block

if self.should_set_weights():
self.set_weights()
self._last_updated_block = self.block

# Always save state.
self.save_state()
Expand All @@ -148,9 +152,10 @@ def should_sync_metagraph(self):
"""
Check if enough epoch blocks have elapsed since the last checkpoint to sync.
"""
return (
self.block - self.metagraph.last_update[self.uid]
) > self.config.neuron.epoch_length
elapsed = self.block - self._last_updated_block

# Only set weights if epoch has passed
return elapsed > self.config.neuron.epoch_length

def should_set_weights(self) -> bool:
# Don't set weights on initialization.
Expand All @@ -161,12 +166,10 @@ def should_set_weights(self) -> bool:
if self.config.neuron.disable_set_weights:
return False

# Define appropriate logic for when set weights.
return (
(self.block - self.metagraph.last_update[self.uid])
> self.config.neuron.epoch_length
and self.neuron_type != "MinerNeuron"
) # don't set weights if you're a miner
elapsed = self.block - self._last_updated_block

# Only set weights if epoch has passed and this isn't a MinerNeuron.
return elapsed > self.config.neuron.epoch_length and self.neuron_type != "MinerNeuron"

def save_state(self):
bt.logging.trace(
Expand Down