Skip to content
Open
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
18 changes: 8 additions & 10 deletions olive/evaluator/lmeval_ort.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,27 +551,25 @@ def model_call(self, input_ids: torch.Tensor, cont_len: int = 0) -> torch.Tensor
self.params.set_search_options(batch_size=batch_size)
generator = og.Generator(self.model, self.params)

if self._returns_full_logits:
generator.append_tokens(input_ids.tolist())
return torch.from_numpy(generator.get_output("logits")).to(self.device)

# Model only returns logits for the last appended position.
if batch_size > 1 and cont_len > 1:
raise ValueError(
"batch_size > 1 is not supported when the model returns single-position logits"
"batch_size > 1 is not supported when using incremental get_logits() retrieval"
" and continuation length > 1. Right-padding misaligns continuation positions across"
" batch elements. Use batch_size=1 instead."
)
Comment on lines 554 to 559
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in f086863: reworded the ValueError to describe the evaluator’s incremental get_logits() strategy (and right-padding misalignment) instead of implying this is a model output-format property.


# Bulk-append context tokens, then step through the last cont_len tokens
# one at a time to collect only the logits we actually need.
# Use incremental token appending with get_logits() to avoid copying
# the full logits tensor from GPU to CPU. get_output("logits") copies
# seq_len * vocab_size * 2 bytes (e.g. 472MB for 900 tokens with
# 262K vocab), while get_logits() copies only vocab_size * 4 bytes
# (~1MB) per position.
n_logits = max(cont_len, 1)
prefix_len = seq_len - n_logits
generator.append_tokens(input_ids[:, : prefix_len + 1].tolist())
all_logits = [torch.from_numpy(generator.get_output("logits")).to(self.device)]
all_logits = [torch.from_numpy(generator.get_logits()).to(self.device)]
for i in range(prefix_len + 1, seq_len):
generator.append_tokens(input_ids[:, i : i + 1].tolist())
all_logits.append(torch.from_numpy(generator.get_output("logits")).to(self.device))
all_logits.append(torch.from_numpy(generator.get_logits()).to(self.device))

# No need to pad to [batch, seq_len, vocab]. The slicing in _loglikelihood_tokens computes
# ctx_len = inplen + (logits.shape[0] - padding_len_inp), which adjusts for the shorter
Expand Down
Loading