Skip to content

Commit f6483ae

Browse files
committed
Fixes for CMake install
Signed-off-by: luka <[email protected]>
1 parent 6e588da commit f6483ae

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ include(${CMAKE_CURRENT_LIST_DIR}/cmake/utils.cmake)
2323
# Suppress potential warnings about unused manually-specified variables
2424
set(ignoreMe "${VLLM_PYTHON_PATH}")
2525

26+
# Prevent installation of dependencies (cutlass) by default.
27+
install(CODE "set(CMAKE_INSTALL_LOCAL_ONLY TRUE)" ALL_COMPONENTS)
28+
2629
#
2730
# Supported python versions. These versions will be searched in order, the
2831
# first match will be selected. These should be kept in sync with setup.py.
@@ -783,5 +786,7 @@ endif()
783786
# For CUDA we also build and ship some external projects.
784787
if (VLLM_GPU_LANG STREQUAL "CUDA")
785788
include(cmake/external_projects/flashmla.cmake)
789+
790+
# vllm-flash-attn should be last as it overwrites some CMake functions
786791
include(cmake/external_projects/vllm_flash_attn.cmake)
787792
endif ()

cmake/external_projects/vllm_flash_attn.cmake

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,38 @@ else()
4646
endif()
4747

4848

49+
# Ensure the vllm/vllm_flash_attn directory exists before installation
50+
install(CODE "file(MAKE_DIRECTORY \"\${CMAKE_INSTALL_PREFIX}/vllm/vllm_flash_attn\")" ALL_COMPONENTS)
51+
52+
# Make sure vllm-flash-attn install rules are nested under vllm/
53+
# This is here to support installing all components under the same prefix with cmake --install.
54+
# setup.py installs every component separately but uses the same prefix for all.
55+
# ALL_COMPONENTS is used to avoid duplication for FA2 and FA3,
56+
# and these statements don't hurt when installing neither component.
57+
install(CODE "set(CMAKE_INSTALL_LOCAL_ONLY FALSE)" ALL_COMPONENTS)
58+
install(CODE "set(OLD_CMAKE_INSTALL_PREFIX \"\${CMAKE_INSTALL_PREFIX}\")" ALL_COMPONENTS)
59+
install(CODE "set(CMAKE_INSTALL_PREFIX \"\${CMAKE_INSTALL_PREFIX}/vllm/\")" ALL_COMPONENTS)
60+
4961
# Fetch the vllm-flash-attn library
5062
FetchContent_MakeAvailable(vllm-flash-attn)
5163
message(STATUS "vllm-flash-attn is available at ${vllm-flash-attn_SOURCE_DIR}")
5264

65+
# Restore the install prefix
66+
install(CODE "set(CMAKE_INSTALL_PREFIX \"\${OLD_CMAKE_INSTALL_PREFIX}\")" ALL_COMPONENTS)
67+
install(CODE "set(CMAKE_INSTALL_LOCAL_ONLY TRUE)" ALL_COMPONENTS)
68+
5369
# Copy over the vllm-flash-attn python files (duplicated for fa2 and fa3, in
5470
# case only one is built, in the case both are built redundant work is done)
5571
install(
5672
DIRECTORY ${vllm-flash-attn_SOURCE_DIR}/vllm_flash_attn/
57-
DESTINATION vllm_flash_attn
73+
DESTINATION vllm/vllm_flash_attn
5874
COMPONENT _vllm_fa2_C
5975
FILES_MATCHING PATTERN "*.py"
6076
)
6177

6278
install(
6379
DIRECTORY ${vllm-flash-attn_SOURCE_DIR}/vllm_flash_attn/
64-
DESTINATION vllm_flash_attn
80+
DESTINATION vllm/vllm_flash_attn
6581
COMPONENT _vllm_fa3_C
6682
FILES_MATCHING PATTERN "*.py"
6783
)

cmake/utils.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ function (hipify_sources_target OUT_SRCS NAME ORIG_SRCS)
7676
set(CSRC_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/csrc)
7777
add_custom_target(
7878
hipify${NAME}
79-
COMMAND ${CMAKE_SOURCE_DIR}/cmake/hipify.py -p ${CMAKE_SOURCE_DIR}/csrc -o ${CSRC_BUILD_DIR} ${SRCS}
79+
COMMAND ${Python_EXECUTABLE} ${CMAKE_SOURCE_DIR}/cmake/hipify.py -p ${CMAKE_SOURCE_DIR}/csrc -o ${CSRC_BUILD_DIR} ${SRCS}
8080
DEPENDS ${CMAKE_SOURCE_DIR}/cmake/hipify.py ${SRCS}
8181
BYPRODUCTS ${HIP_SRCS}
8282
COMMENT "Running hipify on ${NAME} extension source files.")

setup.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,11 +251,8 @@ def target_name(s: str) -> str:
251251

252252
# CMake appends the extension prefix to the install path,
253253
# and outdir already contains that prefix, so we need to remove it.
254-
# We assume only the final component of extension prefix is added by
255-
# CMake, this is currently true for current extensions but may not
256-
# always be the case.
257254
prefix = outdir
258-
if '.' in ext.name:
255+
for _ in range(ext.name.count('.')):
259256
prefix = prefix.parent
260257

261258
# prefix here should actually be the same for all components

0 commit comments

Comments
 (0)