Skip to content

Conversation

@faradawn
Copy link
Contributor

@faradawn faradawn commented Jun 22, 2025

Overview:

On the SGLang side, kv event emitting has been implemented: sgl-project/sglang#6824

This PR wires up the Dynamo side.

Details:

KV router can be spun up successfully

/workspace/examples/sglang
dynamo serve graphs.agg:Frontend -f ./configs/agg.yaml --Frontend.router=kv

╭──────────────── Dynamo Serve ────────────────╮
│ Starting Dynamo service: graphs.agg:Frontend │
╰──────────────────────────────────────────────╯
2025-06-22T23:27:16.491Z  INFO resource._discover_gpus: Discovered 1 GPUs   
2025-06-22T23:27:16.491Z  INFO resource._discover_gpus: Discovered 1 GPUs   
2025-06-22T23:27:16.492Z  INFO allocator.get_resource_envs: Getting resource envs for service Frontend   
2025-06-22T23:27:16.492Z  INFO allocator.get_resource_envs: Using configured worker count: 1   
2025-06-22T23:27:16.492Z  INFO allocator.get_resource_envs: Final resource allocation - workers: 1, envs: []   
2025-06-22T23:27:16.492Z  INFO serving.serve_dynamo_graph: Serving dynamo graph with namespace dynamo   
2025-06-22T23:27:16.492Z  INFO serving.serve_dynamo_graph: Clearing namespace dynamo before serving   
2025-06-22T23:27:16.492Z  INFO allocator.get_resource_envs: Getting resource envs for service SGLangWorker   
2025-06-22T23:27:16.492Z  INFO allocator.get_resource_envs: GPU requirement found: 1   
2025-06-22T23:27:16.492Z  INFO allocator.get_resource_envs: Using configured worker count: 1   
2025-06-22T23:27:16.493Z  INFO allocator.get_resource_envs: GPU allocation enabled   
2025-06-22T23:27:16.493Z  INFO allocator.get_resource_envs: Local deployment detected. Allocating GPUs for 1 

...

2025-06-22T23:29:03.877Z  INFO dynamo_llm::kv_router: KV Routing initialized
2025-06-22T23:29:04.679Z  INFO dynamo_llm::discovery::watcher: added model model_name="deepseek-ai/DeepSeek-R1-Distill-Llama-8B"
2025-06-22T23:30:13.674Z  INFO scheduler.log_prefill_stats: Prefill batch. #new-seq: 1, #new-token: 16, #cached-token: 0, token usage: 0.00, #running-req: 0, #queue-req: 0   

Where should the reviewer start?

Related Issues: (use one of the action keywords Closes / Fixes / Resolves / Relates to)

Summary by CodeRabbit

  • New Features
    • Added support for runtime metrics publishing and event publishing in the SGLang worker component.
    • Introduced a configurable router mode for the frontend service, with a new command-line option and documentation example.
  • Documentation
    • Updated the README with instructions for using the new router option in aggregated serving mode.
  • Chores
    • Updated configuration files and underlying dependencies to support new features, including a new page-size parameter and updated commit references.

@copy-pr-bot
Copy link

copy-pr-bot bot commented Jun 22, 2025

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@faradawn faradawn requested a review from a team as a code owner June 22, 2025 23:50
@github-actions
Copy link

👋 Hi faradawn! Thank you for contributing to ai-dynamo/dynamo.

Just a reminder: The NVIDIA Test Github Validation CI runs an essential subset of the testing framework to quickly catch errors.Your PR reviewers may elect to test the changes comprehensively before approving your changes.

🚀

@github-actions github-actions bot added external-contribution Pull request is from an external contributor feat labels Jun 22, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 22, 2025

Walkthrough

This update introduces runtime metrics publishing and ZMQ KV event publishing capabilities to the SGLang worker, adds a configurable router mode to the frontend, and updates the deployment example documentation to reflect these new features. The Dockerfile and configuration files are also updated to support the new functionality.

Changes

File(s) Change Summary
container/Dockerfile.sglang Updated the sglang package installation to use a commit that includes ZMQ KV event publisher support.
examples/sglang/README.md Added documentation for running aggregated deployment with router mode enabled.
examples/sglang/components/frontend.py Introduced a router parameter in the frontend config and passed it as a command-line argument to the ingress/processor subprocess.
examples/sglang/components/worker.py Added metrics publishing, ZMQ KV event publisher integration, and enhanced LLM registration with cache block size.
examples/sglang/configs/agg.yaml Added page-size parameter to the SGLangWorker configuration section.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Frontend
    participant Worker
    participant MetricsPublisher
    participant ZmqKvEventPublisher

    User->>Frontend: Send request (specifying router mode)
    Frontend->>Worker: Forward request
    Worker->>Worker: _update_metrics()
    Worker->>MetricsPublisher: Publish updated metrics
    Worker->>ZmqKvEventPublisher: Publish KV events
    Worker-->>Frontend: Return response
    Frontend-->>User: Return result
Loading

Possibly related PRs

Poem

A rabbit hops through YAML and code,
Metrics and events now easily flowed.
With routers that choose and workers that tell,
The system now hums and runs very well.
🐇✨
Docker and docs keep it all in line—
Aggregated, routed, everything’s fine!


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
examples/sglang/components/worker.py (1)

68-80: Placeholder metrics need implementation.

The TODO comments correctly identify that these metrics are using placeholder/random values. Ensure these are replaced with actual engine metrics before production use.

Would you like me to help identify the correct SGLang engine APIs to retrieve these metrics or open an issue to track this implementation?

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1065ff1 and f200541.

📒 Files selected for processing (5)
  • container/Dockerfile.sglang (1 hunks)
  • examples/sglang/README.md (1 hunks)
  • examples/sglang/components/frontend.py (2 hunks)
  • examples/sglang/components/worker.py (4 hunks)
  • examples/sglang/configs/agg.yaml (1 hunks)
🧰 Additional context used
🪛 Pylint (3.3.7)
examples/sglang/components/worker.py

[error] 89-89: Class 'SGLangWorker' has no 'dynamo_address' member

(E1101)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build and Test - vllm
🔇 Additional comments (5)
container/Dockerfile.sglang (1)

138-139: LGTM!

The sglang commit update to include ZMQ KV event publisher aligns perfectly with the PR's objective of integrating KV router functionality.

examples/sglang/configs/agg.yaml (1)

23-23: LGTM!

The page-size parameter appropriately configures the KV cache block size for the worker.

examples/sglang/README.md (1)

74-79: LGTM!

Clear documentation of the new KV router option with a practical example command.

examples/sglang/components/frontend.py (1)

48-48: LGTM!

The configurable router mode with "round-robin" default provides flexibility while maintaining backward compatibility.

Also applies to: 85-86

examples/sglang/components/worker.py (1)

38-44: Well-implemented KV router integration!

The metrics publishing and ZMQ KV event publisher setup correctly supports the KV router functionality. The integration with the existing worker lifecycle is clean and follows best practices.

Also applies to: 65-66, 82-84, 91-115, 127-137, 173-173

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 23, 2025

Walkthrough

This update introduces metrics publishing and ZMQ KV event publishing to the SGLang worker, adds a configurable router mode for the frontend, and updates documentation and configuration files to reflect these new options. The Dockerfile is updated to use a newer SGLang commit supporting these features.

Changes

File(s) Change Summary
container/Dockerfile.sglang Updated SGLang commit reference and comment to a version with ZMQ KV event publisher support.
examples/sglang/README.md Added documentation for running with aggregated router mode via a new command-line flag.
examples/sglang/components/frontend.py Added router config field and passed it as a command-line argument to the frontend subprocess.
examples/sglang/components/worker.py Integrated metrics publishing, ZMQ KV event publisher, and updated worker lifecycle and request handling.
examples/sglang/configs/agg.yaml Added page-size parameter to the SGLangWorker configuration section.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Frontend
    participant SGLangWorker
    participant MetricsPublisher
    participant ZmqKvEventPublisher

    User->>Frontend: Send request (with router mode)
    Frontend->>SGLangWorker: Forward request
    SGLangWorker->>SGLangWorker: _update_metrics()
    SGLangWorker->>MetricsPublisher: Publish metrics
    SGLangWorker->>ZmqKvEventPublisher: Relay KV events (if any)
    SGLangWorker->>Frontend: Return response
    Frontend->>User: Return response
Loading

Possibly related PRs

Poem

In the warren where code does hop,
Metrics now publish with every stop.
KV events leap through ZMQ’s gate,
Routers configurable—oh, isn’t that great?
With YAML and docs all up to date,
This bunny’s proud of the state!
🥕✨


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
examples/sglang/configs/agg.yaml (1)

23-23: Configuration looks good. Consider adding documentation.

The page-size parameter correctly configures the KV cache block size for the worker.

Consider adding a comment to document what this parameter controls:

 SGLangWorker:
   model-path: deepseek-ai/DeepSeek-R1-Distill-Llama-8B
   served-model-name: deepseek-ai/DeepSeek-R1-Distill-Llama-8B
+  # KV cache block size for memory management
   page-size: 16
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1065ff1 and f200541.

📒 Files selected for processing (5)
  • container/Dockerfile.sglang (1 hunks)
  • examples/sglang/README.md (1 hunks)
  • examples/sglang/components/frontend.py (2 hunks)
  • examples/sglang/components/worker.py (4 hunks)
  • examples/sglang/configs/agg.yaml (1 hunks)
🧰 Additional context used
🪛 Pylint (3.3.7)
examples/sglang/components/worker.py

[error] 89-89: Class 'SGLangWorker' has no 'dynamo_address' member

(E1101)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build and Test - vllm
🔇 Additional comments (10)
container/Dockerfile.sglang (1)

138-139: LGTM! Dependency update for KV event publishing support.

The SGLang commit update is well-documented and aligns with the PR objectives to integrate KV router functionality.

Please verify that this specific commit is stable and tested:

Is SGLang commit 777688b8929c877e4e28c2eac208d776abe4c3af from PR #68244 stable and ready for production use?
examples/sglang/components/frontend.py (2)

48-48: Router configuration properly implemented.

The router field with "round-robin" default provides a clean way to configure routing modes.


85-86: Command line argument passing looks correct.

The router mode is properly passed to the dynamo-run subprocess.

examples/sglang/README.md (1)

74-79: Documentation clearly explains KV router usage.

The new section properly demonstrates how to enable the KV router mode using the command line flag.

examples/sglang/components/worker.py (6)

38-44: Import additions look good.

The new imports for metrics and KV event publishing are properly organized.


65-66: Metrics publisher initialization is correct.

The WorkerMetricsPublisher is properly instantiated in the constructor.


82-84: Async endpoint creation pattern looks good.

The method properly uses the dynamo context to create the metrics endpoint.


91-115: LLM registration and metrics initialization properly implemented.

The addition of kv_cache_block_size parameter and initial metrics publishing are correct. The async task creation for the metrics endpoint is a good pattern.


127-137: ZMQ KV Event Publisher configuration looks correct.

The publisher is properly configured with worker ID and KV block size. Keeping a reference to prevent garbage collection is a good practice.


173-173: Metrics update on request processing.

Calling _update_metrics at the start of request processing ensures metrics are current.

@ishandhanani
Copy link
Contributor

Nice @faradawn - this looks great.

I see some TODO's around grabbing engine metrics. There's actually a few in-flight PR's for this on our side and the SGLang side. Goal is to merge them in this week.

In the meantime - in the README can you go ahead and call out those TODOs in a >note just so that users are aware? And can you hyperlink

Once these are in - I/we can double back and update based on engine metrics.

LMK what you think

@faradawn
Copy link
Contributor Author

Hi @ishandhanani, I have added the pending PRs to the README as a note. Let me know if there are additional things to modify!

Copy link
Contributor

@alec-flowers alec-flowers left a comment

Choose a reason for hiding this comment

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

Thanks @faradawn. Lets try to make sure we get the metrics in as fast as possible as a follow up. Right now its not actually working.

@faradawn
Copy link
Contributor Author

Thanks @alec-flowers! I have added logger.warn and mentioned this in the README so that users will know.

@faradawn
Copy link
Contributor Author

faradawn commented Jun 24, 2025

Hi @ishandhanani and @alec-flowers, here is the log for kv router: 1) worker score calculation is working, 2) our placeholder warning is shown. Let me know if there is any issue!

dynamo serve graphs.agg:Frontend -f ./configs/agg.yaml --Frontend.router=kv

╭──────────────── Dynamo Serve ────────────────╮
│ Starting Dynamo service: graphs.agg:Frontend │
╰──────────────────────────────────────────────╯
...

2025-06-24T19:45:16.683Z  INFO dynamo_llm::kv_router: KV Routing initialized
2025-06-24T19:45:17.085Z DEBUG dynamo_llm::kv_router::metrics_aggregator: Found metrics endpoint

>>> First request 
2025-06-24T19:46:36.780Z DEBUG dynamo_llm::kv_router::scheduler: best worker logit is 0
2025-06-24T19:46:36.781Z DEBUG dynamo_llm::kv_router::scheduler: Selected worker: 7587887668485286697, logit: 0.000
2025-06-24T19:46:36.792Z  WARN worker._update_metrics: [SGLangWorker:1] Publishing placeholder metrics in SGLangWorker; these are NOT real engine metrics yet and will be replaced once upstream support lands.   
2025-06-24T19:46:36.794Z  INFO scheduler.log_prefill_stats: Prefill batch. #new-seq: 1, #new-token: 16, #cached-token: 0, token usage: 0.00, #running-req: 0, #queue-req: 0   
2025-06-24T19:47:53.603Z DEBUG _core::engine: finished processing python async generator stream request_id="eb99d066-7901-4b67-be5e-81b6fd465cb4"


>>> Second request
2025-06-24T19:48:07.965Z DEBUG dynamo_llm::kv_router::scheduler: Selected worker: 7587887668485286697, logit: -0.163
2025-06-24T19:48:07.969Z  INFO scheduler.log_prefill_stats: Prefill batch. #new-seq: 1, #new-token: 16, #cached-token: 0, token usage: 0.00, #running-req: 0, #queue-req: 0   
2025-06-24T19:48:07.967Z  WARN worker._update_metrics: [SGLangWorker:1] Publishing placeholder metrics in SGLangWorker; these are NOT real engine metrics yet and will be replaced once upstream support lands.   
2025-06-24T19:48:08.630Z  INFO scheduler.log_decode_stats: Decode batch. #running-req: 1, #token: 32, token usage: 0.00, cuda graph: True, gen throughput (token/s): 0.23, #queue-req: 0   
2025-06-24T19:48:09.763Z DEBUG _core::engine: finished processing python async generator stream request_id="36e5e933-48e6-4fa3-8966-adca933696ee"


Copy link
Contributor

@ishandhanani ishandhanani left a comment

Choose a reason for hiding this comment

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

Nice!

@faradawn
Copy link
Contributor Author

@ishandhanani and @alec-flowers do you know how to merge? I don't seem to have write access to the repo. Thanks!

@ishandhanani ishandhanani enabled auto-merge (squash) June 27, 2025 23:50
auto-merge was automatically disabled June 28, 2025 00:41

Head branch was pushed to by a user without write access

@ishandhanani ishandhanani merged commit 0b47f89 into ai-dynamo:main Jun 28, 2025
7 checks passed
atchernych pushed a commit that referenced this pull request Jul 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external-contribution Pull request is from an external contributor feat size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants