Skip to content

Commit

Permalink
Update true_poetry.py
Browse files Browse the repository at this point in the history
fix for Huggingface v4
  • Loading branch information
summerstay authored Apr 30, 2021
1 parent 83ff4e2 commit a726f85
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions true_poetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,8 @@ def expand_node(sentence, past):
input_ids = torch.tensor([sentence[-1]]).unsqueeze(0)
inputs = {'input_ids': input_ids}
with torch.no_grad():
logits, past = model(**inputs, past=past)
logits, past = model(**inputs, past_key_values=past, return_dict=False)
// use this line for Huggingface v3: logits, past = model(**inputs, past=past)
logits[0][0][50256]=-math.inf # no <end of text> token
logits = logits[:, -1, :]
probs = F.softmax(logits, dim=-1).tolist()[0]
Expand Down Expand Up @@ -565,4 +566,4 @@ def poem_scheme(kind):
poem_line[line] = poem_line[line][1:]
for line in range(1,number_of_lines):
print(tokenizer.decode(poem_line[line]))


0 comments on commit a726f85

Please sign in to comment.