-
-
Notifications
You must be signed in to change notification settings - Fork 15.6k
[Hardware] Replace torch.cuda.empty_cache with torch.accelerator.empty_cache
#30681
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
hmellor
merged 20 commits into
vllm-project:main
from
jikunshang:kunshang/acc_empty_cache
Mar 4, 2026
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
a75b55a
replace torch.cuda.empty_cache with torch.accelerator.empty_cache
jikunshang d8f9a14
fix example files
jikunshang 2a007e7
address comments
jikunshang a2a28f2
address comments
jikunshang 2a176d0
fix file match
jikunshang 45cc883
replace more
jikunshang 935d901
replace in tests folder
jikunshang da73581
replace in benchmarks folder
jikunshang a24a4e7
more fix
jikunshang 97839d2
update allowed dir
jikunshang a9a9840
replace more
jikunshang 5101578
use re.finditer
jikunshang a595a4e
avoid call empty cache for cpu in dist cleanup
jikunshang d44ae78
refine
jikunshang 8cb62fd
add back torch._C._host_emptyCache() call
jikunshang 7e59fd4
replace more
jikunshang 55752ad
replace
jikunshang f5d55cd
Merge branch 'main' into kunshang/acc_empty_cache
hmellor 6cd9f92
Merge branch 'main' into kunshang/acc_empty_cache
hmellor 8b3a7df
Merge branch 'main' into kunshang/acc_empty_cache
jikunshang 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
Some comments aren't visible on the classic Files Changed page.
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
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,43 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # SPDX-FileCopyrightText: Copyright contributors to the vLLM project | ||
| import sys | ||
|
|
||
| import regex as re | ||
|
|
||
| # --------------------------------------------------------------------------- # | ||
| # Regex: match `torch.cuda.xxx` but allow `torch.accelerator.xxx` | ||
| # --------------------------------------------------------------------------- # | ||
| _TORCH_CUDA_PATTERNS = [ | ||
| r"\btorch\.cuda\.empty_cache\b", | ||
| ] | ||
|
|
||
| ALLOWED_FILES = {"vllm/platforms/", "vllm/device_allocator/"} | ||
|
|
||
|
|
||
| def scan_file(path: str) -> int: | ||
| with open(path, encoding="utf-8") as f: | ||
| content = f.read() | ||
| for pattern in _TORCH_CUDA_PATTERNS: | ||
| for match in re.finditer(pattern, content, re.MULTILINE): | ||
| # Calculate line number from match position | ||
| line_num = content[: match.start() + 1].count("\n") + 1 | ||
| print( | ||
| f"{path}:{line_num}: " | ||
| "\033[91merror:\033[0m " # red color | ||
| "Found torch.cuda API call" | ||
| ) | ||
| return 1 | ||
| return 0 | ||
|
|
||
|
|
||
| def main(): | ||
| returncode = 0 | ||
| for filename in sys.argv[1:]: | ||
| if any(filename.startswith(prefix) for prefix in ALLOWED_FILES): | ||
| continue | ||
| returncode |= scan_file(filename) | ||
| return returncode | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| sys.exit(main()) |
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
Oops, something went wrong.
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.