fix bug... if topk > vocab_size, torch.topk will throw error
This commit is contained in:
1 parent
57735f532d
commit
91d02510ce
1 file changed
+1
-1
@@ -277,7 +277,7 @@ class GPT(nn.Module):
|
|||||||
logits = logits[:, -1, :] / temperature
|
logits = logits[:, -1, :] / temperature
|
||||||
# optionally crop the logits to only the top k options
|
# optionally crop the logits to only the top k options
|
||||||
if top_k is not None:
|
if top_k is not None:
|
||||||
v, _ = torch.topk(logits, top_k)
|
v, _ = torch.topk(logits, min(top_k, logits.size(-1)))
|
||||||
logits[logits < v[:, [-1]]] = -float('Inf')
|
logits[logits < v[:, [-1]]] = -float('Inf')
|
||||||
# apply softmax to convert logits to (normalized) probabilities
|
# apply softmax to convert logits to (normalized) probabilities
|
||||||
probs = F.softmax(logits, dim=-1)
|
probs = F.softmax(logits, dim=-1)
|
||||||
|
|||||||
Reference in new issue
Block a user