Reuse streamed vocabulary blocks for teacher and student projections
This commit is contained in:
@@ -19,7 +19,14 @@ class CombinationTests(unittest.TestCase):
|
||||
student = normal(3, 4).requires_grad_()
|
||||
teacher = normal(3, 4)
|
||||
weight = normal(13, 4)
|
||||
loss = reverse_kl(student, teacher, lambda: iter(weight.split(5)))
|
||||
traversals = 0
|
||||
def chunks():
|
||||
nonlocal traversals
|
||||
traversals += 1
|
||||
yield from weight.split(5)
|
||||
|
||||
loss = reverse_kl(student, teacher, chunks)
|
||||
self.assertEqual(traversals, 2)
|
||||
logp = (student @ weight.T).log_softmax(-1)
|
||||
logq = (teacher @ weight.T).log_softmax(-1)
|
||||
dense = (logp.exp() * (logp - logq)).sum(-1).mean()
|
||||
|
||||
Reference in New Issue
Block a user