vllm icon indicating copy to clipboard operation
vllm copied to clipboard

[Bugfix] Fix vllm_flash_attn rotary import

Open jeejeelee opened this issue 7 months ago • 1 comments

Using qwen2-vl can reproduce this issue.

jeejeelee avatar Apr 27 '25 08:04 jeejeelee

👋 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 fastcheck CI which starts running only a small and essential subset of CI tests to quickly catch errors. You can run other CI tests on top of those by going to your fastcheck build on Buildkite UI (linked in the PR checks section) and unblock them. If you do not have permission to unblock, ping simon-mo or khluu to add you in our Buildkite org.

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 ready label to the PR or enable auto-merge.

🚀

github-actions[bot] avatar Apr 27 '25 08:04 github-actions[bot]

Hmm, @jeejeelee there is a issue with building on CPU here?

aarnphm avatar Apr 27 '25 14:04 aarnphm

Ah we need to gated the copy ovee in _is_cuda() only here.

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:

aarnphm avatar Apr 27 '25 14:04 aarnphm

Thanks. LGTM

Can you also add a Co-authored-by: Aaron Pham <[email protected]> to the description.

Done

jeejeelee avatar Apr 27 '25 15:04 jeejeelee

Ah we need to gated the copy ovee in _is_cuda() only here.

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:

IIUC, no need to add gate, these changes are just a supplement to vllm_flash_attn copy

jeejeelee avatar Apr 27 '25 15:04 jeejeelee

This is superceded by #17267

aarnphm avatar Apr 27 '25 16:04 aarnphm