From 5d89528f97ebc929495a6a5f4e48b08ba7361cc1 Mon Sep 17 00:00:00 2001 From: opentaco Date: Thu, 17 Nov 2022 13:05:20 +0200 Subject: [PATCH 01/21] Add response table to validator debugging --- .../_neuron/text/core_validator/__init__.py | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/bittensor/_neuron/text/core_validator/__init__.py b/bittensor/_neuron/text/core_validator/__init__.py index efef464611..4b3acb0eb2 100644 --- a/bittensor/_neuron/text/core_validator/__init__.py +++ b/bittensor/_neuron/text/core_validator/__init__.py @@ -1178,6 +1178,7 @@ def textcausallmnext(uids: torch.Tensor, query_responses: List[List[torch.FloatT Statistics per endpoint for this batch. """ + batch_size = inputs.shape[0] inputs_nxt = inputs[..., -validation_len:] # input validation with next token target phrase [batch_size, val_len] def _base_params(_stats, query_response): @@ -1232,6 +1233,10 @@ def _synergy(first, second, target, ext): logger.info(f'{str(synapse)} \t| Shapley synergy values [{time.time() - synergy_start_time:.3g}s]') if logging: + batch_item, predictions = response_predictions(uids, query_responses, batch_size, index_s) + response_table(predictions, inputs[batch_item], validation_len, stats, + sort_col='shapley_values_nxt', console_width=console_width, index_s=index_s) + # === Synergy table === # Prints the synergy loss diff matrix with pairwise loss reduction due to synergy (original loss on diagonal) synergy_table(stats, syn_loss_diff, 'shapley_values_nxt', console_width) @@ -1392,6 +1397,83 @@ def shapley_synergy(stats: Dict, synergy: Callable, ext: str, target: torch.Tens return syn_loss_diff +def response_predictions(uids: torch.Tensor, query_responses: List[List[torch.FloatTensor]], + return_ops: List[torch.LongTensor], batch_size: int, + index_s: int = 0, number_of_predictions: int = 10, batch_item: int = None): + + if batch_item is None: + batch_item = random.randint(0, batch_size - 1) + + std_tokenizer = bittensor.tokenizer() + predictions = {} + for index, uid in enumerate(uids.tolist()): + if return_ops[index][index_s] == bittensor.proto.ReturnCode.Success: + topk_tensor = query_responses[index][index_s] + """topk_tensor (:obj:`torch.Tensor`, `required`): + [batch_size, (topk + 1), max_len] tensor includes topk token probabilities (prob_k) + floor_prob + in first column with gradients attached, with std_tokens in remaining columns with ignore_index padding. + Content structure: + [[[prob_k=0_b=0, tok_0_k=0_b=0, tok_1_k=0_b=0, ..., ignore_index?], + [prob_k=1_b=0, tok_0_k=1_b=0, tok_1_k=1_b=0, ..., ignore_index?], + [...], + [prob_floor_b=0, ignore_index, ..., ignore_index]], + [[prob_k=0_b=1, tok_0_k=0_b=1, tok_1_k=0_b=1, ..., ignore_index?], + [prob_k=1_b=1, tok_0_k=1_b=1, tok_1_k=1_b=1, ..., ignore_index?], + [...], + [prob_floor_b=1, ignore_index, ..., ignore_index]], + [...]] + """ + topk_tokens = topk_tensor[batch_item, :-1, 1:].int() # [batch_size, topk, max_len - 1] Phrase tokens with ignore_index token for padding. + topk_probs = topk_tensor[batch_item, :-1, 0] # [batch_size, topk] Probabilities for each phrase in topk + + preds = {} + for i in range(number_of_predictions): + phrase = topk_tokens[i] + phrase = phrase[phrase >= 0] + preds[f'phrase{i}'] = repr(std_tokenizer.decode(phrase)) + preds[f'prob{i}'] = topk_probs[i] + + predictions[uid] = preds + + return batch_item, predictions + + +def response_table(predictions: Dict, inputs: torch.FloatTensor, validation_len: int, stats: Dict, + sort_col: str, console_width: int, index_s: int = 0, number_of_predictions: int = 10): + + # Query response table columns + # [Column_name, key_name, format_string, rich_style] # description + phrase_columns = sum([[['p', f'prob{i}', '{:.4f}', 'grey30'], # probability of top prediction + ['pred', f'phrase{i}', '{}', ''], # phrase string prediction + ] for i in range(number_of_predictions)], []) + columns = [column for column in neuron_stats_columns if column[1] in ['uid', 'loss_nxt', 'synergy_nxt']] + + sort = sorted([(uid, s[sort_col]) for uid, s in stats.items() if sort_col in s], + reverse=True, key=lambda _row: _row[1]) + + rows = [] + for uid, val in sort: + row = [txt.format(stats[uid][key]) for _, key, txt, _ in columns] + row += [txt.format(predictions[uid][key]) for _, key, txt, _ in phrase_columns] + rows += [row] + + # === Response table === + table = Table(width=console_width, box=None) + table.title = f'[white] [bold]context[/bold]prediction [/white] ' \ + f'[bold]{repr(inputs[-validation_len-8:-validation_len])}[/bold]' \ + f'{repr(inputs[-validation_len:])}' + table.caption = f'[bold]{repr(inputs[-validation_len-28:-validation_len])}[/bold]{repr(inputs[-validation_len:])}' + + for col, _, _, stl in columns + phrase_columns: # [Column_name, key_name, format_string, rich_style] + table.add_column(col, style=stl, justify='right') + for row in rows: + table.add_row(*row) + + if len(rows): + print(table) + print() + + def synergy_table(stats, syn_loss_diff, sort_col, console_width): r""" Prints the synergy loss diff matrix with pairwise loss reduction due to synergy (original loss on diagonal) """ From a559d977458afb60e8fc0bd52459069a4b8a8f77 Mon Sep 17 00:00:00 2001 From: opentaco Date: Thu, 17 Nov 2022 13:17:48 +0200 Subject: [PATCH 02/21] Add return_ops to parameters --- bittensor/_neuron/text/core_validator/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bittensor/_neuron/text/core_validator/__init__.py b/bittensor/_neuron/text/core_validator/__init__.py index 4b3acb0eb2..c286400938 100644 --- a/bittensor/_neuron/text/core_validator/__init__.py +++ b/bittensor/_neuron/text/core_validator/__init__.py @@ -1233,7 +1233,7 @@ def _synergy(first, second, target, ext): logger.info(f'{str(synapse)} \t| Shapley synergy values [{time.time() - synergy_start_time:.3g}s]') if logging: - batch_item, predictions = response_predictions(uids, query_responses, batch_size, index_s) + batch_item, predictions = response_predictions(uids, query_responses, return_ops, batch_size, index_s) response_table(predictions, inputs[batch_item], validation_len, stats, sort_col='shapley_values_nxt', console_width=console_width, index_s=index_s) From a4b2054eba2fd26e10a9bfb3dbe5dbbcf9397e4a Mon Sep 17 00:00:00 2001 From: opentaco Date: Thu, 17 Nov 2022 13:34:45 +0200 Subject: [PATCH 03/21] Decode context and answer --- .../_neuron/text/core_validator/__init__.py | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/bittensor/_neuron/text/core_validator/__init__.py b/bittensor/_neuron/text/core_validator/__init__.py index c286400938..6a7e7435e2 100644 --- a/bittensor/_neuron/text/core_validator/__init__.py +++ b/bittensor/_neuron/text/core_validator/__init__.py @@ -1233,8 +1233,8 @@ def _synergy(first, second, target, ext): logger.info(f'{str(synapse)} \t| Shapley synergy values [{time.time() - synergy_start_time:.3g}s]') if logging: - batch_item, predictions = response_predictions(uids, query_responses, return_ops, batch_size, index_s) - response_table(predictions, inputs[batch_item], validation_len, stats, + context, answer, predictions = response_predictions(uids, query_responses, return_ops, inputs, batch_size, index_s) + response_table(predictions, context, answer, stats, sort_col='shapley_values_nxt', console_width=console_width, index_s=index_s) # === Synergy table === @@ -1398,13 +1398,17 @@ def shapley_synergy(stats: Dict, synergy: Callable, ext: str, target: torch.Tens def response_predictions(uids: torch.Tensor, query_responses: List[List[torch.FloatTensor]], - return_ops: List[torch.LongTensor], batch_size: int, + return_ops: List[torch.LongTensor], inputs: torch.FloatTensor, + validation_len: int, batch_size: int, index_s: int = 0, number_of_predictions: int = 10, batch_item: int = None): if batch_item is None: batch_item = random.randint(0, batch_size - 1) std_tokenizer = bittensor.tokenizer() + context = std_tokenizer.decode(inputs[batch_item][:-validation_len]) + answer = std_tokenizer.decode(inputs[batch_item][-validation_len:]) + predictions = {} for index, uid in enumerate(uids.tolist()): if return_ops[index][index_s] == bittensor.proto.ReturnCode.Success: @@ -1435,10 +1439,10 @@ def response_predictions(uids: torch.Tensor, query_responses: List[List[torch.Fl predictions[uid] = preds - return batch_item, predictions + return context, answer, predictions -def response_table(predictions: Dict, inputs: torch.FloatTensor, validation_len: int, stats: Dict, +def response_table(predictions: Dict, context: str, answer: str, stats: Dict, sort_col: str, console_width: int, index_s: int = 0, number_of_predictions: int = 10): # Query response table columns @@ -1453,6 +1457,7 @@ def response_table(predictions: Dict, inputs: torch.FloatTensor, validation_len: rows = [] for uid, val in sort: + print(uid, predictions[uid]) row = [txt.format(stats[uid][key]) for _, key, txt, _ in columns] row += [txt.format(predictions[uid][key]) for _, key, txt, _ in phrase_columns] rows += [row] @@ -1460,9 +1465,9 @@ def response_table(predictions: Dict, inputs: torch.FloatTensor, validation_len: # === Response table === table = Table(width=console_width, box=None) table.title = f'[white] [bold]context[/bold]prediction [/white] ' \ - f'[bold]{repr(inputs[-validation_len-8:-validation_len])}[/bold]' \ - f'{repr(inputs[-validation_len:])}' - table.caption = f'[bold]{repr(inputs[-validation_len-28:-validation_len])}[/bold]{repr(inputs[-validation_len:])}' + f'[bold]{repr(context[-15:])}[/bold]' \ + f'{repr(answer)}' + table.caption = f'[bold]{repr(context[-25:])}[/bold]{repr(answer)}' for col, _, _, stl in columns + phrase_columns: # [Column_name, key_name, format_string, rich_style] table.add_column(col, style=stl, justify='right') From edbdd684df7e6a05cc6918b49cecc8b3d6258026 Mon Sep 17 00:00:00 2001 From: opentaco Date: Thu, 17 Nov 2022 13:43:58 +0200 Subject: [PATCH 04/21] Add validation length parameter --- bittensor/_neuron/text/core_validator/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bittensor/_neuron/text/core_validator/__init__.py b/bittensor/_neuron/text/core_validator/__init__.py index 6a7e7435e2..7e0304c563 100644 --- a/bittensor/_neuron/text/core_validator/__init__.py +++ b/bittensor/_neuron/text/core_validator/__init__.py @@ -1233,7 +1233,8 @@ def _synergy(first, second, target, ext): logger.info(f'{str(synapse)} \t| Shapley synergy values [{time.time() - synergy_start_time:.3g}s]') if logging: - context, answer, predictions = response_predictions(uids, query_responses, return_ops, inputs, batch_size, index_s) + context, answer, predictions = response_predictions(uids, query_responses, return_ops, + inputs, validation_len, batch_size, index_s) response_table(predictions, context, answer, stats, sort_col='shapley_values_nxt', console_width=console_width, index_s=index_s) From 6b6419ba6f7652f99b7837e0b1acc4e8550a9ade Mon Sep 17 00:00:00 2001 From: opentaco Date: Thu, 17 Nov 2022 13:52:50 +0200 Subject: [PATCH 05/21] Itemize probabilities --- bittensor/_neuron/text/core_validator/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bittensor/_neuron/text/core_validator/__init__.py b/bittensor/_neuron/text/core_validator/__init__.py index 7e0304c563..e7a60e1f67 100644 --- a/bittensor/_neuron/text/core_validator/__init__.py +++ b/bittensor/_neuron/text/core_validator/__init__.py @@ -1436,7 +1436,7 @@ def response_predictions(uids: torch.Tensor, query_responses: List[List[torch.Fl phrase = topk_tokens[i] phrase = phrase[phrase >= 0] preds[f'phrase{i}'] = repr(std_tokenizer.decode(phrase)) - preds[f'prob{i}'] = topk_probs[i] + preds[f'prob{i}'] = topk_probs[i].item() predictions[uid] = preds From 1f9c3305f2a2ea6f75abe2cb5ef9a613643f9e41 Mon Sep 17 00:00:00 2001 From: opentaco Date: Thu, 17 Nov 2022 14:00:41 +0200 Subject: [PATCH 06/21] Add debug prints --- bittensor/_neuron/text/core_validator/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bittensor/_neuron/text/core_validator/__init__.py b/bittensor/_neuron/text/core_validator/__init__.py index e7a60e1f67..7fd43fc8fb 100644 --- a/bittensor/_neuron/text/core_validator/__init__.py +++ b/bittensor/_neuron/text/core_validator/__init__.py @@ -1452,7 +1452,7 @@ def response_table(predictions: Dict, context: str, answer: str, stats: Dict, ['pred', f'phrase{i}', '{}', ''], # phrase string prediction ] for i in range(number_of_predictions)], []) columns = [column for column in neuron_stats_columns if column[1] in ['uid', 'loss_nxt', 'synergy_nxt']] - + print('phrase_columns', phrase_columns) sort = sorted([(uid, s[sort_col]) for uid, s in stats.items() if sort_col in s], reverse=True, key=lambda _row: _row[1]) @@ -1461,6 +1461,7 @@ def response_table(predictions: Dict, context: str, answer: str, stats: Dict, print(uid, predictions[uid]) row = [txt.format(stats[uid][key]) for _, key, txt, _ in columns] row += [txt.format(predictions[uid][key]) for _, key, txt, _ in phrase_columns] + print(row) rows += [row] # === Response table === From b7611fe9cc25e73b3a1f28669f4a763334831815 Mon Sep 17 00:00:00 2001 From: opentaco Date: Thu, 17 Nov 2022 14:09:14 +0200 Subject: [PATCH 07/21] Change table formatting --- bittensor/_neuron/text/core_validator/__init__.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/bittensor/_neuron/text/core_validator/__init__.py b/bittensor/_neuron/text/core_validator/__init__.py index 7fd43fc8fb..8eb55e9331 100644 --- a/bittensor/_neuron/text/core_validator/__init__.py +++ b/bittensor/_neuron/text/core_validator/__init__.py @@ -1448,20 +1448,18 @@ def response_table(predictions: Dict, context: str, answer: str, stats: Dict, # Query response table columns # [Column_name, key_name, format_string, rich_style] # description - phrase_columns = sum([[['p', f'prob{i}', '{:.4f}', 'grey30'], # probability of top prediction + phrase_columns = sum([[['p', f'prob{i}', '{:.4f}', 'magenta'], # probability of top prediction ['pred', f'phrase{i}', '{}', ''], # phrase string prediction ] for i in range(number_of_predictions)], []) columns = [column for column in neuron_stats_columns if column[1] in ['uid', 'loss_nxt', 'synergy_nxt']] - print('phrase_columns', phrase_columns) + sort = sorted([(uid, s[sort_col]) for uid, s in stats.items() if sort_col in s], reverse=True, key=lambda _row: _row[1]) rows = [] for uid, val in sort: - print(uid, predictions[uid]) row = [txt.format(stats[uid][key]) for _, key, txt, _ in columns] row += [txt.format(predictions[uid][key]) for _, key, txt, _ in phrase_columns] - print(row) rows += [row] # === Response table === From ef5f3696af913edeb9ee53efdf415313069a7c9e Mon Sep 17 00:00:00 2001 From: opentaco Date: Thu, 17 Nov 2022 18:36:11 +0200 Subject: [PATCH 08/21] Add extra tasks to response table --- .../_neuron/text/core_validator/__init__.py | 131 ++++++++---------- 1 file changed, 61 insertions(+), 70 deletions(-) diff --git a/bittensor/_neuron/text/core_validator/__init__.py b/bittensor/_neuron/text/core_validator/__init__.py index 8eb55e9331..5480e5efda 100644 --- a/bittensor/_neuron/text/core_validator/__init__.py +++ b/bittensor/_neuron/text/core_validator/__init__.py @@ -1233,10 +1233,9 @@ def _synergy(first, second, target, ext): logger.info(f'{str(synapse)} \t| Shapley synergy values [{time.time() - synergy_start_time:.3g}s]') if logging: - context, answer, predictions = response_predictions(uids, query_responses, return_ops, - inputs, validation_len, batch_size, index_s) - response_table(predictions, context, answer, stats, - sort_col='shapley_values_nxt', console_width=console_width, index_s=index_s) + batch_predictions = format_predictions(uids, query_responses, return_ops, + inputs, validation_len, batch_size, index_s) + response_table(batch_predictions, stats, sort_col='shapley_values_nxt', console_width=console_width) # === Synergy table === # Prints the synergy loss diff matrix with pairwise loss reduction due to synergy (original loss on diagonal) @@ -1398,85 +1397,77 @@ def shapley_synergy(stats: Dict, synergy: Callable, ext: str, target: torch.Tens return syn_loss_diff -def response_predictions(uids: torch.Tensor, query_responses: List[List[torch.FloatTensor]], - return_ops: List[torch.LongTensor], inputs: torch.FloatTensor, - validation_len: int, batch_size: int, - index_s: int = 0, number_of_predictions: int = 10, batch_item: int = None): - - if batch_item is None: - batch_item = random.randint(0, batch_size - 1) +def format_predictions(uids: torch.Tensor, query_responses: List[List[torch.FloatTensor]], + return_ops: List[torch.LongTensor], inputs: torch.FloatTensor, + validation_len: int, index_s: int = 0, number_of_predictions: int = 3): + batch_size = inputs.shape[0] + batch_predictions = [] std_tokenizer = bittensor.tokenizer() - context = std_tokenizer.decode(inputs[batch_item][:-validation_len]) - answer = std_tokenizer.decode(inputs[batch_item][-validation_len:]) - predictions = {} - for index, uid in enumerate(uids.tolist()): - if return_ops[index][index_s] == bittensor.proto.ReturnCode.Success: - topk_tensor = query_responses[index][index_s] - """topk_tensor (:obj:`torch.Tensor`, `required`): - [batch_size, (topk + 1), max_len] tensor includes topk token probabilities (prob_k) + floor_prob - in first column with gradients attached, with std_tokens in remaining columns with ignore_index padding. - Content structure: - [[[prob_k=0_b=0, tok_0_k=0_b=0, tok_1_k=0_b=0, ..., ignore_index?], - [prob_k=1_b=0, tok_0_k=1_b=0, tok_1_k=1_b=0, ..., ignore_index?], - [...], - [prob_floor_b=0, ignore_index, ..., ignore_index]], - [[prob_k=0_b=1, tok_0_k=0_b=1, tok_1_k=0_b=1, ..., ignore_index?], - [prob_k=1_b=1, tok_0_k=1_b=1, tok_1_k=1_b=1, ..., ignore_index?], - [...], - [prob_floor_b=1, ignore_index, ..., ignore_index]], - [...]] - """ - topk_tokens = topk_tensor[batch_item, :-1, 1:].int() # [batch_size, topk, max_len - 1] Phrase tokens with ignore_index token for padding. - topk_probs = topk_tensor[batch_item, :-1, 0] # [batch_size, topk] Probabilities for each phrase in topk - - preds = {} - for i in range(number_of_predictions): - phrase = topk_tokens[i] - phrase = phrase[phrase >= 0] - preds[f'phrase{i}'] = repr(std_tokenizer.decode(phrase)) - preds[f'prob{i}'] = topk_probs[i].item() - - predictions[uid] = preds - - return context, answer, predictions - - -def response_table(predictions: Dict, context: str, answer: str, stats: Dict, - sort_col: str, console_width: int, index_s: int = 0, number_of_predictions: int = 10): - - # Query response table columns - # [Column_name, key_name, format_string, rich_style] # description - phrase_columns = sum([[['p', f'prob{i}', '{:.4f}', 'magenta'], # probability of top prediction - ['pred', f'phrase{i}', '{}', ''], # phrase string prediction - ] for i in range(number_of_predictions)], []) + for batch_item in range(batch_size): + context = inputs[batch_item][:-validation_len] + answer = inputs[batch_item][-validation_len:] + + context = repr(std_tokenizer.decode(context))[1:-1][-30:] # strip '' and truncate + answer = repr(std_tokenizer.decode(answer))[1:-1][:15] # strip '' and truncate + + task = f"[bold]{context}[/bold]{answer}" + + predictions = {} + for index, uid in enumerate(uids.tolist()): + if return_ops[index][index_s] == bittensor.proto.ReturnCode.Success: + topk_tensor = query_responses[index][index_s] # [batch_size, (topk + 1), max_len] (prob_k) + floor_prob + topk_tokens = topk_tensor[batch_item, :-1, 1:].int() # [batch_size, topk, max_len - 1] Phrase tokens with ignore_index token for padding. + topk_probs = topk_tensor[batch_item, :-1, 0] # [batch_size, topk] Probabilities for each phrase in topk + + preds = '' + for i in range(number_of_predictions): + phrase = topk_tokens[i] + phrase = phrase[phrase >= 0] + phrase_str = repr(std_tokenizer.decode(phrase))[:15] # escape and truncate + preds += f"[[white]{topk_probs[i]:.3f}[/white]: {phrase_str} " + + predictions[uid] = preds[:-1] # strip trailing space + + batch_predictions += [(task, predictions)] + + return batch_predictions + + +def response_table(batch_predictions: List, stats: Dict, sort_col: str, console_width: int, + task_repeat: int = 4, tasks_per_server: int = 3): columns = [column for column in neuron_stats_columns if column[1] in ['uid', 'loss_nxt', 'synergy_nxt']] sort = sorted([(uid, s[sort_col]) for uid, s in stats.items() if sort_col in s], reverse=True, key=lambda _row: _row[1]) - rows = [] - for uid, val in sort: + batch_size = len(batch_predictions) + batch_perm = torch.randperm(batch_size) # avoid restricting observation to predictable subsets + + for i, (uid, val) in enumerate(sort): + if i % task_repeat == 0: + # === Response table === + table = Table(width=console_width, box=None) + for col, _, _, stl in columns: # [Column_name, key_name, format_string, rich_style] + table.add_column(col, style=stl, justify='right') + row = [txt.format(stats[uid][key]) for _, key, txt, _ in columns] - row += [txt.format(predictions[uid][key]) for _, key, txt, _ in phrase_columns] - rows += [row] + for j in range(tasks_per_server): + batch_item = batch_size % ((i // task_repeat) * tasks_per_server + j) # do not exceed batch_size, repeat task over servers + task, predictions = batch_predictions[batch_perm[batch_item]] - # === Response table === - table = Table(width=console_width, box=None) - table.title = f'[white] [bold]context[/bold]prediction [/white] ' \ - f'[bold]{repr(context[-15:])}[/bold]' \ - f'{repr(answer)}' - table.caption = f'[bold]{repr(context[-25:])}[/bold]{repr(answer)}' + if i % task_repeat == 0: + table.add_column(task, style='', justify='left') + + row += [predictions[uid]] - for col, _, _, stl in columns + phrase_columns: # [Column_name, key_name, format_string, rich_style] - table.add_column(col, style=stl, justify='right') - for row in rows: table.add_row(*row) - if len(rows): - print(table) - print() + if i % task_repeat == task_repeat - 1: + print(table) + + print() def synergy_table(stats, syn_loss_diff, sort_col, console_width): From 4c279b35cb91ffeeec9119fe00b5a8c3076eb224 Mon Sep 17 00:00:00 2001 From: opentaco Date: Thu, 17 Nov 2022 18:54:21 +0200 Subject: [PATCH 09/21] Debug add print --- bittensor/_neuron/text/core_validator/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bittensor/_neuron/text/core_validator/__init__.py b/bittensor/_neuron/text/core_validator/__init__.py index 5480e5efda..e891c3ef0f 100644 --- a/bittensor/_neuron/text/core_validator/__init__.py +++ b/bittensor/_neuron/text/core_validator/__init__.py @@ -1416,6 +1416,7 @@ def format_predictions(uids: torch.Tensor, query_responses: List[List[torch.Floa predictions = {} for index, uid in enumerate(uids.tolist()): + print('uid', uid, 'index', index, 'index_s', index_s, len(return_ops), end='; ') if return_ops[index][index_s] == bittensor.proto.ReturnCode.Success: topk_tensor = query_responses[index][index_s] # [batch_size, (topk + 1), max_len] (prob_k) + floor_prob topk_tokens = topk_tensor[batch_item, :-1, 1:].int() # [batch_size, topk, max_len - 1] Phrase tokens with ignore_index token for padding. @@ -1429,7 +1430,7 @@ def format_predictions(uids: torch.Tensor, query_responses: List[List[torch.Floa preds += f"[[white]{topk_probs[i]:.3f}[/white]: {phrase_str} " predictions[uid] = preds[:-1] # strip trailing space - + print() batch_predictions += [(task, predictions)] return batch_predictions From 9ebebbeb34d0e34ef2c6a565e0624679530febbd Mon Sep 17 00:00:00 2001 From: opentaco Date: Thu, 17 Nov 2022 18:59:27 +0200 Subject: [PATCH 10/21] Remove batch_size parameter --- bittensor/_neuron/text/core_validator/__init__.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/bittensor/_neuron/text/core_validator/__init__.py b/bittensor/_neuron/text/core_validator/__init__.py index e891c3ef0f..74840f9d95 100644 --- a/bittensor/_neuron/text/core_validator/__init__.py +++ b/bittensor/_neuron/text/core_validator/__init__.py @@ -1178,7 +1178,6 @@ def textcausallmnext(uids: torch.Tensor, query_responses: List[List[torch.FloatT Statistics per endpoint for this batch. """ - batch_size = inputs.shape[0] inputs_nxt = inputs[..., -validation_len:] # input validation with next token target phrase [batch_size, val_len] def _base_params(_stats, query_response): @@ -1233,8 +1232,7 @@ def _synergy(first, second, target, ext): logger.info(f'{str(synapse)} \t| Shapley synergy values [{time.time() - synergy_start_time:.3g}s]') if logging: - batch_predictions = format_predictions(uids, query_responses, return_ops, - inputs, validation_len, batch_size, index_s) + batch_predictions = format_predictions(uids, query_responses, return_ops, inputs, validation_len, index_s) response_table(batch_predictions, stats, sort_col='shapley_values_nxt', console_width=console_width) # === Synergy table === @@ -1416,7 +1414,6 @@ def format_predictions(uids: torch.Tensor, query_responses: List[List[torch.Floa predictions = {} for index, uid in enumerate(uids.tolist()): - print('uid', uid, 'index', index, 'index_s', index_s, len(return_ops), end='; ') if return_ops[index][index_s] == bittensor.proto.ReturnCode.Success: topk_tensor = query_responses[index][index_s] # [batch_size, (topk + 1), max_len] (prob_k) + floor_prob topk_tokens = topk_tensor[batch_item, :-1, 1:].int() # [batch_size, topk, max_len - 1] Phrase tokens with ignore_index token for padding. @@ -1430,7 +1427,7 @@ def format_predictions(uids: torch.Tensor, query_responses: List[List[torch.Floa preds += f"[[white]{topk_probs[i]:.3f}[/white]: {phrase_str} " predictions[uid] = preds[:-1] # strip trailing space - print() + batch_predictions += [(task, predictions)] return batch_predictions From 98a1454382543318f4997509abec6afe82a11e5f Mon Sep 17 00:00:00 2001 From: opentaco Date: Thu, 17 Nov 2022 19:38:19 +0200 Subject: [PATCH 11/21] Switch modulo order --- bittensor/_neuron/text/core_validator/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bittensor/_neuron/text/core_validator/__init__.py b/bittensor/_neuron/text/core_validator/__init__.py index 74840f9d95..5377def50b 100644 --- a/bittensor/_neuron/text/core_validator/__init__.py +++ b/bittensor/_neuron/text/core_validator/__init__.py @@ -1452,7 +1452,7 @@ def response_table(batch_predictions: List, stats: Dict, sort_col: str, console_ row = [txt.format(stats[uid][key]) for _, key, txt, _ in columns] for j in range(tasks_per_server): - batch_item = batch_size % ((i // task_repeat) * tasks_per_server + j) # do not exceed batch_size, repeat task over servers + batch_item = ((i // task_repeat) * tasks_per_server + j) % batch_size # repeat task over servers, do not exceed batch_size task, predictions = batch_predictions[batch_perm[batch_item]] if i % task_repeat == 0: From a9e45ea8efe8088ec21345a08da2dc9781e017be Mon Sep 17 00:00:00 2001 From: opentaco Date: Thu, 17 Nov 2022 19:54:53 +0200 Subject: [PATCH 12/21] Modify table format --- bittensor/_neuron/text/core_validator/__init__.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/bittensor/_neuron/text/core_validator/__init__.py b/bittensor/_neuron/text/core_validator/__init__.py index 5377def50b..7ec5801153 100644 --- a/bittensor/_neuron/text/core_validator/__init__.py +++ b/bittensor/_neuron/text/core_validator/__init__.py @@ -1424,7 +1424,9 @@ def format_predictions(uids: torch.Tensor, query_responses: List[List[torch.Floa phrase = topk_tokens[i] phrase = phrase[phrase >= 0] phrase_str = repr(std_tokenizer.decode(phrase))[:15] # escape and truncate - preds += f"[[white]{topk_probs[i]:.3f}[/white]: {phrase_str} " + prob = f'{topk_probs[i]:.3f}' + prob = prob[1:] if prob[0] == '0' else prob + preds += f"[green]{prob}[/green]: {phrase_str} " predictions[uid] = preds[:-1] # strip trailing space @@ -1447,6 +1449,9 @@ def response_table(batch_predictions: List, stats: Dict, sort_col: str, console_ if i % task_repeat == 0: # === Response table === table = Table(width=console_width, box=None) + if i == 0: + table.title = f'[white] Response sample [/white]' + for col, _, _, stl in columns: # [Column_name, key_name, format_string, rich_style] table.add_column(col, style=stl, justify='right') @@ -1456,7 +1461,7 @@ def response_table(batch_predictions: List, stats: Dict, sort_col: str, console_ task, predictions = batch_predictions[batch_perm[batch_item]] if i % task_repeat == 0: - table.add_column(task, style='', justify='left') + table.add_column(task, header_style='not bold', style='', justify='left') row += [predictions[uid]] @@ -1465,6 +1470,9 @@ def response_table(batch_predictions: List, stats: Dict, sort_col: str, console_ if i % task_repeat == task_repeat - 1: print(table) + if (len(sort) - 1) % task_repeat != task_repeat - 1: + table.caption = f'[white]context[/white]prediction' + print(table) print() From ed472ceedf1f8a5077ac83ddae46a6210ab88407 Mon Sep 17 00:00:00 2001 From: opentaco Date: Thu, 17 Nov 2022 20:05:20 +0200 Subject: [PATCH 13/21] Modify table format --- bittensor/_neuron/text/core_validator/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bittensor/_neuron/text/core_validator/__init__.py b/bittensor/_neuron/text/core_validator/__init__.py index 7ec5801153..816396d6e7 100644 --- a/bittensor/_neuron/text/core_validator/__init__.py +++ b/bittensor/_neuron/text/core_validator/__init__.py @@ -1410,7 +1410,7 @@ def format_predictions(uids: torch.Tensor, query_responses: List[List[torch.Floa context = repr(std_tokenizer.decode(context))[1:-1][-30:] # strip '' and truncate answer = repr(std_tokenizer.decode(answer))[1:-1][:15] # strip '' and truncate - task = f"[bold]{context}[/bold]{answer}" + task = f"[bold reverse]{context}[/bold reverse]{answer}" predictions = {} for index, uid in enumerate(uids.tolist()): From d55c98add835491d05e27cc2f26ca84778ff0890 Mon Sep 17 00:00:00 2001 From: opentaco Date: Thu, 17 Nov 2022 20:17:31 +0200 Subject: [PATCH 14/21] Modify table format --- bittensor/_neuron/text/core_validator/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bittensor/_neuron/text/core_validator/__init__.py b/bittensor/_neuron/text/core_validator/__init__.py index 816396d6e7..8759af4dcd 100644 --- a/bittensor/_neuron/text/core_validator/__init__.py +++ b/bittensor/_neuron/text/core_validator/__init__.py @@ -1410,7 +1410,7 @@ def format_predictions(uids: torch.Tensor, query_responses: List[List[torch.Floa context = repr(std_tokenizer.decode(context))[1:-1][-30:] # strip '' and truncate answer = repr(std_tokenizer.decode(answer))[1:-1][:15] # strip '' and truncate - task = f"[bold reverse]{context}[/bold reverse]{answer}" + task = f"[reverse]{context}[/reverse][bold]{answer}[/bold]" predictions = {} for index, uid in enumerate(uids.tolist()): @@ -1425,7 +1425,7 @@ def format_predictions(uids: torch.Tensor, query_responses: List[List[torch.Floa phrase = phrase[phrase >= 0] phrase_str = repr(std_tokenizer.decode(phrase))[:15] # escape and truncate prob = f'{topk_probs[i]:.3f}' - prob = prob[1:] if prob[0] == '0' else prob + prob = prob[1:] if prob[0] == '0' else prob[:-1] preds += f"[green]{prob}[/green]: {phrase_str} " predictions[uid] = preds[:-1] # strip trailing space @@ -1450,7 +1450,7 @@ def response_table(batch_predictions: List, stats: Dict, sort_col: str, console_ # === Response table === table = Table(width=console_width, box=None) if i == 0: - table.title = f'[white] Response sample [/white]' + table.title = f'[white] Query responses [/white]' for col, _, _, stl in columns: # [Column_name, key_name, format_string, rich_style] table.add_column(col, style=stl, justify='right') @@ -1471,7 +1471,7 @@ def response_table(batch_predictions: List, stats: Dict, sort_col: str, console_ print(table) if (len(sort) - 1) % task_repeat != task_repeat - 1: - table.caption = f'[white]context[/white]prediction' + table.caption = f'[white]context[/white][bold]prediction[/bold]' print(table) print() From 9d5688b24d79484dfa0c5da419818deccea949aa Mon Sep 17 00:00:00 2001 From: opentaco Date: Thu, 17 Nov 2022 20:32:24 +0200 Subject: [PATCH 15/21] Modify table format --- bittensor/_neuron/text/core_validator/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bittensor/_neuron/text/core_validator/__init__.py b/bittensor/_neuron/text/core_validator/__init__.py index 8759af4dcd..d50e71eb4b 100644 --- a/bittensor/_neuron/text/core_validator/__init__.py +++ b/bittensor/_neuron/text/core_validator/__init__.py @@ -1468,6 +1468,8 @@ def response_table(batch_predictions: List, stats: Dict, sort_col: str, console_ table.add_row(*row) if i % task_repeat == task_repeat - 1: + if i == len(sort) - 1: + table.caption = f'[white]context[/white][bold]prediction[/bold]' print(table) if (len(sort) - 1) % task_repeat != task_repeat - 1: From e65a4e9ae838d4dcee3a7e82442527f80b69a645 Mon Sep 17 00:00:00 2001 From: opentaco Date: Fri, 18 Nov 2022 10:46:04 +0200 Subject: [PATCH 16/21] Try table print to catch rich errors --- .../_neuron/text/core_validator/__init__.py | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/bittensor/_neuron/text/core_validator/__init__.py b/bittensor/_neuron/text/core_validator/__init__.py index d50e71eb4b..c5dc14ee7f 100644 --- a/bittensor/_neuron/text/core_validator/__init__.py +++ b/bittensor/_neuron/text/core_validator/__init__.py @@ -1437,14 +1437,16 @@ def format_predictions(uids: torch.Tensor, query_responses: List[List[torch.Floa def response_table(batch_predictions: List, stats: Dict, sort_col: str, console_width: int, task_repeat: int = 4, tasks_per_server: int = 3): + batch_size = len(batch_predictions) + if batch_size == 0: + return + batch_perm = torch.randperm(batch_size) # avoid restricting observation to predictable subsets + columns = [column for column in neuron_stats_columns if column[1] in ['uid', 'loss_nxt', 'synergy_nxt']] sort = sorted([(uid, s[sort_col]) for uid, s in stats.items() if sort_col in s], reverse=True, key=lambda _row: _row[1]) - batch_size = len(batch_predictions) - batch_perm = torch.randperm(batch_size) # avoid restricting observation to predictable subsets - for i, (uid, val) in enumerate(sort): if i % task_repeat == 0: # === Response table === @@ -1455,6 +1457,9 @@ def response_table(batch_predictions: List, stats: Dict, sort_col: str, console_ for col, _, _, stl in columns: # [Column_name, key_name, format_string, rich_style] table.add_column(col, style=stl, justify='right') + if i == len(sort) - 1: + table.caption = f'[white]context[/white][bold]prediction[/bold]' + row = [txt.format(stats[uid][key]) for _, key, txt, _ in columns] for j in range(tasks_per_server): batch_item = ((i // task_repeat) * tasks_per_server + j) % batch_size # repeat task over servers, do not exceed batch_size @@ -1467,15 +1472,14 @@ def response_table(batch_predictions: List, stats: Dict, sort_col: str, console_ table.add_row(*row) - if i % task_repeat == task_repeat - 1: - if i == len(sort) - 1: - table.caption = f'[white]context[/white][bold]prediction[/bold]' - print(table) - - if (len(sort) - 1) % task_repeat != task_repeat - 1: - table.caption = f'[white]context[/white][bold]prediction[/bold]' - print(table) - print() + if (i == len(sort) - 1) or (i % task_repeat == task_repeat - 1): + try: + print(table) + except Exception as e: + print(e) + else: + if i == len(sort) - 1: + print() def synergy_table(stats, syn_loss_diff, sort_col, console_width): From 62d2404c13d7bb16e144861cf677bd85b5409147 Mon Sep 17 00:00:00 2001 From: opentaco Date: Fri, 18 Nov 2022 11:16:01 +0200 Subject: [PATCH 17/21] Modify table title and caption --- bittensor/_neuron/text/core_validator/__init__.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/bittensor/_neuron/text/core_validator/__init__.py b/bittensor/_neuron/text/core_validator/__init__.py index c5dc14ee7f..47ff7e9e13 100644 --- a/bittensor/_neuron/text/core_validator/__init__.py +++ b/bittensor/_neuron/text/core_validator/__init__.py @@ -1232,6 +1232,8 @@ def _synergy(first, second, target, ext): logger.info(f'{str(synapse)} \t| Shapley synergy values [{time.time() - synergy_start_time:.3g}s]') if logging: + # === Response table === + # Prints the query response table: top prediction probabilities and texts for batch items batch_predictions = format_predictions(uids, query_responses, return_ops, inputs, validation_len, index_s) response_table(batch_predictions, stats, sort_col='shapley_values_nxt', console_width=console_width) @@ -1443,7 +1445,6 @@ def response_table(batch_predictions: List, stats: Dict, sort_col: str, console_ batch_perm = torch.randperm(batch_size) # avoid restricting observation to predictable subsets columns = [column for column in neuron_stats_columns if column[1] in ['uid', 'loss_nxt', 'synergy_nxt']] - sort = sorted([(uid, s[sort_col]) for uid, s in stats.items() if sort_col in s], reverse=True, key=lambda _row: _row[1]) @@ -1452,24 +1453,26 @@ def response_table(batch_predictions: List, stats: Dict, sort_col: str, console_ # === Response table === table = Table(width=console_width, box=None) if i == 0: - table.title = f'[white] Query responses [/white]' + table.title = f"[white bold] Query responses [/white bold] | " \ + f"[white]context[/white][bold]continuation[/bold] | " \ + f".prob: 'prediction'" for col, _, _, stl in columns: # [Column_name, key_name, format_string, rich_style] table.add_column(col, style=stl, justify='right') if i == len(sort) - 1: - table.caption = f'[white]context[/white][bold]prediction[/bold]' + table.caption = f'[bold]{len([s for s in stats.values() if len(s)])}[/bold]/{len(stats)} (respond/topk) | ' \ + f'{tasks_per_server} tasks per server | repeat tasks over {task_repeat} servers' row = [txt.format(stats[uid][key]) for _, key, txt, _ in columns] for j in range(tasks_per_server): batch_item = ((i // task_repeat) * tasks_per_server + j) % batch_size # repeat task over servers, do not exceed batch_size task, predictions = batch_predictions[batch_perm[batch_item]] + row += [predictions[uid]] if i % task_repeat == 0: table.add_column(task, header_style='not bold', style='', justify='left') - row += [predictions[uid]] - table.add_row(*row) if (i == len(sort) - 1) or (i % task_repeat == task_repeat - 1): From 6f653858cfcdc07eba3b5956ea01b724ce7da35e Mon Sep 17 00:00:00 2001 From: opentaco Date: Fri, 18 Nov 2022 11:29:03 +0200 Subject: [PATCH 18/21] Add shapley_values_nxt column --- bittensor/_neuron/text/core_validator/__init__.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bittensor/_neuron/text/core_validator/__init__.py b/bittensor/_neuron/text/core_validator/__init__.py index 47ff7e9e13..ffe392f49c 100644 --- a/bittensor/_neuron/text/core_validator/__init__.py +++ b/bittensor/_neuron/text/core_validator/__init__.py @@ -1444,9 +1444,14 @@ def response_table(batch_predictions: List, stats: Dict, sort_col: str, console_ return batch_perm = torch.randperm(batch_size) # avoid restricting observation to predictable subsets - columns = [column for column in neuron_stats_columns if column[1] in ['uid', 'loss_nxt', 'synergy_nxt']] + columns = [c[:] for c in neuron_stats_columns if c[1] in ['uid', 'shapley_values_nxt', 'loss_nxt', 'synergy_nxt']] + # === Sort rows === sort = sorted([(uid, s[sort_col]) for uid, s in stats.items() if sort_col in s], reverse=True, key=lambda _row: _row[1]) + col_keys = [c[1] for c in columns] + if sort_col in col_keys: + sort_idx = col_keys.index(sort_col) # sort column with key of sort_col + columns[sort_idx][0] += '\u2193' # ↓ downwards arrow (sort) for i, (uid, val) in enumerate(sort): if i % task_repeat == 0: From b3f06f6a4878ea82450e4e90929f8314053c4012 Mon Sep 17 00:00:00 2001 From: opentaco Date: Fri, 18 Nov 2022 12:02:38 +0200 Subject: [PATCH 19/21] Refactor response table functions --- .../_neuron/text/core_validator/__init__.py | 54 ++++++++++++------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/bittensor/_neuron/text/core_validator/__init__.py b/bittensor/_neuron/text/core_validator/__init__.py index ffe392f49c..7f9e7401f0 100644 --- a/bittensor/_neuron/text/core_validator/__init__.py +++ b/bittensor/_neuron/text/core_validator/__init__.py @@ -36,6 +36,7 @@ from rich.console import Console from rich.style import Style from rich.table import Table +from rich.errors import MarkupError from rich.traceback import install from typing import List, Tuple, Callable, Dict, Any, Union, Set @@ -1233,7 +1234,7 @@ def _synergy(first, second, target, ext): if logging: # === Response table === - # Prints the query response table: top prediction probabilities and texts for batch items + # Prints the query response table: top prediction probabilities and texts for batch tasks batch_predictions = format_predictions(uids, query_responses, return_ops, inputs, validation_len, index_s) response_table(batch_predictions, stats, sort_col='shapley_values_nxt', console_width=console_width) @@ -1399,13 +1400,15 @@ def shapley_synergy(stats: Dict, synergy: Callable, ext: str, target: torch.Tens def format_predictions(uids: torch.Tensor, query_responses: List[List[torch.FloatTensor]], return_ops: List[torch.LongTensor], inputs: torch.FloatTensor, - validation_len: int, index_s: int = 0, number_of_predictions: int = 3): - - batch_size = inputs.shape[0] + validation_len: int, index_s: int = 0, number_of_predictions: int = 3) -> List: + r""" Format batch task topk predictions for rich table print of query responses. + """ batch_predictions = [] std_tokenizer = bittensor.tokenizer() - for batch_item in range(batch_size): + # === Batch iteration === + for batch_item in range(inputs.shape[0]): + # === Task formatting === context = inputs[batch_item][:-validation_len] answer = inputs[batch_item][-validation_len:] @@ -1414,6 +1417,7 @@ def format_predictions(uids: torch.Tensor, query_responses: List[List[torch.Floa task = f"[reverse]{context}[/reverse][bold]{answer}[/bold]" + # === Prediction formatting === predictions = {} for index, uid in enumerate(uids.tolist()): if return_ops[index][index_s] == bittensor.proto.ReturnCode.Success: @@ -1421,16 +1425,19 @@ def format_predictions(uids: torch.Tensor, query_responses: List[List[torch.Floa topk_tokens = topk_tensor[batch_item, :-1, 1:].int() # [batch_size, topk, max_len - 1] Phrase tokens with ignore_index token for padding. topk_probs = topk_tensor[batch_item, :-1, 0] # [batch_size, topk] Probabilities for each phrase in topk - preds = '' + # === Topk iteration === + topk_predictions = '' for i in range(number_of_predictions): phrase = topk_tokens[i] - phrase = phrase[phrase >= 0] - phrase_str = repr(std_tokenizer.decode(phrase))[:15] # escape and truncate + phrase = phrase[phrase >= 0] # strip negative ignore_index = -100 + phrase_str = repr(std_tokenizer.decode(phrase))[:15] # decode, escape and truncate + prob = f'{topk_probs[i]:.3f}' - prob = prob[1:] if prob[0] == '0' else prob[:-1] - preds += f"[green]{prob}[/green]: {phrase_str} " + prob = prob[1:] if prob[0] == '0' else prob[:-1] # remove obvious leading 0 - predictions[uid] = preds[:-1] # strip trailing space + topk_predictions += f"[green]{prob}[/green]: {phrase_str} " + + predictions[uid] = topk_predictions[:-1] # strip trailing space batch_predictions += [(task, predictions)] @@ -1439,36 +1446,42 @@ def format_predictions(uids: torch.Tensor, query_responses: List[List[torch.Floa def response_table(batch_predictions: List, stats: Dict, sort_col: str, console_width: int, task_repeat: int = 4, tasks_per_server: int = 3): + r""" Prints the query response table: top prediction probabilities and texts for batch tasks. + """ + # === Batch permutation === batch_size = len(batch_predictions) if batch_size == 0: return batch_perm = torch.randperm(batch_size) # avoid restricting observation to predictable subsets - columns = [c[:] for c in neuron_stats_columns if c[1] in ['uid', 'shapley_values_nxt', 'loss_nxt', 'synergy_nxt']] - # === Sort rows === - sort = sorted([(uid, s[sort_col]) for uid, s in stats.items() if sort_col in s], - reverse=True, key=lambda _row: _row[1]) + # === Column selection === + columns = [c[:] for c in neuron_stats_columns if c[1] in ['uid', sort_col, 'loss_nxt', 'synergy_nxt']] col_keys = [c[1] for c in columns] + + # === Sort rows === + sort = sorted([(uid, s[sort_col]) for uid, s in stats.items() if sort_col in s], reverse=True, key=lambda _row: _row[1]) if sort_col in col_keys: sort_idx = col_keys.index(sort_col) # sort column with key of sort_col columns[sort_idx][0] += '\u2193' # ↓ downwards arrow (sort) for i, (uid, val) in enumerate(sort): + # === New table section === if i % task_repeat == 0: - # === Response table === table = Table(width=console_width, box=None) if i == 0: table.title = f"[white bold] Query responses [/white bold] | " \ - f"[white]context[/white][bold]continuation[/bold] | " \ - f".prob: 'prediction'" + f"[white]context[/white][bold]continuation[/bold] | .prob: 'prediction'" for col, _, _, stl in columns: # [Column_name, key_name, format_string, rich_style] table.add_column(col, style=stl, justify='right') + # === Last table section === if i == len(sort) - 1: table.caption = f'[bold]{len([s for s in stats.values() if len(s)])}[/bold]/{len(stats)} (respond/topk) | ' \ - f'{tasks_per_server} tasks per server | repeat tasks over {task_repeat} servers' + f'[bold]{tasks_per_server}[/bold] tasks per server | ' \ + f'repeat tasks over [bold]{task_repeat}[/bold] servers' + # === Row addition === row = [txt.format(stats[uid][key]) for _, key, txt, _ in columns] for j in range(tasks_per_server): batch_item = ((i // task_repeat) * tasks_per_server + j) % batch_size # repeat task over servers, do not exceed batch_size @@ -1480,10 +1493,11 @@ def response_table(batch_predictions: List, stats: Dict, sort_col: str, console_ table.add_row(*row) + # === Table print === if (i == len(sort) - 1) or (i % task_repeat == task_repeat - 1): try: print(table) - except Exception as e: + except MarkupError as e: print(e) else: if i == len(sort) - 1: From 0006d1099db93ec335a5d6a0ebf426f304b9d656 Mon Sep 17 00:00:00 2001 From: opentaco Date: Fri, 18 Nov 2022 12:20:16 +0200 Subject: [PATCH 20/21] Correct responsive count --- bittensor/_neuron/text/core_validator/__init__.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/bittensor/_neuron/text/core_validator/__init__.py b/bittensor/_neuron/text/core_validator/__init__.py index 7f9e7401f0..fbb5955959 100644 --- a/bittensor/_neuron/text/core_validator/__init__.py +++ b/bittensor/_neuron/text/core_validator/__init__.py @@ -1477,9 +1477,10 @@ def response_table(batch_predictions: List, stats: Dict, sort_col: str, console_ # === Last table section === if i == len(sort) - 1: - table.caption = f'[bold]{len([s for s in stats.values() if len(s)])}[/bold]/{len(stats)} (respond/topk) | ' \ + table.caption = f'[bold]{len(sort)}[/bold]/{len(stats)} (respond/topk) | ' \ f'[bold]{tasks_per_server}[/bold] tasks per server | ' \ - f'repeat tasks over [bold]{task_repeat}[/bold] servers' + f'repeat tasks over [bold]{task_repeat}[/bold] servers ' \ + f'\[{batch_size}]' # === Row addition === row = [txt.format(stats[uid][key]) for _, key, txt, _ in columns] @@ -1576,10 +1577,10 @@ def stats_table(stats, sort_col, console_width, title, caption, mark_uids=None): def synapse_table(name, stats, sort_col, console_width, start_time): r""" Prints the evaluation of the neuron responses to the validator request """ - stats_table(stats, sort_col, console_width, f'[white] \[{name}] responses [/white] | Validator forward', # title - f'[bold]{len([s for s in stats.values() if len(s)])}[/bold]/{len(stats)} (respond/topk) | ' + f'[bold]{len([s for s in stats.values() if len(s) and sort_col in s])}[/bold]/' + f'{len(stats)} (respond/topk) | ' f'[bold]Synapse[/bold] | [white]\[{time.time() - start_time:.3g}s][/white]' # caption ) From df86916e07f516c3e027e34cf8323191deb3c7b8 Mon Sep 17 00:00:00 2001 From: opentaco Date: Fri, 18 Nov 2022 12:24:26 +0200 Subject: [PATCH 21/21] Format table caption --- bittensor/_neuron/text/core_validator/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bittensor/_neuron/text/core_validator/__init__.py b/bittensor/_neuron/text/core_validator/__init__.py index fbb5955959..6fcf60bea3 100644 --- a/bittensor/_neuron/text/core_validator/__init__.py +++ b/bittensor/_neuron/text/core_validator/__init__.py @@ -1480,7 +1480,8 @@ def response_table(batch_predictions: List, stats: Dict, sort_col: str, console_ table.caption = f'[bold]{len(sort)}[/bold]/{len(stats)} (respond/topk) | ' \ f'[bold]{tasks_per_server}[/bold] tasks per server | ' \ f'repeat tasks over [bold]{task_repeat}[/bold] servers ' \ - f'\[{batch_size}]' + f'[white]\[{math.ceil(1. * len(sort) / task_repeat) * tasks_per_server}/' \ + f'{batch_size} batch tasks][/white]' # === Row addition === row = [txt.format(stats[uid][key]) for _, key, txt, _ in columns]