Screen deeper LiSA sharing with complete autoregressive answers
This commit is contained in:
@@ -43,6 +43,20 @@ class LiSATrainingTests(unittest.TestCase):
|
||||
torch.testing.assert_close(torch.autograd.grad(streamed, h)[0],
|
||||
torch.autograd.grad(dense, h)[0])
|
||||
|
||||
def test_completion_loss_covers_all_reply_tokens(self):
|
||||
h = torch.randn((2, 6, 3), generator=torch.Generator().manual_seed(4),
|
||||
requires_grad=True)
|
||||
w = torch.randn((8, 3), generator=torch.Generator().manual_seed(5))
|
||||
ids = torch.tensor([[1, 2, 1, 4, 2, 7], [1, 3, 5, 7, 0, 0]])
|
||||
lengths, starts = torch.tensor([6, 4]), torch.tensor([3, 2])
|
||||
valid = (torch.arange(1, 6) < lengths[:, None]) & (torch.arange(1, 6) >= starts[:, None])
|
||||
reference = F.cross_entropy(F.linear(h[:, :-1][valid], w), ids[:, 1:][valid])
|
||||
streamed = language_model_loss(h, ids, lengths, lambda: iter([(0, w)]),
|
||||
completion_starts=starts)
|
||||
torch.testing.assert_close(streamed, reference)
|
||||
torch.testing.assert_close(torch.autograd.grad(streamed, h)[0],
|
||||
torch.autograd.grad(reference, h)[0])
|
||||
|
||||
def test_causality_and_gradients_for_both_adapter_components(self):
|
||||
torch.manual_seed(9)
|
||||
a = LearnableSharingAttention(8, 2, 1, 8, 10000, .25, width=10)
|
||||
|
||||
Reference in New Issue
Block a user