Skip to content

[Core] Implement sleep/wake_up for SpecDecodeWorker #20422

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kebe7jun
Copy link
Contributor

@kebe7jun kebe7jun commented Jul 3, 2025

Essential Elements of an Effective PR Description Checklist

  • The purpose of the PR, such as "Fix some issue (link existing issues this PR will resolve)".
  • The test plan, such as providing test command.
  • The test results, such as pasting the results comparison before and after, or e2e results
  • (Optional) The necessary documentation update, such as updating supported_models.md and examples for a new model.

Fix #20209 #19400

Purpose

Make sure to enter the sleep state when using speculative decoding.

Test Plan

Make sure that the following script works well.

from vllm import LLM, SamplingParams

prompts = [
    "The future of AI is",
]
sampling_params = SamplingParams(temperature=0.8, top_p=0.95)

llm = LLM(
    model="Qwen/Qwen2.5-3B-Instruct",
    tensor_parallel_size=1,
    speculative_config={
        "model": "Qwen/Qwen2.5-0.5B-Instruct",
        "num_speculative_tokens": 5,
    },
    enable_sleep_mode=True,
)

print(llm.generate(
    prompts=prompts,
    sampling_params=sampling_params,
))

llm.sleep(level=1)
llm.wake_up()
llm.reset_prefix_cache()
print(llm.generate(
    prompts=prompts,
    sampling_params=sampling_params,
))

Test Result

Logs:

...
INFO 07-04 01:44:00 [llm_engine.py:428] init engine (profile, create kv cache, warmup model) took 3.38 seconds
Adding requests: 100%|██████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00, 73.09it/s]
Processed prompts: 100%|████████████████████████████████████████| 1/1 [00:03<00:00,  3.15s/it, est. speed input: 1.59 toks/s, output: 5.09 toks/s]
[RequestOutput(request_id=0, prompt='The future of AI is', prompt_token_ids=[785, 3853, 315, 15235, 374], encoder_prompt=None, encoder_prompt_token_ids=None, prompt_logprobs=None, outputs=[CompletionOutput(index=0, text=' bright, but also uncertain. Which of the following statements is false?\nA.', token_ids=(9906, 11, 714, 1083, 35118, 13, 15920, 315, 279, 2701, 12239, 374, 895, 5267, 32, 13), cumulative_logprob=None, logprobs=None, finish_reason=length, stop_reason=None)], finished=True, metrics=RequestMetrics(arrival_time=1751593441.9057398, last_token_time=1751593445.0631874, first_scheduled_time=1751593441.921623, first_token_time=1751593442.0488722, time_in_queue=0.015883207321166992, finished_time=1751593445.0638692, scheduler_time=0.003490094022708945, model_forward_time=None, model_execute_time=None, spec_token_acceptance_counts=[5, 4, 4, 2, 2, 2]), lora_request=None, num_cached_tokens=0, multi_modal_placeholders={})]
calling sleep self.driver_worker=<vllm.worker.worker_base.WorkerWrapperBase object at 0x7f43dd629a90>
INFO 07-04 01:44:10 [spec_decode_worker.py:1318] Sleep mode freed 53.63 GiB memory, 17.44 GiB memory is still in use.
INFO 07-04 01:44:10 [executor_base.py:211] It took 4.975467 seconds to fall asleep.
INFO 07-04 01:44:10 [executor_base.py:227] It took 0.157232 seconds to wake up tags {'kv_cache', 'weights'}.
Adding requests: 100%|████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00, 1510.92it/s]
Processed prompts: 100%|██████████████████████████████████████| 1/1 [00:00<00:00,  3.19it/s, est. speed input: 15.95 toks/s, output: 51.03 toks/s]
[RequestOutput(request_id=1, prompt='The future of AI is', prompt_token_ids=[785, 3853, 315, 15235, 374], encoder_prompt=None, encoder_prompt_token_ids=None, prompt_logprobs=None, outputs=[CompletionOutput(index=0, text=' bright, but there are still hurdles to overcome. Can you provide a detailed analysis', token_ids=(9906, 11, 714, 1052, 525, 2058, 72535, 311, 22279, 13, 2980, 498, 3410, 264, 11682, 6358), cumulative_logprob=None, logprobs=None, finish_reason=length, stop_reason=None)], finished=True, metrics=RequestMetrics(arrival_time=1751593450.1997783, last_token_time=1751593450.5139823, first_scheduled_time=1751593450.2009227, first_token_time=1751593450.2378645, time_in_queue=0.0011444091796875, finished_time=1751593450.5141394, scheduler_time=0.0006611900025745854, model_forward_time=None, model_execute_time=None, spec_token_acceptance_counts=[5, 4, 4, 3, 2, 2]), lora_request=None, num_cached_tokens=0, multi_modal_placeholders={})]
[rank0]:[W704 01:44:11.217240564 ProcessGroupNCCL.cpp:1476] Warning: WARNING: destroy_process_group() was not called before program exit, which can leak resources. For more info, please see https://pytorch.org/docs/stable/distributed.html#shutdown (function operator())

Copy link

github-actions bot commented Jul 3, 2025

👋 Hi! Thank you for contributing to the vLLM project.

💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels.

Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run fastcheck CI which starts running only a small and essential subset of CI tests to quickly catch errors. You can run other CI tests on top of those by going to your fastcheck build on Buildkite UI (linked in the PR checks section) and unblock them. If you do not have permission to unblock, ping simon-mo or khluu to add you in our Buildkite org.

Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging.

To run CI, PR reviewers can either: Add ready label to the PR or enable auto-merge.

🚀

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.

Summary of Changes

Hello @kebe7jun, 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 introduces the ability for the speculative decoding worker to enter and exit a 'sleep' state, effectively managing GPU memory by freeing resources when the model is not actively processing requests and quickly restoring them when needed. This enhancement improves resource utilization, especially in scenarios where the model might be idle for periods.

Highlights

  • Sleep/Wake-up Functionality for Speculative Decoding: I've implemented sleep and wake_up methods within the SpecDecodeWorker class. These methods are crucial for enabling memory management capabilities, allowing the speculative decoding component to release GPU memory when idle and quickly re-allocate it when needed.
  • Delegation to Proposer Worker: The newly added sleep and wake_up methods in SpecDecodeWorker delegate their calls directly to the self.proposer_worker. This indicates that the underlying memory management logic for speculative decoding is handled by the proposer component.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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 issue 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 is currently in preview and 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 to provide feedback.

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 implements sleep and wake_up functionality for the SpecDecodeWorker. The implementation delegates these calls only to the proposer_worker (draft model) but should also call them on the scorer_worker (target model) to ensure memory is freed correctly.

@kebe7jun kebe7jun force-pushed the feature/spec-decode-worker-sleep branch from 6ece776 to b2c6fd3 Compare July 3, 2025 08:15
@kebe7jun kebe7jun marked this pull request as draft July 3, 2025 08:29
@kebe7jun kebe7jun force-pushed the feature/spec-decode-worker-sleep branch from b2c6fd3 to 5627cae Compare July 3, 2025 08:45
@kebe7jun kebe7jun marked this pull request as ready for review July 3, 2025 08:48
@kebe7jun kebe7jun marked this pull request as draft July 3, 2025 08:54
@njhill njhill added the v0 label Jul 3, 2025
Signed-off-by: Kebe <mail@kebe7jun.com>
@kebe7jun kebe7jun force-pushed the feature/spec-decode-worker-sleep branch from 5627cae to 377e8d2 Compare July 4, 2025 01:48
@kebe7jun kebe7jun marked this pull request as ready for review July 4, 2025 02:27
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.

[Bug]: When enable speculative decoding, sleep cannot work
2 participants