Cross-check LiSA held-out metrics across scoring paths
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
"""Check answer-only metrics and isolate recovery from newly lost items."""
|
||||
import json
|
||||
from pathlib import Path
|
||||
from tempfile import TemporaryDirectory
|
||||
import unittest
|
||||
|
||||
import numpy as np
|
||||
@@ -6,11 +9,44 @@ import torch
|
||||
from torch.nn import functional as F
|
||||
|
||||
from crossqkv.lisa_effect_answer_audit import vocabulary_scores
|
||||
from crossqkv.lisa_effect_audit import paired
|
||||
from crossqkv.lisa_effect_audit import MODES, full_vocab_metrics, loss_delta, paired
|
||||
from tests.test_lisa_tail import Tensor
|
||||
|
||||
|
||||
class EffectAuditTests(unittest.TestCase):
|
||||
def test_loss_interval_uses_paired_differences(self):
|
||||
direct = np.array([0.5, 1.0, 4.0, 9.0])
|
||||
result = loss_delta(direct - 0.25, direct)
|
||||
self.assertEqual(result, {'mean_delta': -0.25,
|
||||
'paired_prompt_bootstrap_95': [-0.25, -0.25]})
|
||||
|
||||
def test_full_vocab_compares_each_recipient_schedule_to_matched_direct(self):
|
||||
mapped = ('native', 'linear', 'direct_chain', 'lisa_chain', 'lisa_answer_weighted',
|
||||
'direct_23', 'lisa_23_ablation')
|
||||
payload = {'candidate_sites': [19, 23], 'single_lisa_is_ablation_of_joint_checkpoint': True,
|
||||
'arms': {}}
|
||||
for name in mapped:
|
||||
correct = name not in ('direct_chain', 'direct_23')
|
||||
payload['arms'][name] = {
|
||||
'n': 1, 'full_vocab_correct': int(correct), 'four_choice_correct': 1,
|
||||
'full_vocab_nll': 0.25 if correct else 2.0,
|
||||
'rows': [{'id': 'test-a', 'gold_id': 3, 'greedy_id': 3 if correct else 4,
|
||||
'choice_id': 3, 'nll': 0.25 if correct else 2.0}],
|
||||
}
|
||||
choices = {name: np.array([True]) for name in MODES}
|
||||
with TemporaryDirectory() as scratch:
|
||||
path = Path(scratch) / 'answers.json'
|
||||
path.write_text(json.dumps(payload))
|
||||
measured = full_vocab_metrics(path, [('test-a', 0)], [19, 23], choices)
|
||||
comparisons = measured['matched_direct_comparisons']
|
||||
self.assertEqual(comparisons['lisa_chain']['baseline'], 'direct_chain')
|
||||
self.assertEqual(comparisons['lisa_23_ablation']['baseline'], 'direct_23')
|
||||
self.assertEqual(comparisons['lisa_chain']['rescued'], 1)
|
||||
self.assertEqual(comparisons['lisa_chain']['answer_nll_delta']['mean_delta'], -1.75)
|
||||
choices['lisa'] = np.array([False])
|
||||
with self.assertRaisesRegex(ValueError, 'lisa_chain choices differ'):
|
||||
full_vocab_metrics(path, [('test-a', 0)], [19, 23], choices)
|
||||
|
||||
def test_paired_rescue_excludes_natively_wrong_items(self):
|
||||
native, direct, candidate = (np.array(x, dtype=bool) for x in
|
||||
[(1, 1, 1, 0), (0, 0, 1, 1), (1, 0, 0, 1)])
|
||||
|
||||
Reference in New Issue
Block a user