-
-
Notifications
You must be signed in to change notification settings - Fork 12k
[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
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
hmellor marked this conversation as resolved.
Show resolved
Hide resolved
|
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,85 @@ | ||||||||||||||||||||||
| # SPDX-License-Identifier: Apache-2.0 | ||||||||||||||||||||||
| # SPDX-FileCopyrightText: Copyright contributors to the vLLM project | ||||||||||||||||||||||
| import subprocess | ||||||||||||||||||||||
| import sys | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| import regex as re | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # --------------------------------------------------------------------------- # | ||||||||||||||||||||||
| # Regex: match `torch.cuda.xxx` but allow `torch.accelerator.xxx` | ||||||||||||||||||||||
| # --------------------------------------------------------------------------- # | ||||||||||||||||||||||
| _TORCH_CUDA_RE = re.compile(r"\btorch\.cuda\.empty_cache\b") | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ALLOWED_FILES = {"tests/", "benchmarks/", "vllm/platforms/*"} | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def is_allowed_file(current_file: str) -> bool: | ||||||||||||||||||||||
| return current_file in ALLOWED_FILES | ||||||||||||||||||||||
|
||||||||||||||||||||||
| ALLOWED_FILES = {"tests/", "benchmarks/", "vllm/platforms/*"} | |
| def is_allowed_file(current_file: str) -> bool: | |
| return current_file in ALLOWED_FILES | |
| ALLOWED_FILES = {"tests/", "benchmarks/", "vllm/platforms/"} | |
| def is_allowed_file(current_file: str) -> bool: | |
| return any(current_file.startswith(p) for p in ALLOWED_FILES) |
Outdated
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.
re.match only checks for a match at the beginning of the string. This will fail to detect forbidden API calls that are not at the start of a line (after stripping whitespace), for example x = torch.cuda.empty_cache(). You should use re.search to find a match anywhere in the line.
| def is_forbidden_torch_cuda_api(line: str) -> bool: | |
| stripped = line.strip() | |
| return bool(_TORCH_CUDA_RE.match(stripped)) | |
| def is_forbidden_torch_cuda_api(line: str) -> bool: | |
| return bool(_TORCH_CUDA_RE.search(line)) |
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.
We should pass file names, otherwise this will run on all files every commit