Skip to content

Commit

Permalink
stash
Browse files Browse the repository at this point in the history
  • Loading branch information
robertgshaw2-redhat committed Dec 12, 2024
1 parent 4816d20 commit 0f3cf42
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
9 changes: 4 additions & 5 deletions examples/openai_completion_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Modify OpenAI's API key and API base to use vLLM's API server.
openai_api_key = "EMPTY"
openai_api_base = "http://localhost:8000/v1"
openai_api_base = "http://localhost:8001/v1"

client = OpenAI(
# defaults to os.environ.get("OPENAI_API_KEY")
Expand All @@ -14,14 +14,13 @@
model = models.data[0].id

# Completion API
stream = False
stream = True
completion = client.completions.create(
model=model,
prompt="A robot may not injure a human being",
echo=False,
n=2,
stream=stream,
logprobs=3)
n=1,
stream=stream)

print("Completion results:")
if stream:
Expand Down
20 changes: 20 additions & 0 deletions vllm/engine/multiprocessing/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import hashlib
import hmac
import secrets
from dataclasses import dataclass
from enum import Enum
from typing import List, Mapping, Optional, Union, overload
Expand All @@ -14,12 +17,29 @@

VLLM_RPC_SUCCESS_STR = "SUCCESS"

# TODO: switch to SECRET_KEY = secrets.token_bytes(16)
# and pass the SECRET_KEY to the background process.
SECRET_KEY = b"my_key"
IPC_INPUT_EXT = "_input_socket"
IPC_OUTPUT_EXT = "_output_socket"
IPC_HEALTH_EXT = "_health_socket"
IPC_DATA_EXT = "_data_socket"


def sign(msg: bytes) -> bytes:
"""Compute the HMAC digest of msg, given signing key `key`"""
return hmac.HMAC(
SECRET_KEY,
msg,
digestmod=hashlib.sha256,
).digest()


def check_signed(sig: bytes, msg: bytes) -> bool:
correct_sig = sign(msg)
return hmac.compare_digest(sig, correct_sig)


class MQEngineDeadError(RuntimeError):
pass

Expand Down
8 changes: 5 additions & 3 deletions vllm/engine/multiprocessing/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# yapf: disable
from vllm.engine.async_llm_engine import (
build_guided_decoding_logits_processor_async)
from vllm.engine.multiprocessing import (ENGINE_DEAD_ERROR, IPC_DATA_EXT,
from vllm.engine.multiprocessing import (ENGINE_DEAD_ERROR, IPC_DATA_EXT, check_signed,
IPC_HEALTH_EXT, IPC_INPUT_EXT,
IPC_OUTPUT_EXT, RPC_REQUEST_T,
VLLM_RPC_SUCCESS_STR, RPCAbortRequest,
Expand Down Expand Up @@ -192,8 +192,10 @@ async def run_output_handler_loop(self):
ENGINE_DEAD_ERROR(self._errored_with))
return

message: Frame = await self.output_socket.recv(copy=False)
request_outputs = pickle.loads(message.buffer)
sig, message = await self.output_socket.recv_multipart(copy=False)
if not check_signed(sig, message):
raise Exception
request_outputs = pickle.loads(message)

is_error = isinstance(request_outputs,
(BaseException, RPCError))
Expand Down
6 changes: 4 additions & 2 deletions vllm/engine/multiprocessing/engine.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pickle
import signal
import hmac
from contextlib import contextmanager
from typing import Iterator, List, Optional, Union

Expand All @@ -10,7 +11,7 @@
from vllm.engine.llm_engine import LLMEngine
# yapf conflicts with isort for this block
# yapf: disable
from vllm.engine.multiprocessing import (ENGINE_DEAD_ERROR, IPC_DATA_EXT,
from vllm.engine.multiprocessing import (ENGINE_DEAD_ERROR, sign, IPC_DATA_EXT,
IPC_HEALTH_EXT, IPC_INPUT_EXT,
IPC_OUTPUT_EXT, REQUEST_OUTPUTS_T,
VLLM_RPC_SUCCESS_STR, RPCAbortRequest,
Expand Down Expand Up @@ -310,7 +311,8 @@ def _send_outputs(self, outputs: REQUEST_OUTPUTS_T):
pass

output_bytes = pickle.dumps(outputs)
self.output_socket.send_multipart((output_bytes, ), copy=False)
sig = sign(output_bytes)
self.output_socket.send_multipart((sig, output_bytes), copy=False)

def _send_healthy(self):
"""Send HEALTHY message to RPCClient."""
Expand Down

0 comments on commit 0f3cf42

Please sign in to comment.