Skip to content

Conversation

CatherineSue
Copy link
Collaborator

@CatherineSue CatherineSue commented Oct 6, 2025

Motivation

Problem Identified

Proto3 numeric defaults (0) don't match Python SamplingParams semantic defaults (temperature=1.0, top_p=1.0, top_k=-1, repetition_penalty=1.0, etc.), which could cause incorrect behavior if proto fields are used directly.

Design Philosophy Chosen

Single source of truth: Rust constructs proto messages with proper defaults → Python trusts and uses values directly (no defensive checks)

Modifications

1. Proto Field Design (sglang_scheduler.proto)

  • Optional fields: max_new_tokens and stream_interval (semantically optional)
  • Removed unused fields: lora_path, token_healing
  • Added warning comment: Don't use ::default() directly - proto3 defaults don't match semantics

2. Rust Client (sgl-router/src/grpc_client/sglang_scheduler.rs)

  • Sets explicit defaults for all fields:
    • temperature: 1.0, top_p: 1.0, top_k: -1, repetition_penalty: 1.0
    • skip_special_tokens: true, spaces_between_special_tokens: true
    • n: 1
    • (by grpc default): min_new_tokens: 0, ignore_eos: false, no_stop_trim: false

3. Python Server (grpc_server.py)

  • Direct pass-through: Removed all or checks that would break on valid 0 values
    • Before (WRONG): temperature=grpc_params.temperature or 1.0 (breaks when temperature=0.0 for greedy sampling)
    • After (CORRECT): temperature=grpc_params.temperature
  • Added missing conversions: logit_bias, custom_params, stream_interval, no_stop_trim
  • Fixed semantic defaults: Convert empty repeated fields to None (not [])
    • stop=list(grpc_params.stop) if grpc_params.stop else None
    • stop_token_ids=list(grpc_params.stop_token_ids) if grpc_params.stop_token_ids else None

Accuracy Tests

Benchmarking and Profiling

Checklist

- Remove unused fields: `lora_path`, `token_healing`
- Make Rust always set explicit defaults (temperature=1.0, top_p=1.0,
etc.)
- Fix Python conversion to trust proto values directly (no defensive
checks)
- Fix temperature=0.0 bug from `or` operator override
- Convert empty repeated fields to None for `stop`/`stop_token_ids`
- Add missing conversions: `logit_bias`, `custom_params`,
`stream_interval`, `no_stop_trim`
- Make `stream_interval` optional, renumber proto fields 1-23
Copy link
Contributor

Summary of Changes

Hello @CatherineSue, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a critical issue concerning the handling of default values for sampling parameters in the gRPC interface between the Rust client and Python server. Previously, the implicit numeric defaults of Proto3 (e.g., 0) clashed with the explicit semantic defaults expected by the Python SamplingParams (e.g., temperature=1.0), leading to potential misconfigurations. The solution establishes a robust "single source of truth" by having the Rust client explicitly set all semantic default values when creating proto messages. Consequently, the Python server now directly consumes these values, removing the need for defensive or checks and ensuring consistent, correct behavior across the system. Additionally, the proto definition has been cleaned up by removing unused fields and making semantically optional fields explicit.

Highlights

  • Proto3 Default Mismatch Resolution: Addressed the discrepancy between Proto3's numeric defaults (0) and Python's SamplingParams semantic defaults (e.g., temperature=1.0, top_p=1.0), which previously caused incorrect behavior.
  • Single Source of Truth for Defaults: Implemented a design where the Rust client explicitly constructs proto messages with proper semantic defaults, allowing the Python server to trust and use these values directly without defensive checks.
  • Proto Definition Refinements: Marked max_new_tokens and stream_interval as optional, removed unused fields (lora_path, token_healing), and added a warning comment in sglang_scheduler.proto to prevent direct use of proto3 defaults.
  • Python Server Simplification: Eliminated redundant or <default_value> checks in grpc_server.py and added necessary conversions for logit_bias, custom_params, stream_interval, and no_stop_trim, ensuring correct handling of None for empty repeated fields.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request addresses a critical issue with default value mismatches between Protobuf and Python for sampling parameters. The approach of making Rust the single source of truth for defaults and removing defensive checks in Python is sound. The changes in the .proto files and the Rust client are well-executed and include helpful comments and tests.

I've found one issue in the Python gRPC server where optional fields are not handled correctly, which could lead to incorrect default values being used. My review includes a suggestion to fix this, ensuring the defaults from SGLSamplingParams are correctly applied when parameters are not explicitly set.

@slin1237 slin1237 merged commit a578d30 into main Oct 7, 2025
66 of 75 checks passed
@slin1237 slin1237 deleted the chang/stream branch October 7, 2025 01:54
PrinsYin pushed a commit to PrinsYin/sglang that referenced this pull request Oct 7, 2025
ch-tiger1 pushed a commit to ch-tiger1/sglang that referenced this pull request Oct 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants