-
Notifications
You must be signed in to change notification settings - Fork 541
Cherry pick changes from main branch to release0.6 branch #1969
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
5 commits
Select commit
Hold shift + click to select a range
304ffd6
feat: add sglang gateway metrics and gateway dashboard (#1959)
scarlet25151 b5d8486
feat: add support for routing-profiles (#1944)
varungup90 f55ce0e
Feat: Support vllm new kvevent format (#1962)
penfree f98473b
feat: add queue for prometheus query (#1964)
scarlet25151 9ea4e3d
fix: update metric name for routing-algorithms (#1968)
varungup90 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| apiVersion: apps/v1 | ||
| kind: Deployment | ||
| metadata: | ||
| name: mock-qwen3-8b | ||
| labels: | ||
| model.aibrix.ai/name: "qwen3-8b" | ||
| model.aibrix.ai/port: "8000" | ||
| adapter.model.aibrix.ai/enabled: "true" | ||
| spec: | ||
| replicas: 1 | ||
| selector: | ||
| matchLabels: | ||
| adapter.model.aibrix.ai/enabled: "true" | ||
| model.aibrix.ai/name: "qwen3-8b" | ||
| app: "mock-qwen3-8b" | ||
| template: | ||
| metadata: | ||
| labels: | ||
| adapter.model.aibrix.ai/enabled: "true" | ||
| model.aibrix.ai/name: "qwen3-8b" | ||
| app: "mock-qwen3-8b" | ||
| annotations: | ||
| model.aibrix.ai/config: | | ||
| { | ||
| "defaultProfile": "least-request", | ||
| "profiles": { | ||
| "least-request": { | ||
| "routingStrategy": "least-request" | ||
| }, | ||
| "throughput": { | ||
| "routingStrategy": "throughput" | ||
| } | ||
| } | ||
| } | ||
| spec: | ||
| serviceAccountName: mocked-app-sa | ||
| containers: | ||
| - name: llm-engine | ||
| image: aibrix/vllm-mock:nightly | ||
| command: | ||
| - python3 | ||
| - app.py | ||
| - --api_key | ||
| - test-key-1234567890 | ||
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,162 @@ | ||
| .. _model_config_profiles: | ||
|
|
||
| ========================= | ||
| Model Config and Profiles | ||
| ========================= | ||
|
|
||
| This design describes how to supply **model/gateway configuration** (routing strategy, PD bucket bounds, combined mode, etc.) via a **single annotation** (or ConfigMap), with support for **multiple named profiles** selectable at **runtime** by the client. | ||
|
|
||
| Motivation | ||
| ---------- | ||
|
|
||
| Today, options are encoded as many pod labels (e.g. ``model.aibrix.ai/name``, ``model.aibrix.ai/port``, ``model.aibrix.ai/routing-strategy``, ``prompt-min-length``, etc.). Adding new options requires new labels and gateway changes to read them. This does not scale. Using a single structured annotation with **multiple profiles** allows: | ||
|
|
||
| * One place to add new options (extend the JSON schema). | ||
| * Different configurations for the same model (e.g. ``default``, ``pd``, ``low-latency``) selectable per request via a header. | ||
|
|
||
| Overview | ||
| -------- | ||
|
|
||
| * **Annotation** (on the pod): ``model.aibrix.ai/config`` holds a JSON object with a ``profiles`` map. Each profile is a set of gateway options: ``routingStrategy``, ``promptLenBucketMinLength``, ``promptLenBucketMaxLength``, ``combined``. | ||
| * **Runtime selection**: Client sends header ``config-profile: <profile-name>`` (e.g. ``pd``, ``low-latency``). If omitted, the ``defaultProfile`` (or ``"default"``) is used. | ||
|
|
||
| JSON Schema (Implementation) | ||
| ---------------------------- | ||
|
|
||
| The implementation parses the following structure. Extra fields (e.g. ``name``, ``port``, ``engine``) in the JSON are ignored. | ||
|
|
||
| Root object: | ||
|
|
||
| * ``defaultProfile`` (string, optional): Profile name to use when header is empty or profile not found. Default: ``"default"``. | ||
| * ``profiles`` (object, required): Map of profile name → profile object. | ||
|
|
||
| Profile object (``ModelConfigProfile``): | ||
|
|
||
| * ``routingStrategy`` (string): e.g. ``random``, ``pd``, ``least-latency``. | ||
| * ``promptLenBucketMinLength`` (int, optional): Lower bound for bucketing. Default: ``0``. If negative, normalized to ``0``. | ||
| * ``promptLenBucketMaxLength`` (int, optional): Upper bound for bucketing. Default: ``math.MaxInt32`` when ``0`` or omitted. | ||
| * ``combined`` (bool, optional): When true, indicates combined prefill/decode pod for PD routing. | ||
|
|
||
| Single profile (backward compatible): | ||
|
|
||
| .. code-block:: json | ||
|
|
||
| { | ||
| "profiles": { | ||
| "default": { | ||
| "routingStrategy": "pd", | ||
| "promptLenBucketMinLength": 0, | ||
| "promptLenBucketMaxLength": 2048 | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Multiple profiles with default: | ||
|
|
||
| .. code-block:: json | ||
|
|
||
| { | ||
| "defaultProfile": "pd", | ||
| "profiles": { | ||
| "default": { | ||
| "routingStrategy": "random", | ||
| "promptLenBucketMinLength": 0, | ||
| "promptLenBucketMaxLength": 4096 | ||
| }, | ||
| "pd": { | ||
| "routingStrategy": "pd", | ||
| "promptLenBucketMinLength": 0, | ||
| "promptLenBucketMaxLength": 2048 | ||
| }, | ||
| "low-latency": { | ||
| "routingStrategy": "least-latency", | ||
| "promptLenBucketMinLength": 0, | ||
| "promptLenBucketMaxLength": 2048 | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Runtime Behavior | ||
| ---------------- | ||
|
|
||
| 1. Gateway resolves config from pod annotation ``model.aibrix.ai/config``. ConfigMap lookup is not yet implemented. If no annotation, fall back to existing label-based resolution. | ||
| 2. Gateway reads ``config-profile`` from request headers. If missing, use ``defaultProfile`` from the JSON, or ``"default"``. | ||
| 3. Gateway selects the profile via ``GetProfile(profileName)``: exact match first, then fallback to ``defaultProfile``, then ``"default"``. | ||
| 4. The resolved profile is stored on ``RoutingContext.ConfigProfile`` (``ResolvedConfigProfile``) for the request. | ||
| 5. Routing strategy is derived from: request headers → ``ConfigProfile.RoutingStrategy`` → env ``ROUTING_ALGORITHM``. | ||
| 6. PD router uses ``ResolveProfileFromPod(pod, routingCtx.ReqConfigProfile)`` with fallback to the default profile; prompt bounds and ``combined`` are read from the selected profile. | ||
|
|
||
| Annotation Example (StormService pod template) | ||
| ---------------------------------------------- | ||
|
|
||
| .. code-block:: yaml | ||
|
|
||
| template: | ||
| metadata: | ||
| labels: | ||
| app: sglang-qwen3-8b-1p1d-0-2k | ||
| model.aibrix.ai/name: qwen3-8B | ||
| annotations: | ||
| prometheus.io/scrape: "true" | ||
| prometheus.io/port: "30000" | ||
| prometheus.io/path: "/metrics" | ||
| model.aibrix.ai/config: | | ||
| { | ||
| "defaultProfile": "pd", | ||
| "profiles": { | ||
| "default": { | ||
| "routingStrategy": "random", | ||
| "promptLenBucketMinLength": 0, | ||
| "promptLenBucketMaxLength": 4096 | ||
| }, | ||
| "pd": { | ||
| "routingStrategy": "pd", | ||
| "promptLenBucketMinLength": 0, | ||
| "promptLenBucketMaxLength": 2048 | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Client Usage | ||
| ------------ | ||
|
|
||
| * Use default profile: do not set any header (or set ``config-profile: default``). | ||
| * Use a specific profile: set header ``config-profile: pd`` or ``config-profile: low-latency``. | ||
|
|
||
| Implementation | ||
| ------------- | ||
|
|
||
| Package: ``pkg/plugins/gateway/configprofiles/`` | ||
|
|
||
| * ``ModelConfigProfile``: struct with ``RoutingStrategy``, ``PromptLenBucketMinLength``, ``PromptLenBucketMaxLength``, ``Combined``. | ||
| * ``ModelConfigProfiles``: struct with ``DefaultProfile``, ``Profiles map[string]ModelConfigProfile``. | ||
| * ``ParseModelConfig(jsonStr)``: parses JSON; normalizes ``promptLenBucketMinLength`` (≥0) and ``promptLenBucketMaxLength`` (0→MaxInt32). | ||
| * ``GetProfile(name)``: returns profile by name; falls back to ``defaultProfile`` then ``"default"``. | ||
| * ``ResolveProfile(pods, headerProfile)``: iterates pods, returns first non-nil from ``ResolveProfileFromPod``. | ||
| * ``ResolveProfileFromPod(pod, headerProfile)``: reads ``model.aibrix.ai/config`` from pod, parses, returns ``GetProfile(headerProfile)``. | ||
| * Prompt length bounds normalization occurs in ``ParseModelConfig``: ``promptLenBucketMinLength`` (<0 → 0), ``promptLenBucketMaxLength`` (0 → ``math.MaxInt32``). | ||
|
|
||
| Constants: ``ModelAnnoConfig`` (pkg/constants/model.go), ``HeaderConfigProfile`` (pkg/plugins/gateway/types.go). | ||
|
|
||
| Gateway flow: | ||
|
|
||
| * ``HandleRequestHeaders``: captures ``config-profile`` into ``ReqConfigProfile``. | ||
| * ``HandleRequestBody``: calls ``applyConfigProfile`` which resolves config from pod annotation, sets ``routingCtx.ConfigProfile``, and provides routing strategy to ``deriveRoutingStrategyFromContext``. | ||
| * ``deriveRoutingStrategyFromContext``: chooses the routing strategy for the request using this precedence: (1) request header ``routing-strategy`` if present and non-empty; (2) ``routingCtx.ConfigProfile.RoutingStrategy`` from the resolved profile (config-profile + pod annotation); (3) environment default. Returns the strategy and whether it was explicitly set (used to validate and set ``routingCtx.Algorithm`` in ``HandleRequestBody``). | ||
|
|
||
| PD router: | ||
|
|
||
| * ``isPodSuitableForPromptLength(routingCtx, pod, promptLength)``: uses ``ResolveProfileFromPod(pod, routingCtx.ReqConfigProfile)`` for ``promptLenBucketMinLength``/``promptLenBucketMaxLength``. | ||
| * ``isCombinedPod(routingCtx, pod)``: uses ``ResolveProfileFromPod(pod, routingCtx.ReqConfigProfile)`` for ``combined``. | ||
|
|
||
| Backward Compatibility | ||
| ---------------------- | ||
|
|
||
| If no annotation is present, ``ResolveProfile`` returns nil. Gateway continues to use existing pod labels and env for routing strategy, port, engine, etc. | ||
|
|
||
| Future Work | ||
| ---------- | ||
|
|
||
| * ConfigMap lookup (wire when gateway config supports it). | ||
| * Extend profile schema: ``port``, ``metricPort``, ``engine``, ``name`` for full parity with labels. | ||
| * Use request-level ``ConfigProfile`` (from ``config-profile``) for PD bucketing instead of per-pod ``"pd"`` profile. |
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.