Replay verified frozen prefix inputs for reference trajectory distillation

This commit is contained in:
2026-11-25 23:08:14 +08:00
parent c577bb740a
commit ce4c0e404b
6 changed files with 94 additions and 23 deletions
+23 -1
View File
@@ -10,10 +10,32 @@ import torch
from crossqkv.lisa_combination_eval import changed_answers
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_train import reverse_kl
from crossqkv.lisa_trajectory_train import replay_teacher_inputs, reverse_kl
class CombinationTests(unittest.TestCase):
def test_reference_replay_uses_native_tail_only_on_matching_gold_tokens(self):
ids = torch.tensor([[13, 4, 7, 9]])
lengths = torch.tensor([4])
residual = torch.arange(12).reshape(1, 4, 3).float()
donor = torch.arange(16).reshape(1, 1, 4, 4).float()
def native_tail(h, scores, sizes, mode, recipients):
self.assertTrue(torch.equal(sizes, lengths))
self.assertEqual((mode, recipients), ('native', ()))
return h * 2, {}
with tempfile.TemporaryDirectory() as folder:
path = Path(folder)/'capture.npz'
np.savez(path, ids=ids.numpy(), start=[2], residual=residual.numpy(), donor=donor.numpy())
target, h, scores = replay_teacher_inputs(native_tail, path, ids, 2, lengths)
self.assertTrue(torch.equal(target, 2 * residual))
self.assertTrue(torch.equal(h, residual))
self.assertTrue(torch.equal(scores, donor))
for wrong_ids, start in [(ids + 1, 2), (ids, 1)]:
with self.assertRaises(ValueError):
replay_teacher_inputs(native_tail, path, wrong_ids, start, lengths)
def test_joint_recoveries_require_beating_both_single_methods_on_one_item(self):
items = [{'id': name} for name in ['a', 'b', 'c', 'd']]
diffs = {'rank-vs-uniform': np.array([[1, -1], [1, 0]]),