Skip to content

fix eager_eval with kv cache and improve pybind eval speed #4720

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

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
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
11 changes: 5 additions & 6 deletions examples/models/llama2/eval_llama_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,11 @@ def _model_call(self, inps):
# inps: Tensor of shape (1, max_seq_len - 1)
# logits: Tensor of shape (1, max_seq_len - 1, vocab_size)
if self._use_kv_cache:
result_logits = []
for pos in range(self._max_seq_length):
pos_tensor = torch.tensor([pos], dtype=torch.int64)
logits = self._et_model.forward((inps[:, pos : pos + 1], pos_tensor))
result_logits.append(logits[0])
return torch.cat(result_logits, dim=1)
pos_tensor = torch.tensor([0], dtype=torch.int64, device=self.device)
result = self._et_model.forward(
(inps[:, : self._max_seq_length], pos_tensor)
)
return result[0]
else:
result = self._et_model.forward((inps,))
return result[0]
Expand Down
5 changes: 1 addition & 4 deletions examples/models/llama2/evaluate/eager_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,7 @@ def tok_decode(self, tokens):

def _model_call(self, inps):
if self._use_kv_cache:
pos_tensor = torch.arange(
self._max_seq_length, dtype=torch.int64, device=self.device
)

pos_tensor = torch.tensor([0], dtype=torch.int64, device=self.device)
# Batch process the whole sequence.
logits = self._model(inps[:, : self._max_seq_length], pos_tensor)
return logits
Expand Down
Loading