Update llama.py
This commit is contained in:
parent
ee6f5096ed
commit
6aa46ffff6
1 changed files with 6 additions and 3 deletions
|
|
@ -486,9 +486,12 @@ def LlamaModel_fast_forward(
|
|||
if inputs_embeds is None:
|
||||
inputs_embeds = self.embed_tokens(input_ids)
|
||||
|
||||
inputs_embeds.requires_grad_(False)
|
||||
inputs_embeds *= attention_mask.unsqueeze(0).transpose(0, 1).transpose(1, 2)
|
||||
inputs_embeds.requires_grad_(True)
|
||||
# Fix up attention mask by setting elements to 0
|
||||
inputs_requires_grad = inputs_embeds.requires_grad
|
||||
if inputs_requires_grad: inputs_embeds.requires_grad_(False)
|
||||
inputs_embeds[attention_mask == 0] = -torch.inf
|
||||
if inputs_requires_grad: inputs_embeds.requires_grad_(True)
|
||||
#
|
||||
|
||||
# Ignore attention_mask
|
||||
if attention_mask is None:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue