Skip to content

adds response return data #149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions openvalidators/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
class EventSchema:
completions: List[str] # List of completions received for a given prompt
completion_times: List[float] # List of completion times for a given prompt
completion_return_messages: List[str] # List of completion return messages for a given prompt
completion_return_codes: List[str] # List of completion return codes for a given prompt
name: str # Prompt type, e.g. 'followup', 'answer'
block: float # Current block at given step
gating_loss: float # Gating model loss for given step
Expand Down Expand Up @@ -95,6 +97,8 @@ def from_dict(event_dict: dict, disable_log_rewards: bool) -> 'EventSchema':
return EventSchema(
completions=event_dict['completions'],
completion_times=event_dict['completion_times'],
completion_return_messages=event_dict['completion_return_messages'],
completion_return_codes=event_dict['completion_return_codes'],
name=event_dict['name'],
block=event_dict['block'],
gating_loss=event_dict['gating_loss'],
Expand Down
8 changes: 6 additions & 2 deletions openvalidators/forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ async def run_step(self, prompt: str, k: int, timeout: float, name: str, exclude

# Get completion times
completion_times: List[float] = [comp.elapsed_time for comp in responses]
completion_return_messages: List[str] = [str(comp.return_message) for comp in responses]
completion_return_codes: List[str] = [str(comp.return_code) for comp in responses]

# Compute forward pass rewards, assumes followup_uids and answer_uids are mutually exclusive.
# shape: [ metagraph.n ]
Expand All @@ -133,6 +135,8 @@ async def run_step(self, prompt: str, k: int, timeout: float, name: str, exclude
"uids": uids.tolist(),
"completions": completions,
"completion_times": completion_times,
"completion_return_messages": completion_return_messages,
"completion_return_codes": completion_return_codes,
"rewards": rewards.tolist(),
"gating_loss": gating_loss.item(),
"best": best,
Expand All @@ -142,9 +146,9 @@ async def run_step(self, prompt: str, k: int, timeout: float, name: str, exclude
if not self.config.neuron.dont_save_events:
logger.log("EVENTS", "events", **event)

# Log the event to wandb.
wandb_event = EventSchema.from_dict(event, self.config.neuron.disable_log_rewards)
# Log the event to wandb.
if not self.config.wandb.off:
wandb_event = EventSchema.from_dict(event, self.config.neuron.disable_log_rewards)
self.wandb.log(asdict(wandb_event))

# Return the event.
Expand Down
2 changes: 2 additions & 0 deletions openvalidators/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ def reward(

class MockDendriteResponse:
completion = ""
return_message = "Success"
return_code = "1"
elapsed_time = 0
is_success = True
firewall_prompt = FirewallPrompt()
Expand Down
3 changes: 2 additions & 1 deletion openvalidators/neuron.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,9 @@ def __init__(self):
if self.config.neuron.mock_reward_models:
self.reward_functions = []
self.reward_weights = []
self.blacklist = MockRewardModel(RewardModelType.blacklist.value)
self.masking_functions = [
MockRewardModel(RewardModelType.blacklist.value),
self.blacklist,
MockRewardModel(RewardModelType.nsfw.value),
]
bt.logging.debug(str(self.reward_functions))
Expand Down
3 changes: 3 additions & 0 deletions openvalidators/reward/reward.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,8 @@ def __init__(self, mock_name: str = 'MockReward'):
def apply( self, prompt: str, completion: List[str], name: str ) -> torch.FloatTensor:
mock_reward = torch.tensor( [0 for _ in completion], dtype=torch.float32 )
return mock_reward, mock_reward

def reset(self):
pass


2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
bittensor>=5.2.1,<6.0.0
transformers==4.28.0
wandb==0.15.3
wandb==0.15.10
datasets==2.14.0
plotly==5.14.1
networkx==3.1
Expand Down
10 changes: 8 additions & 2 deletions tests/test_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ def test_event_from_dict_all_forward_columns_match(self):
event_dict = {
'completions': ['test'],
'completion_times': [0.123],
'completion_return_messages': ['Success'],
'completion_return_codes': ['1'],
'name': 'test-name',
'block': 1.0,
'gating_loss': 1.0,
Expand Down Expand Up @@ -85,7 +87,9 @@ def test_event_from_dict_forward_no_reward_logging(self):
# Assert: create a dictionary with all non-related reward columns
event_dict = {
'completions': ['test'],
'completion_times': [0.123],
'completion_times': [0.123],
'completion_return_messages': ['Success'],
'completion_return_codes': ['1'],
'name': 'test-name',
'block': 1.0,
'gating_loss': 1.0,
Expand Down Expand Up @@ -134,7 +138,9 @@ def test_event_from_dict_forward_reward_logging_mismatch(self):
# Assert: create a dictionary with all non-related reward columns
event_dict = {
'completions': ['test'],
'completion_times': [0.123],
'completion_times': [0.123],
'completion_return_messages': ['Success'],
'completion_return_codes': ['1'],
'name': 'test-name',
'block': 1.0,
'gating_loss': 1.0,
Expand Down