-
-
Notifications
You must be signed in to change notification settings - Fork 7.2k
[Bugfix] Fix vllm_flash_attn rotary import #17247
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
Conversation
Signed-off-by: Jee Jee Li <[email protected]>
👋 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 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 🚀 |
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.
One slight change
setup.py
Outdated
src_layers = os.path.join(self.build_lib, "vllm", "vllm_flash_attn", | ||
"layers") | ||
dst_layers = os.path.join("vllm", "vllm_flash_attn", "layers") | ||
if os.path.exists(src_layers): | ||
print(f"Copying directory {src_layers} to {dst_layers}") | ||
if os.path.exists(dst_layers): | ||
shutil.rmtree(dst_layers) | ||
shutil.copytree(src_layers, dst_layers) | ||
|
||
# copy vllm_flash_attn/ops dir | ||
src_ops = os.path.join(self.build_lib, "vllm", "vllm_flash_attn", | ||
"ops") | ||
dst_ops = os.path.join("vllm", "vllm_flash_attn", "ops") | ||
if os.path.exists(src_ops): | ||
print(f"Copying directory {src_ops} to {dst_ops}") | ||
if os.path.exists(dst_ops): | ||
shutil.rmtree(dst_ops) | ||
shutil.copytree(src_ops, dst_ops) |
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.
You should use self.copy_tree
instead
src_layers = os.path.join(self.build_lib, "vllm", "vllm_flash_attn", | |
"layers") | |
dst_layers = os.path.join("vllm", "vllm_flash_attn", "layers") | |
if os.path.exists(src_layers): | |
print(f"Copying directory {src_layers} to {dst_layers}") | |
if os.path.exists(dst_layers): | |
shutil.rmtree(dst_layers) | |
shutil.copytree(src_layers, dst_layers) | |
# copy vllm_flash_attn/ops dir | |
src_ops = os.path.join(self.build_lib, "vllm", "vllm_flash_attn", | |
"ops") | |
dst_ops = os.path.join("vllm", "vllm_flash_attn", "ops") | |
if os.path.exists(src_ops): | |
print(f"Copying directory {src_ops} to {dst_ops}") | |
if os.path.exists(dst_ops): | |
shutil.rmtree(dst_ops) | |
shutil.copytree(src_ops, dst_ops) | |
for folder in ("layers", "ops"): | |
src = os.path.join(self.build_lib, "vllm", "vllm_flash_attn", folder) | |
out = os.path.join("vllm", "vllm_flash_attn", folder) | |
self.copy_tree(src, out) |
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.
You can use this patch here
diff --git a/setup.py b/setup.py
index 671ec7739..f5b3f5165 100755
--- a/setup.py
+++ b/setup.py
@@ -283,6 +283,13 @@ class cmake_build_ext(build_ext):
dst_file = os.path.join("vllm/vllm_flash_attn", basename)
print(f"Copying {file} to {dst_file}")
self.copy_file(file, dst_file)
+ # We will need to copy these folders to use its ops for qwen-vl
+ for folder in ("layers", "ops"):
+ src = os.path.join(self.build_lib, 'vllm', 'vllm_flash_attn',
+ folder)
+ out = os.path.join('vllm', 'vllm_flash_attn', folder)
+ print(f"Copying {folder} from vllm/vllm_flash_attn")
+ self.copy_tree(src, out)
class repackage_wheel(build_ext):
@@ -402,6 +409,32 @@ class repackage_wheel(build_ext):
package_data[package_name].append(file_name)
+ # Extract and include the layers and ops folders for qwen-vl
+ folders_to_copy = {"layers", "ops"}
+ for folder in folders_to_copy:
+ folder_path = f"vllm/vllm_flash_attn/{folder}"
+ folder_files = [
+ f for f in wheel.filelist
+ if f.filename.startswith(folder_path)
+ ]
+
+ if folder_files:
+ print(f"Include {folder} folder from vllm/vllm_flash_attn")
+ for file in folder_files:
+ wheel.extract(file)
+
+ # Add the file to package_data if it's not a Python file
+ rel_path = file.filename.split("/")
+ # vllm/vllm_flash_attn/folder/file
+ if len(rel_path) >= 4:
+ package_name = "vllm.vllm_flash_attn." + folder
+ file_name = rel_path[-1]
+
+ if not file_name.endswith(".py"):
+ if package_name not in package_data:
+ package_data[package_name] = []
+ package_data[package_name].append(file_name)
+
def _is_hpu() -> bool:
# if VLLM_TARGET_DEVICE env var was set explicitly, skip HPU autodetection
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.
Thank you
Signed-off-by: Jee Jee Li <[email protected]>
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.
Thanks. LGTM
Can you also add a Co-authored-by: Aaron Pham <[email protected]>
to the description.
Hmm, @jeejeelee there is a issue with building on CPU here? |
Ah we need to gated the copy ovee in 27fdbeea7 - chore: only gated in CUDA (HEAD -> fix-flash-att-rotray)
Signed-off-by: Aaron Pham <[email protected]>
(G) Aaron Pham <[email protected]> (Sun Apr 27 14:57:44 2025 +0000)
diff --git a/setup.py b/setup.py
index 34be6a641..8e18c8215 100755
--- a/setup.py
+++ b/setup.py
@@ -280,13 +280,14 @@ class cmake_build_ext(build_ext):
print(f"Copying {file} to {dst_file}")
self.copy_file(file, dst_file)
- # copy these folders to use the vllm_flash_attn rotary_kernel.
- for folder in ("layers", "ops"):
- src = os.path.join(self.build_lib, "vllm", "vllm_flash_attn",
- folder)
- out = os.path.join("vllm", "vllm_flash_attn", folder)
- print(f"Copying {folder} from vllm/vllm_flash_attn")
- self.copy_tree(src, out)
+ if _is_cuda():
+ # copy these folders to use the vllm_flash_attn rotary_kernel.
+ for folder in ("layers", "ops"):
+ src = os.path.join(self.build_lib, "vllm", "vllm_flash_attn",
+ folder)
+ out = os.path.join("vllm", "vllm_flash_attn", folder)
+ print(f"Copying {folder} from vllm/vllm_flash_attn")
+ self.copy_tree(src, out)
class repackage_wheel(build_ext):
@@ -409,29 +410,34 @@ class repackage_wheel(build_ext):
package_data[package_name].append(file_name)
# Extract and include the layers and ops of rotary embedding.
- folders_to_copy = {"layers", "ops"}
- for folder in folders_to_copy:
- folder_path = f"vllm/vllm_flash_attn/{folder}"
- folder_files = [
- f for f in wheel.filelist
- if f.filename.startswith(folder_path)
- ]
-
- if folder_files:
- print(f"Include {folder} folder from vllm/vllm_flash_attn")
- for file in folder_files:
- wheel.extract(file)
-
- # Add the file to package_data if it's not a Python file
- rel_path = file.filename.split("/")
- # vllm/vllm_flash_attn/folder/file
- if len(rel_path) >= 4:
- package_name = "vllm.vllm_flash_attn." + folder
- file_name = rel_path[-1]
- if not file_name.endswith(".py"):
- if package_name not in package_data:
- package_data[package_name] = []
- package_data[package_name].append(file_name)
+ if _is_cuda():
+ folders_to_copy = {"layers", "ops"}
+ for folder in folders_to_copy:
+ folder_path = f"vllm/vllm_flash_attn/{folder}"
+ folder_files = [
+ f for f in wheel.filelist
+ if f.filename.startswith(folder_path)
+ ]
+
+ if folder_files:
+ print(
+ f"Include {folder} folder from vllm/vllm_flash_attn"
+ )
+ for file in folder_files:
+ wheel.extract(file)
+
+ # Add the file to package_data if
+ # it's not a Python file
+ rel_path = file.filename.split("/")
+ # vllm/vllm_flash_attn/folder/file
+ if len(rel_path) >= 4:
+ package_name = "vllm.vllm_flash_attn." + folder
+ file_name = rel_path[-1]
+ if not file_name.endswith(".py"):
+ if package_name not in package_data:
+ package_data[package_name] = []
+ package_data[package_name].append(
+ file_name)
def _is_hpu() -> bool: |
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.
Can you please add a description of the bug to the PR comment
@@ -280,6 +280,14 @@ def run(self): | |||
print(f"Copying {file} to {dst_file}") | |||
self.copy_file(file, dst_file) | |||
|
|||
# copy these folders to use the vllm_flash_attn rotary_kernel. | |||
for folder in ("layers", "ops"): |
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.
this seems unnecessary, why not just do:
files = glob.glob(
os.path.join(self.build_lib, "vllm", "vllm_flash_attn", "**", "*.py"))
on line 275-276 instead?
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.
this will only grab all of the python files, then we still need to check if the folder exists or not, then copy over here.
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.
Would this conflict with #17260?
@@ -400,6 +408,31 @@ def run(self) -> None: | |||
|
|||
package_data[package_name].append(file_name) | |||
|
|||
# Extract and include the layers and ops of rotary embedding. | |||
folders_to_copy = {"layers", "ops"} | |||
for folder in folders_to_copy: |
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.
This also seems unnecessarily messing / complicated, I think we can just use glob.translate
(https://docs.python.org/3/library/glob.html#glob.translate) and grab the file list like use the same glob pattern mentioned above
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 agree, overlook on my end.
Done |
IIUC, no need to add gate, these changes are just a supplement to |
This is superceded by #17267 |
Using qwen2-vl can reproduce this issue.
FIX #17263
Co-authored-by: Aaron Pham [email protected]