Skip to content

Introduce future indices#11301

Merged
hnyls2002 merged 4 commits intomainfrom
lsyin/introduce-future-indices
Oct 7, 2025
Merged

Introduce future indices#11301
hnyls2002 merged 4 commits intomainfrom
lsyin/introduce-future-indices

Conversation

@hnyls2002
Copy link
Collaborator

@hnyls2002 hnyls2002 commented Oct 7, 2025

A new abstraction: FutureIndices, current implementation uses a hacky way to process the future indices, i.e., storing them in the input_ids of ScheduleBatch and using negative numbers to identify which ones are futures.


  • FutureIndices should always be the only output of the forward stream.
  • It should support merging with non-future tensors and filtering.
  • Introduce this abstraction to prepare the future tensor in overlap-spec([POC] Overlap scheduler refactor with SD #9334)

@hnyls2002 hnyls2002 changed the base branch from main to lsyin/remove-overlap-thread October 7, 2025 11:51
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @hnyls2002, 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 significantly refactors the scheduling and execution pipeline to enhance performance through more effective overlap of CPU and GPU operations. It introduces a novel "future indices" concept and leverages CUDA streams to enable asynchronous processing, allowing for delayed sampling and more granular control over when and how batch results are processed. These changes aim to reduce idle times and improve the overall throughput of the system, especially in scenarios involving complex generation constraints like grammars.

Highlights

  • Asynchronous Overlap Scheduling: Implemented a new mechanism for overlapping CPU processing and GPU computation using CUDA streams, FutureIndices, and delayed sampling to enhance performance.
  • Introduction of Future Indices: A new FutureIndices dataclass and FutureMap utility are introduced to manage and resolve token IDs for future steps in the generation process, enabling non-blocking operations.
  • Refactored GenerationBatchResult: The GenerationBatchResult dataclass was enhanced to include CUDA events (copy_done), flags for delayed sampling, and references to ForwardBatch and FutureIndices for better overlap scheduling management.
  • Delayed Sampling for Optimization: Sampling of generated tokens can now be delayed, particularly when grammars are involved, to optimize the scheduling pipeline and improve concurrency.
  • Streamlined Result Processing: The launch_last_batch_sample_if_needed method centralizes the logic for handling delayed samples and processing batch results, improving the overall efficiency of the scheduler.
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 introduces a FutureIndices dataclass to encapsulate the logic for handling future token indices in overlap scheduling. This is a good refactoring that improves code clarity by replacing primitive types with a dedicated object. The changes primarily affect overlap_utils.py and scheduler.py. I've identified a critical issue in the implementation of store_to_map that would cause incorrect token resolution. The rest of the changes look good.

Base automatically changed from lsyin/remove-overlap-thread to main October 7, 2025 12:12
@hnyls2002 hnyls2002 force-pushed the lsyin/introduce-future-indices branch from a40d8ea to 7782a36 Compare October 7, 2025 12:23
@hnyls2002 hnyls2002 marked this pull request as draft October 7, 2025 12:24
@hnyls2002 hnyls2002 mentioned this pull request Oct 7, 2025
4 tasks
@hnyls2002 hnyls2002 marked this pull request as ready for review October 7, 2025 13:42
@hnyls2002 hnyls2002 force-pushed the lsyin/introduce-future-indices branch from df65001 to c6b1b1f Compare October 7, 2025 13:48
@hnyls2002 hnyls2002 merged commit 3ddd7dc into main Oct 7, 2025
57 of 63 checks passed
@hnyls2002 hnyls2002 deleted the lsyin/introduce-future-indices branch October 7, 2025 14:24
ch-tiger1 pushed a commit to ch-tiger1/sglang that referenced this pull request Oct 9, 2025
lpc0220 pushed a commit to lpc0220/sglang that referenced this pull request Oct 29, 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.

2 participants

Comments