Skip to content
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

Speculative inference #590

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft
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: 9 additions & 1 deletion src/petals/client/inference_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ def step(
if self.closed:
raise Exception("Session is closed, cannot perform step")

if start_from_position is not None:
assert start_from_position <= self._position
self._position = start_from_position
if self.history is not None and self.history.shape[1] >= start_from_position:
self.history = self.history[:, :start_from_position, :] if start_from_position > 0 else None

n_input_tokens = inputs.shape[1]
if self.history is None:
self.history = inputs
Expand Down Expand Up @@ -330,7 +336,9 @@ def step(
self._update_sequence(server_idx, block_idx, attempt_no)

server_session = self._server_sessions[server_idx]
assert server_session.position == self.position, f"{server_session.position} and {self.position}"
assert (
server_session.position == self.position
), f"Position mismatch: {server_session.position} and {self.position}"
inputs = server_session.step(
inputs,
prompts[server_session.span.start : server_session.span.end],
Expand Down
Loading