Skip to content

Conversation

@hnyls2002
Copy link
Collaborator

@hnyls2002 hnyls2002 commented Oct 4, 2025

A step to merge #9334 into main.


This PR:

  • Remove the overlap thread in the overlap scheduler.
  • Use a CUDA stream to do overlap scheduling.
    • Forward stream's launch is always synchronized with the schedule stream(default stream)
    • Also, try to keep a reference for the recent two ModelWorkerBatch (maybe removed or replaced with cuda stream recording).
  • Unify the ForwardBatchOutput with GenerationBatchResult
  • Introduce delayed sample launch to handle grammar updates.

What to do next (in the following cleanup PR)

@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 Work In Progress pull request aims to streamline and refactor the system's overlap scheduling. It transitions the underlying mechanism to utilize explicit CUDA streams and events for asynchronous operations, enhancing control and potentially performance. The changes also involve centralizing related logic for sampling information and simplifying worker management, all as a preparatory step for merging a larger feature (#9334).

Highlights

  • Overlap Scheduling Refactor: The pull request refactors the overlap scheduling mechanism, moving from a previous thread-based approach to a more explicit asynchronous model leveraging CUDA streams and events.
  • CUDA Stream and FutureMap Integration: New CUDA streams (forward_stream, copy_stream) and a FutureMap are introduced to manage asynchronous batch processing and results, replacing older synchronization methods.
  • Centralized Sampling Info Preparation: Logic for preparing SamplingBatchInfo for forward passes, including penalty updates, has been centralized into a new copy_for_forward method within the SamplingBatchInfo class.
  • Removal of TpModelWorkerClient: The conditional instantiation of TpModelWorkerClient has been removed, with TpModelWorker now being used exclusively, indicating a consolidation of worker types.
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 refactors the overlap scheduling mechanism by removing the separate overlap thread and integrating its logic directly into the Scheduler. The changes involve using CUDA streams and events for synchronization, which simplifies the design. My review focuses on code correctness and cleanup opportunities. I've identified some dead code, a typo, and several FIXME comments that should be addressed. Overall, this is a good step towards simplifying the scheduling logic.

@hnyls2002 hnyls2002 requested a review from ByronHsu as a code owner October 4, 2025 15:20
@hnyls2002 hnyls2002 force-pushed the lsyin/remove-overlap-thread branch from a921488 to 5083846 Compare October 5, 2025 14:45
@hnyls2002 hnyls2002 requested a review from kssteven418 as a code owner October 5, 2025 14:45
@zhyncs zhyncs changed the title [WIP] Remove overlap thread. Remove overlap thread Oct 6, 2025
@hnyls2002 hnyls2002 force-pushed the lsyin/remove-overlap-thread branch from 30944bf to 1c1973b Compare October 6, 2025 14:40
@hnyls2002 hnyls2002 enabled auto-merge (squash) October 7, 2025 10:58
@hnyls2002 hnyls2002 disabled auto-merge October 7, 2025 12:11
@hnyls2002 hnyls2002 merged commit 1519a89 into main Oct 7, 2025
224 of 243 checks passed
@hnyls2002 hnyls2002 deleted the lsyin/remove-overlap-thread branch October 7, 2025 12:12
ch-tiger1 pushed a commit to ch-tiger1/sglang that referenced this pull request Oct 9, 2025
Co-authored-by: Lianmin Zheng <[email protected]>
Co-authored-by: Hanming Lu <[email protected]>
@yudian0504
Copy link
Contributor

yudian0504 commented Oct 21, 2025

It seems like after this PR got merged, I’ve run into the following error quite a few times—it happens pretty frequently, but I haven’t figured out a consistent way to reproduce it yet. Strangely, when I set CUDA_LAUNCH_BLOCKING=1, the issue seems to go away.


Scheduler hit an exception: Traceback (most recent call last):^M
  File "/opt/conda/lib/python3.10/site-packages/sglang/srt/managers/scheduler.py", line 2880, in run_scheduler_process^M
    scheduler.event_loop_overlap()^M
  File "/opt/conda/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 120, in decorate_context^M
    return func(*args, **kwargs)^M
  File "/opt/conda/lib/python3.10/site-packages/sglang/srt/managers/scheduler.py", line 981, in event_loop_overlap^M
    self.process_batch_result(tmp_batch, tmp_result)^M
  File "/opt/conda/lib/python3.10/site-packages/sglang/srt/managers/scheduler.py", line 2121, in process_batch_result^M
    self.process_batch_result_decode(batch, result)^M
  File "/opt/conda/lib/python3.10/site-packages/sglang/srt/managers/scheduler_output_processor_mixin.py", line 229, in process_batch_result_decode^M
    result.copy_done.synchronize()^M
  File "/opt/conda/lib/python3.10/site-packages/torch/cuda/streams.py", line 231, in synchronize^M
    super().synchronize()^M
torch.AcceleratorError: CUDA error: an illegal memory access was encountered^M
CUDA kernel errors might be asynchronously reported at some other API call, so the stacktrace below might be incorrect.^M
For debugging consider passing CUDA_LAUNCH_BLOCKING=1^M
Compile with `TORCH_USE_CUDA_DSA` to enable device-side assertions.^M

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.

7 participants