Skip to content
Merged
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
10 changes: 5 additions & 5 deletions optillm/cot_decoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ def calculate_confidence(logits: List[torch.Tensor], answer_ids: torch.Tensor) -
break
token_logits = logits[t]
probs = torch.softmax(token_logits, dim=-1)
if probs.size(0) > 1:
top_2_probs, _ = torch.topk(probs, min(2, probs.size(0)))
if top_2_probs.size(0) > 1:
confidence_sum += (top_2_probs[0] - top_2_probs[1]).item()
if probs.size(-1) > 1:
top_2_probs, _ = torch.topk(probs, min(2, probs.size(-1)))
if top_2_probs.size(-1) > 1:
confidence_sum += (top_2_probs[-1][0] - top_2_probs[-1][1]).item()
else:
confidence_sum += 1.0 # Max confidence if there's only one token
else:
Expand Down Expand Up @@ -142,4 +142,4 @@ def cot_decode(
return aggregate_paths_based_on_scores(paths)
else:
return max(paths, key=lambda x: x[1])