Screen deeper LiSA sharing with complete autoregressive answers
This commit is contained in:
@@ -114,10 +114,13 @@ class _FrozenVocabularyCE(torch.autograd.Function):
|
||||
return grad_hidden * (gradient * weights[:, None] / weights.sum()), None, None, None
|
||||
|
||||
|
||||
def language_model_loss(hidden, ids, lengths, vocabulary, answer_weight=1.0):
|
||||
def language_model_loss(hidden, ids, lengths, vocabulary, answer_weight=1.0,
|
||||
completion_starts=None):
|
||||
"""Train on all valid next-token targets, avoiding padding and final positions."""
|
||||
positions = torch.arange(ids.shape[1] - 1, device=ids.device)
|
||||
valid = positions[None, :] + 1 < lengths[:, None]
|
||||
if completion_starts is not None:
|
||||
valid = valid & (positions[None, :] + 1 >= completion_starts[:, None])
|
||||
weights = torch.where(positions[None, :] + 2 == lengths[:, None], answer_weight, 1.0)
|
||||
return _FrozenVocabularyCE.apply(hidden[:, :-1][valid], ids[:, 1:][valid],
|
||||
weights[valid].to(dtype=hidden.dtype), vocabulary)
|
||||
|
||||
Reference in New Issue
Block a user