Repository navigation
feat(vllm-grpc): Redis media-processing sidecar backend and reference sidecar #2401
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
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
12b30c2
feat(vllm-grpc): Redis media-processing sidecar backend and reference…
CatherineSue ac799c4
fix(vllm-grpc): harden the media sidecar loop and namespace the sidec…
CatherineSue a945849
fix(vllm-grpc): fingerprint the per-prompt media limit, harden sideca…
CatherineSue 13b5026
fix(vllm-grpc): one fingerprint derivation, resolved media limits, pr…
CatherineSue 9ea2d3d
fix(vllm-grpc): fingerprint validated media limits with their sibling…
CatherineSue 9ca1aed
fix(vllm-grpc): normalize spelled-out default media limits, hash unkn…
CatherineSue 05e3a78
test(vllm-grpc): pin the uniform unset media limit the fingerprint re…
CatherineSue 6989304
ci: run the servicer's vLLM-gated unit tests in the vLLM e2e lanes
CatherineSue b8b8a5f
ci: run the servicer suite in one vLLM lane, with an import canary
CatherineSue b9ba83a
ci: install msgspec for the servicer unit tests and show skip reasons
CatherineSue 95bb909
ci: state which servicer test gates the CPU job still skips, install …
CatherineSue File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,192 @@ | ||
| """Servicer <-> sidecar protocol for worker-side media processing over Redis. | ||
|
|
||
| Engine-free: no vLLM import. Redis is a job transport plus the sidecar's own | ||
| cache; the servicer always receives full tensors, so nothing here has to stay | ||
| consistent with vLLM's processor caches. | ||
|
|
||
| Keys under ``smg:mm:v1:{namespace}``: | ||
| - ``:hello`` HASH, refreshed by the sidecar (fingerprint + schemes) | ||
| - ``:jobs`` LIST, servicer LPUSH / sidecar BRPOP | ||
| - ``:res:{job_id}`` LIST, sidecar LPUSH + EXPIRE / servicer BRPOP | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import hashlib | ||
| from collections.abc import Mapping | ||
|
|
||
| import msgspec | ||
|
|
||
| SCHEMA_VERSION = 1 | ||
| KEY_ROOT = "smg:mm:v1" | ||
|
|
||
| ENV_REDIS_URL = "SMG_VLLM_MM_REDIS_URL" | ||
| ENV_TIMEOUT_MS = "SMG_VLLM_MM_SIDECAR_TIMEOUT_MS" | ||
| ENV_MAX_QUEUE = "SMG_VLLM_MM_SIDECAR_MAX_QUEUE" | ||
| ENV_NAMESPACE = "SMG_VLLM_MM_SIDECAR_NAMESPACE" | ||
|
|
||
| DEFAULT_REDIS_URL = "redis://127.0.0.1:6379/0" | ||
| DEFAULT_TIMEOUT_MS = 30_000 | ||
| DEFAULT_MAX_QUEUE = 256 | ||
|
|
||
| HELLO_TTL_S = 15 | ||
| HELLO_REFRESH_S = 5 | ||
| RESULT_TTL_S = 120 | ||
|
|
||
| # Client-caused failures become INVALID_ARGUMENT (terminal 400). | ||
| CLIENT_ERROR_CODES = frozenset( | ||
| { | ||
| "fetch_failed", | ||
| "domain_not_allowed", | ||
| "scheme_not_accepted", | ||
| "limit_exceeded", | ||
| "decode_failed", | ||
| "placeholder_mismatch", | ||
| } | ||
| ) | ||
| # Everything else is UNAVAILABLE (503) so the router retries elsewhere. | ||
| RETRYABLE_ERROR_CODES = frozenset({"expired", "processor_error", "fingerprint_mismatch"}) | ||
|
|
||
|
|
||
| class Fingerprint(msgspec.Struct, frozen=True): | ||
| """What must match between a worker and the sidecar processing for it.""" | ||
|
|
||
| model: str | ||
| vllm_version: str | ||
| dtype: str | ||
| video_backend: str | ||
| media_io_kwargs: str | ||
| mm_processor_kwargs: str | ||
| # The sidecar's limit is the only one applied on the redis path. | ||
| limit_per_prompt: str | ||
|
|
||
| def namespace(self) -> str: | ||
| """Key namespace: fleets that would fail `mismatches` never share keys.""" | ||
| joined = "|".join(getattr(self, name) for name in self.__struct_fields__) | ||
| return hashlib.sha256(joined.encode()).hexdigest()[:16] | ||
|
|
||
| def mismatches(self, other: Fingerprint) -> list[str]: | ||
| return [ | ||
| name for name in self.__struct_fields__ if getattr(self, name) != getattr(other, name) | ||
| ] | ||
|
|
||
| def to_hello(self) -> dict[str, str]: | ||
| return {name: getattr(self, name) for name in self.__struct_fields__} | ||
|
|
||
| @classmethod | ||
| def from_hello(cls, mapping: Mapping[bytes | str, bytes | str]) -> Fingerprint | None: | ||
| decoded = {_text(key): _text(value) for key, value in mapping.items()} | ||
| try: | ||
| return cls(**{name: decoded[name] for name in cls.__struct_fields__}) | ||
| except KeyError: | ||
| return None | ||
|
|
||
|
|
||
| def _text(value: bytes | str) -> str: | ||
| return value.decode("utf-8", errors="replace") if isinstance(value, bytes) else value | ||
|
|
||
|
|
||
| def hello_field(mapping: Mapping[bytes | str, bytes | str], name: str) -> str: | ||
| for key, value in mapping.items(): | ||
| if _text(key) == name: | ||
| return _text(value) | ||
| return "" | ||
|
|
||
|
|
||
| def hello_schemes(mapping: Mapping[bytes | str, bytes | str]) -> str: | ||
| return hello_field(mapping, "schemes") | ||
|
|
||
|
|
||
| def resolve_namespace(fingerprint: Fingerprint, override: str | None) -> str: | ||
| override = (override or "").strip() | ||
| return override if override else fingerprint.namespace() | ||
|
|
||
|
|
||
| class Keys(msgspec.Struct, frozen=True): | ||
| prefix: str | ||
|
|
||
| @classmethod | ||
| def for_namespace(cls, namespace: str) -> Keys: | ||
| return cls(prefix=f"{KEY_ROOT}:{namespace}") | ||
|
|
||
| @property | ||
| def hello(self) -> str: | ||
| return f"{self.prefix}:hello" | ||
|
|
||
| @property | ||
| def jobs(self) -> str: | ||
| return f"{self.prefix}:jobs" | ||
|
|
||
| def result(self, job_id: str) -> str: | ||
| return f"{self.prefix}:res:{job_id}" | ||
|
|
||
|
|
||
| class JobItem(msgspec.Struct): | ||
| modality: str | ||
| url: str | ||
|
|
||
|
|
||
| class Job(msgspec.Struct): | ||
| v: int | ||
| job_id: str | ||
| request_id: str | ||
| fingerprint: Fingerprint | ||
| prompt_token_ids: list[int] | ||
| prompt: str | None | ||
| items: list[JobItem] | ||
| enqueued_ms: int | ||
| deadline_ms: int | ||
|
|
||
|
|
||
| class Placeholder(msgspec.Struct): | ||
| offset: int | ||
| length: int | ||
| is_embed: list[bool] | None = None | ||
|
|
||
|
|
||
| class Timing(msgspec.Struct): | ||
| queue_ms: int = 0 | ||
| fetch_ms: int = 0 | ||
| process_ms: int = 0 | ||
|
|
||
|
|
||
| class JobResult(msgspec.Struct): | ||
| v: int | ||
| job_id: str | ||
| ok: bool | ||
| fingerprint: Fingerprint | None = None | ||
| prompt_token_ids: list[int] = msgspec.field(default_factory=list) | ||
| mm_hashes: dict[str, list[str]] = msgspec.field(default_factory=dict) | ||
| mm_placeholders: dict[str, list[Placeholder]] = msgspec.field(default_factory=dict) | ||
| # Per item: one vLLM MsgpackEncoder buffer of a MultiModalKwargsItem. | ||
| mm_kwargs: dict[str, list[bytes]] = msgspec.field(default_factory=dict) | ||
| code: str = "" | ||
| message: str = "" | ||
| timing: Timing | None = None | ||
| cache: str = "" | ||
|
|
||
|
|
||
| def failure(job_id: str, code: str, message: str) -> JobResult: | ||
| return JobResult(v=SCHEMA_VERSION, job_id=job_id, ok=False, code=code, message=message) | ||
|
|
||
|
|
||
| _job_encoder = msgspec.msgpack.Encoder() | ||
| _job_decoder = msgspec.msgpack.Decoder(type=Job) | ||
| _result_encoder = msgspec.msgpack.Encoder() | ||
| _result_decoder = msgspec.msgpack.Decoder(type=JobResult) | ||
|
|
||
|
|
||
| def encode_job(job: Job) -> bytes: | ||
| return _job_encoder.encode(job) | ||
|
|
||
|
|
||
| def decode_job(raw: bytes) -> Job: | ||
| return _job_decoder.decode(raw) | ||
|
|
||
|
|
||
| def encode_result(result: JobResult) -> bytes: | ||
| return _result_encoder.encode(result) | ||
|
|
||
|
|
||
| def decode_result(raw: bytes) -> JobResult: | ||
| return _result_decoder.decode(raw) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.