Update llama.py
This commit is contained in:
parent
25a88ea003
commit
5cfea20129
1 changed files with 9 additions and 9 deletions
|
|
@ -488,15 +488,15 @@ def LlamaModel_fast_forward(
|
|||
|
||||
# Fix up attention mask by setting elements to 0
|
||||
# Specifically for DPO
|
||||
try:
|
||||
if self._has_no_labels and attention_mask is not None:
|
||||
inputs_requires_grad = inputs_embeds.requires_grad
|
||||
if inputs_requires_grad: inputs_embeds.requires_grad_(False)
|
||||
inputs_embeds *= attention_mask.unsqueeze(0).transpose(0, 1).transpose(1, 2)
|
||||
if inputs_requires_grad: inputs_embeds.requires_grad_(True)
|
||||
pass
|
||||
except:
|
||||
print(inputs_embeds.shape, attention_mask.shape)
|
||||
if self._has_no_labels and attention_mask is not None and \
|
||||
attention_mask.shape[1] == seq_length:
|
||||
# Careful for inference the attention_mask is size (1, kv_seq_len)
|
||||
# Whilst the input_embeds is size (1, 1, 4096)
|
||||
inputs_requires_grad = inputs_embeds.requires_grad
|
||||
if inputs_requires_grad: inputs_embeds.requires_grad_(False)
|
||||
inputs_embeds *= attention_mask.unsqueeze(0).transpose(0, 1).transpose(1, 2)
|
||||
if inputs_requires_grad: inputs_embeds.requires_grad_(True)
|
||||
pass
|
||||
|
||||
# Ignore attention_mask
|
||||
if attention_mask is None:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue