-
-
Notifications
You must be signed in to change notification settings - Fork 11.2k
[Chore] Separate out vllm.utils.platform_utils.py
#27374
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
Merged
Changes from all commits
Commits
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
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
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
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
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
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
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,54 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # SPDX-FileCopyrightText: Copyright contributors to the vLLM project | ||
|
|
||
| import multiprocessing | ||
| from collections.abc import Sequence | ||
| from concurrent.futures.process import ProcessPoolExecutor | ||
| from functools import cache | ||
| from typing import Any | ||
|
|
||
| import torch | ||
|
|
||
|
|
||
| def cuda_is_initialized() -> bool: | ||
| """Check if CUDA is initialized.""" | ||
| if not torch.cuda._is_compiled(): | ||
| return False | ||
| return torch.cuda.is_initialized() | ||
|
|
||
|
|
||
| def xpu_is_initialized() -> bool: | ||
| """Check if XPU is initialized.""" | ||
| if not torch.xpu._is_compiled(): | ||
| return False | ||
| return torch.xpu.is_initialized() | ||
|
|
||
|
|
||
| def cuda_get_device_properties( | ||
| device, names: Sequence[str], init_cuda=False | ||
| ) -> tuple[Any, ...]: | ||
| """Get specified CUDA device property values without initializing CUDA in | ||
| the current process.""" | ||
| if init_cuda or cuda_is_initialized(): | ||
| props = torch.cuda.get_device_properties(device) | ||
| return tuple(getattr(props, name) for name in names) | ||
|
|
||
| # Run in subprocess to avoid initializing CUDA as a side effect. | ||
| mp_ctx = multiprocessing.get_context("fork") | ||
| with ProcessPoolExecutor(max_workers=1, mp_context=mp_ctx) as executor: | ||
| return executor.submit(cuda_get_device_properties, device, names, True).result() | ||
|
|
||
|
|
||
| @cache | ||
| def is_pin_memory_available() -> bool: | ||
| from vllm.platforms import current_platform | ||
|
|
||
| return current_platform.is_pin_memory_available() | ||
|
|
||
|
|
||
| @cache | ||
| def is_uva_available() -> bool: | ||
| """Check if Unified Virtual Addressing (UVA) is available.""" | ||
| # UVA requires pinned memory. | ||
| # TODO: Add more requirements for UVA if needed. | ||
| return is_pin_memory_available() | ||
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
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hardcoding the multiprocessing start method to
"fork"is not portable and can cause issues on platforms like macOS or Windows whereforkis unavailable or unsafe. It's better to use the centralizedget_mp_contextutility for consistency and safety.To avoid a circular dependency (since
vllm.utilsimports this file), I recommend movingget_mp_contextand its helper_maybe_force_spawnfromvllm/utils/__init__.pyto this file (vllm/utils/hardware_utils.py). This change aligns with the goal of this PR to centralize hardware-related utilities.After moving the functions, you can change this line to use
get_mp_context(). You'll also need to:os,vllm.envs,vllm.logger,vllm.ray.lazy_utils) tovllm/utils/hardware_utils.py.vllm/utils/__init__.pyto importget_mp_contextfrom its new location.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think
get_mp_contextandmaybe_force_spawnare hardware utility functions. I think I can do a follow up to move these into their ownmultiprocessor.pyutil file and have that import thehardware_utilfunctions