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

Implement direct server-to-server communication #331

Merged
merged 27 commits into from
Jul 11, 2023
Merged

Conversation

borzunov
Copy link
Collaborator

@borzunov borzunov commented Jun 24, 2023

Implement #226.

TODO:

  • Session pipes => session queues (manager.Queue())
  • Send block indices instead of uids to compactify next_servers

@@ -47,6 +51,8 @@ def __init__(
dht: DHT,
module_backends: Dict[str, TransformerBackend],
*,
push_manager: SyncManager,
session_pipes: Dict[str, Tuple[PipeConnection, threading.Lock]],
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

rpc_push() may be received by a connection handler different from the one holding the inference session, so we use some multiprocess communication here.

@@ -92,11 +101,20 @@ def _unpack(req: runtime_pb2.ExpertRequest) -> Iterable[runtime_pb2.Tensor]:
assert isinstance(block_uid, str) and isinstance(metadata, dict)
return block_uid, inputs, metadata

async def rpc_push(self, request: runtime_pb2.ExpertRequest, context: P2PContext) -> runtime_pb2.ExpertResponse:
Copy link
Collaborator Author

@borzunov borzunov Jul 1, 2023

Choose a reason for hiding this comment

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

TODO: This can be stream-to-unary handler, so that (a) the previous server doesn't have to make a new connection each time and (b) we don't have to parse metadata at this stage each time (now it's done to find session_id). I'm not sure if it affects performance much though, so I'd postpone that to a later PR.

for attempt_no in itertools.count():
logger.debug(f"Inference: block {block_idx}, attempt {attempt_no}")
span = None
try:
if not self._chosen_spans or not self._server_sessions or attempt_no >= 1:
# If there is a failed server session, this code closes it
Copy link
Collaborator Author

@borzunov borzunov Jul 1, 2023

Choose a reason for hiding this comment

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

This code was moved to a separate method InferenceSession._update_sequence() to simplify this method.

@borzunov borzunov force-pushed the server-to-server branch 2 times, most recently from 0e5ce37 to 2445aa5 Compare July 2, 2023 00:36
inputs = self.history # Pass full inputs including prefix
else:
inputs = inputs[:, -n_input_tokens:] # No need to pass prefix further

Copy link
Collaborator Author

@borzunov borzunov Jul 10, 2023

Choose a reason for hiding this comment

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

Refactored: This code was moved from InferenceSession.step() to _ServerInferenceSession.step(), since it's actually about one server only. The overall structure is more clear this way.

@borzunov borzunov marked this pull request as ready for review July 10, 2023 00:16
src/petals/client/inference_session.py Outdated Show resolved Hide resolved
src/petals/client/inference_session.py Outdated Show resolved Hide resolved
src/petals/client/inference_session.py Outdated Show resolved Hide resolved
src/petals/server/server.py Show resolved Hide resolved
@borzunov borzunov merged commit 158013a into main Jul 11, 2023
7 checks passed
@borzunov borzunov deleted the server-to-server branch July 11, 2023 13:29
artek0chumak pushed a commit to artek0chumak/petals that referenced this pull request Jul 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants