-
Notifications
You must be signed in to change notification settings - Fork 549
Compose split routed experts from vLLM responses #1349
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
Open
S1ro1
wants to merge
7
commits into
main
Choose a base branch
from
feat/split-routed-experts
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+150
−32
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8dbd674
feat: compose split routed experts
S1ro1 b76a6bb
feat: decode base64 routed experts
S1ro1 591914a
Revert "fix: narrow send_cancel BaseException catch to Exception (#11…
S1ro1 d70c07f
feat: keep routed experts compact
S1ro1 2423ba3
Revert "Revert "fix: narrow send_cancel BaseException catch to Except…
S1ro1 0c6fcff
chore: narrow routed experts payload handling
S1ro1 162cffb
Merge remote-tracking branch 'origin/main' into fix/split-routed-expe…
S1ro1 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import base64 | ||
| from typing import Any, Mapping, cast | ||
|
|
||
| from verifiers.types import RoutedExperts | ||
|
|
||
| INT16_BYTES = 2 | ||
|
|
||
|
|
||
| def _shape_numel(shape: list[int]) -> int: | ||
| seq_len, num_layers, topk = shape | ||
| return seq_len * num_layers * topk | ||
|
|
||
|
|
||
| def _token_stride(shape: list[int]) -> int: | ||
| return shape[1] * shape[2] * INT16_BYTES | ||
|
|
||
|
|
||
| def _validate_routed_experts(payload: RoutedExperts) -> RoutedExperts: | ||
| assert payload.dtype == "int16" | ||
| assert len(payload.shape) == 3 | ||
| assert len(payload.data) == _shape_numel(payload.shape) * INT16_BYTES | ||
| return payload | ||
|
|
||
|
|
||
| def _decode_routed_experts(raw: Any) -> RoutedExperts: | ||
| if isinstance(raw, RoutedExperts): | ||
| return _validate_routed_experts(raw) | ||
|
|
||
| if hasattr(raw, "model_dump"): | ||
| raw = raw.model_dump(mode="python") | ||
|
|
||
| raw = cast(Mapping[str, Any], raw) | ||
| assert raw["encoding"] == "base64" | ||
| assert raw["dtype"] == "int16" | ||
| shape = [int(dim) for dim in raw["shape"]] | ||
| data = base64.b64decode(raw["data"]) | ||
| return _validate_routed_experts(RoutedExperts(shape=shape, data=data)) | ||
|
|
||
|
|
||
| def slice_routed_experts(payload: RoutedExperts, end: int) -> RoutedExperts: | ||
| payload = _validate_routed_experts(payload) | ||
| assert 0 <= end <= payload.shape[0] | ||
| stride = _token_stride(payload.shape) | ||
| return RoutedExperts( | ||
| shape=[end, payload.shape[1], payload.shape[2]], | ||
| data=payload.data[: end * stride], | ||
| ) | ||
|
|
||
|
|
||
| def compose_split_routed_experts( | ||
| *, | ||
| prompt_routed_experts: Any, | ||
| completion_routed_experts: Any, | ||
| prompt_len: int, | ||
| completion_len: int, | ||
| ) -> RoutedExperts | None: | ||
| """Compose split prompt/completion routing into compact int16 bytes.""" | ||
|
|
||
| if prompt_routed_experts is None and completion_routed_experts is None: | ||
| return None | ||
|
|
||
| prompt = _decode_routed_experts(prompt_routed_experts) | ||
| assert prompt.shape[0] == prompt_len | ||
|
|
||
| expected_completion_routed_len = max(completion_len - 1, 0) | ||
| if expected_completion_routed_len == 0: | ||
| completion_data = b"" | ||
| else: | ||
| completion = _decode_routed_experts(completion_routed_experts) | ||
| assert completion.shape[1:] == prompt.shape[1:] | ||
| assert completion.shape[0] == expected_completion_routed_len | ||
| completion_data = completion.data | ||
|
|
||
| if completion_len == 0: | ||
| return prompt | ||
|
|
||
| stride = _token_stride(prompt.shape) | ||
| return _validate_routed_experts( | ||
| RoutedExperts( | ||
| shape=[prompt_len + completion_len, prompt.shape[1], prompt.shape[2]], | ||
| data=prompt.data + completion_data + (b"\0" * stride), | ||
| ) | ||
| ) | ||
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
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.