Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrapped up mem-efficient contrastive search #15

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/transformers/generation/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1974,7 +1974,7 @@ def contrastive_search(

if subset_hidden:
print ('Using subset of last hidden layer')
last_hidden_states = last_hidden_states[:, :, :100]
last_hidden_states = last_hidden_states[:, :, :500]

elif compress_hidden:
print ('Using compressed last hidden layer')
Expand Down Expand Up @@ -2065,7 +2065,6 @@ def contrastive_search(
for key in all_outputs:
if torch.is_tensor(all_outputs[key]):
outputs[key] = torch.stack(all_outputs[key], dim=0)
print (outputs)

else:
# compute the candidate tokens by the language model and collect their hidden_states
Expand All @@ -2087,7 +2086,7 @@ def contrastive_search(
full_hidden_states = outputs.hidden_states

if subset_hidden:
next_hidden = next_hidden[:, :, :100]
next_hidden = next_hidden[:, :, :500]

elif compress_hidden:
next_hidden = compressor(next_hidden)
Expand Down