-
Notifications
You must be signed in to change notification settings - Fork 77
Sleep mode support #584
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
Merged
xuechendi
merged 10 commits into
vllm-project:main
from
Kacper-Pietkun:dev/kpietkun/sleep_mode
Dec 4, 2025
Merged
Sleep mode support #584
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
43c9d88
sleep mode level 1
Kacper-Pietkun 0ecf4b8
fix for defragmenter
Kacper-Pietkun e53b689
add test asserts and add it to bash script
Kacper-Pietkun 934a1bf
Merge branch 'main' into dev/kpietkun/sleep_mode
Kacper-Pietkun 776613d
pre-commit fix
Kacper-Pietkun 2314cce
Stylistic change
Kacper-Pietkun 8f10fcd
add msg
Kacper-Pietkun 775fe16
Merge branch 'main' into dev/kpietkun/sleep_mode
Kacper-Pietkun e1ac645
Change test location
Kacper-Pietkun acb3664
Merge branch 'main' into dev/kpietkun/sleep_mode
Kacper-Pietkun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # SPDX-FileCopyrightText: Copyright contributors to the vLLM project | ||
|
|
||
| import os | ||
| from vllm import LLM, EngineArgs | ||
| from vllm.utils.argparse_utils import FlexibleArgumentParser | ||
| from vllm_gaudi.extension.profiler import HabanaMemoryProfiler | ||
|
|
||
|
|
||
| def create_parser(): | ||
| parser = FlexibleArgumentParser() | ||
| # Add engine args | ||
| EngineArgs.add_cli_args(parser) | ||
| parser.set_defaults(model="meta-llama/Llama-3.2-1B-Instruct", enforce_eager=False) | ||
| return parser | ||
|
|
||
|
|
||
| def print_outputs(outputs): | ||
| print("-" * 50) | ||
| for output in outputs: | ||
| prompt = output.prompt | ||
| generated_text = output.outputs[0].text | ||
| print(f"Prompt: {prompt!r}\nGenerated text: {generated_text!r}") | ||
| print("-" * 50) | ||
|
|
||
|
|
||
| def assert_model_device(model_runner, targert_device): | ||
| if model_runner: | ||
| params_devices = list(set([p.device for p in model_runner.model.parameters()])) | ||
| assert len(params_devices) == 1 | ||
| assert params_devices[0].type == targert_device | ||
|
|
||
|
|
||
| def main(args): | ||
| """ | ||
| Test script to actually instantiate HPUWorker and test sleep/wakeup functionality. | ||
| This test creates a real HPUWorker instance and calls the methods. | ||
| """ | ||
| llm = LLM(**args) | ||
|
|
||
| prompts = [ | ||
| "Hello, my name is", | ||
| "The president of the United States is", | ||
| "The capital of France is", | ||
| "The future of AI is", | ||
| ] | ||
|
|
||
| multiproc = os.getenv("VLLM_ENABLE_V1_MULTIPROCESSING") | ||
| model_runner = None | ||
| if multiproc == "0": | ||
| model_runner = llm.llm_engine.model_executor.driver_worker.worker.model_runner | ||
|
|
||
| outputs = llm.generate(prompts) | ||
| print_outputs(outputs) | ||
|
|
||
| for i in range(3): | ||
| with HabanaMemoryProfiler() as m: | ||
| llm.sleep() | ||
| assert m.consumed_device_memory < -60 * 1024 * 1024 * 1024 # check if more than 60GB was freed | ||
| assert_model_device(model_runner, "cpu") | ||
|
|
||
| with HabanaMemoryProfiler() as m: | ||
| llm.wake_up(["weights", "kv_cache"]) | ||
| assert m.consumed_device_memory > 60 * 1024 * 1024 * 1024 # check if more than 60GB was allocated | ||
| assert_model_device(model_runner, "hpu") | ||
|
|
||
| outputs = llm.generate(prompts) | ||
| print_outputs(outputs) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| parser = create_parser() | ||
| args: dict = vars(parser.parse_args()) | ||
| try: | ||
| main(args) | ||
| except Exception: | ||
| import traceback | ||
| print("An error occurred during generation:") | ||
| traceback.print_exc() | ||
| os._exit(1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.