Evaluate matched half-size trajectory distillation updates

This commit is contained in:
2026-11-26 15:12:33 +08:00
parent 6baff1af4a
commit a5978c0840
5 changed files with 238 additions and 2 deletions
+27
View File
@@ -10,10 +10,37 @@ import torch
from crossqkv.lisa_combination_eval import changed_answers, score_differences
from crossqkv.lisa_combination_screen import SITES, paired_questions
from crossqkv.lisa_rank_compare import assignments, make_adapters, score_gold_answers
from crossqkv.lisa_trajectory_midpoint import midpoint, summarize
from crossqkv.lisa_trajectory_train import replay_teacher_inputs, reverse_kl
class CombinationTests(unittest.TestCase):
def test_checkpoint_midpoint_preserves_shape_dtype_and_endpoints(self):
base = {'a': torch.tensor([2., -4.]), 'b': torch.tensor([1.], dtype=torch.bfloat16)}
trained = {'a': torch.tensor([0., 6.]), 'b': torch.tensor([3.], dtype=torch.bfloat16)}
middle = midpoint(base, trained)
torch.testing.assert_close(middle['a'], torch.tensor([1., 1.]))
torch.testing.assert_close(middle['b'], torch.tensor([2.], dtype=torch.bfloat16))
self.assertEqual(base['a'].tolist(), [2., -4.])
self.assertEqual(trained['a'].tolist(), [0., 6.])
with self.assertRaises(ValueError):
midpoint(base, {'a': torch.ones(1), 'b': trained['b']})
def test_midpoint_comparisons_keep_gains_losses_and_pairs(self):
qs = [{'id': f'q{i}'} for i in range(4)]
flags = {'prior-lisa': [1, 0, 1, 0], 'trajectory-student': [0, 0, 1, 0],
'trajectory-reference': [1, 0, 0, 0], 'half-reference': [1, 0, 0, 0],
'half-student': [1, 1, 0, 1]}
answers = {k: [{'correct': bool(x)} for x in v] for k, v in flags.items()}
val = summarize(qs, answers, intervals=False)
self.assertEqual(val['correct']['half-student'], 3)
self.assertEqual(val['pairs_both_correct']['half-student'], 1)
result = val['comparisons']['half-student-vs-prior-lisa']
self.assertEqual(result, {'delta': .25, 'corrected': ['q1', 'q3'], 'lost': ['q2']})
test = summarize(qs, answers, intervals=True)
self.assertEqual(test['comparisons']['half-student-vs-prior-lisa']['interval_95'], [0., .5])
self.assertEqual(test['comparisons']['half-student-vs-half-reference']['corrected'], ['q1', 'q3'])
def test_reference_replay_uses_native_tail_only_on_matching_gold_tokens(self):
ids = torch.tensor([[13, 4, 7, 9]])
lengths = torch.tensor([4])