Skip to content

Conversation

alec-flowers
Copy link
Contributor

@alec-flowers alec-flowers commented Jul 1, 2025

Overview:

Users noticed that vLLM wasn't working on main anymore. I investigated and a recent refactor introduce a bug - #1687.

A new RouterConfig is created, but since it is Option the default is None. Since register_llm keeps this default, we get a panic when we try to take() the value.

The fix is to add the default and a way to set at least part of the config from register_llm.

Summary by CodeRabbit

  • New Features
    • Added support for configuring router mode when registering a language model via Python, with available modes: RoundRobin, Random, and KV.
    • Introduced a new RouterMode class for specifying routing behavior during model registration.
    • The register_llm function now accepts an optional router_mode parameter to customize request routing.

Copy link

copy-pr-bot bot commented Jul 1, 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.

@alec-flowers alec-flowers changed the title fix default to None initialization of routing config fix: default to None initialization of routing config Jul 1, 2025
@github-actions github-actions bot added the fix label Jul 1, 2025
Copy link
Contributor

coderabbitai bot commented Jul 1, 2025

Walkthrough

A new RouterMode enum was introduced and exposed to Python, allowing users to specify routing behavior when registering language models. The register_llm function now accepts an optional router_mode argument, defaulting to RoundRobin if not provided. These changes are reflected in both the Rust implementation and Python interface.

Changes

File(s) Change Summary
lib/bindings/python/rust/lib.rs Added Python-exposed RouterMode enum and conversion to internal Rust type; updated register_llm to accept and use router_mode; added RouterMode to Python module.
lib/bindings/python/src/dynamo/_core.pyi Added RouterMode class with variants; updated register_llm signature to include optional router_mode parameter.

Sequence Diagram(s)

sequenceDiagram
    participant PythonUser
    participant PythonModule
    participant RustBackend

    PythonUser->>PythonModule: register_llm(..., router_mode=RouterMode.Random)
    PythonModule->>RustBackend: register_llm(..., router_mode=Random)
    RustBackend->>RustBackend: Convert RouterMode to internal type
    RustBackend->>RustBackend: Create RouterConfig with selected mode
    RustBackend-->>PythonModule: Registration result
    PythonModule-->>PythonUser: Return result
Loading

Poem

In the warren of code, a new path appears,
With routers that hop between modes, three peers.
RoundRobin, Random, or KV to choose,
Register your LLMs—no way to lose!
Now Python and Rust, in harmony sing,
Routing requests on a brand new spring. 🐇✨


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6365a01 and be5d23f.

📒 Files selected for processing (2)
  • lib/bindings/python/rust/lib.rs (5 hunks)
  • lib/bindings/python/src/dynamo/_core.pyi (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: PeaBrane
PR: ai-dynamo/dynamo#1285
File: lib/llm/src/kv_router/scoring.rs:58-63
Timestamp: 2025-05-30T06:38:09.630Z
Learning: In lib/llm/src/kv_router/scoring.rs, the user prefers to keep the panic behavior when calculating load_avg and variance with empty endpoints rather than adding guards for division by zero. They want the code to fail fast on this error condition.
lib/bindings/python/rust/lib.rs (1)
Learnt from: PeaBrane
PR: ai-dynamo/dynamo#1285
File: lib/llm/src/kv_router/scoring.rs:58-63
Timestamp: 2025-05-30T06:38:09.630Z
Learning: In lib/llm/src/kv_router/scoring.rs, the user prefers to keep the panic behavior when calculating load_avg and variance with empty endpoints rather than adding guards for division by zero. They want the code to fail fast on this error condition.
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Build and Test - vllm
  • GitHub Check: pre-merge-rust (lib/runtime/examples)
  • GitHub Check: pre-merge-rust (.)
  • GitHub Check: pre-merge-rust (lib/bindings/python)
🔇 Additional comments (11)
lib/bindings/python/src/dynamo/_core.pyi (2)

751-756: LGTM! Well-structured RouterMode class definition.

The RouterMode class is properly defined with clear class attributes representing the three routing modes. The type annotations follow Python typing conventions correctly.


757-757: LGTM! Backward-compatible function signature update.

The addition of the optional router_mode parameter maintains backward compatibility while providing the new routing configuration capability. The parameter placement at the end is appropriate.

lib/bindings/python/rust/lib.rs (9)

18-18: LGTM! Appropriate import for RouterMode type conversion.

The import correctly aliases the runtime RouterMode as RsRouterMode to avoid naming conflicts with the Python-exposed RouterMode enum.


24-25: LGTM! Required imports for RouterConfig functionality.

The imports for RouterConfig and KvRouterConfig are necessary for the new routing configuration feature.


26-32: LGTM! Well-defined Python-exposed RouterMode enum.

The RouterMode enum is properly defined with:

  • Correct pyclass annotations for Python exposure
  • Clear variant names matching the intended routing modes
  • Proper Clone and Debug derives for functionality

34-42: LGTM! Correct RouterMode type conversion implementation.

The From trait implementation correctly maps all RouterMode variants to their corresponding runtime types, ensuring proper type conversion between the Python interface and internal Rust types.


96-96: LGTM! RouterMode class properly exposed to Python.

The RouterMode class is correctly added to the Python module, making it available for use in Python code.


121-121: LGTM! Function signature properly updated with optional router_mode parameter.

The register_llm function signature correctly includes the new optional router_mode parameter while maintaining backward compatibility through the optional type.


131-131: LGTM! Parameter correctly added to function definition.

The router_mode parameter is properly typed as Optional and positioned appropriately in the function signature.


151-152: LGTM! RouterConfig properly integrated into LocalModelBuilder.

The router_config is correctly set on the LocalModelBuilder, completing the integration of the routing configuration feature. The placement after other configuration parameters is appropriate.


142-143: Confirmed sensible defaults in KvRouterConfig::default()

The impl Default for KvRouterConfig (lib/llm/src/kv_router.rs:73–81) sets all three routing weights to 1.0:

  • overlap_score_weight: 1.0
  • gpu_cache_usage_weight: 1.0
  • waiting_requests_weight: 1.0

This ensures equal weighting when no custom configuration is provided. No further changes are required.


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.

@alec-flowers alec-flowers force-pushed the aflowers/fix-register-llm-routing branch from be5d23f to 418be13 Compare July 1, 2025 05:23
Copy link
Contributor

@biswapanda biswapanda left a comment

Choose a reason for hiding this comment

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

approved to unblock main

@grahamking
Copy link
Contributor

Can you check Biswa's comment about all the strings being 'RouterMode'? Apart from that LGTM.

@alec-flowers alec-flowers merged commit 0a32b34 into main Jul 1, 2025
10 checks passed
@alec-flowers alec-flowers deleted the aflowers/fix-register-llm-routing branch July 1, 2025 17:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants