From e3941d9c674dbd9891dc3ceda390daeb21f05fd1 Mon Sep 17 00:00:00 2001 From: Andrei Betlen Date: Tue, 28 Nov 2023 04:55:21 -0500 Subject: [PATCH] Make building llava optional --- CMakeLists.txt | 49 ++++++++++++++++++++++-------------------- llama_cpp/llava_cpp.py | 4 ++-- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 658b71d..795dad7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.21) project(llama_cpp) option(LLAMA_BUILD "Build llama.cpp shared library and install alongside python package" ON) +option(LLAVA_BUILD "Build llava shared library and install alongside python package" ON) if (LLAMA_BUILD) set(BUILD_SHARED_LIBS "On") @@ -44,28 +45,30 @@ if (LLAMA_BUILD) DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/llama_cpp ) - # Building llava - add_subdirectory(vendor/llama.cpp/examples/llava) - set_target_properties(llava_shared PROPERTIES OUTPUT_NAME "llava") - # Set CUDA_ARCHITECTURES to OFF on windows - if (WIN32) - set_target_properties(llava_shared PROPERTIES CUDA_ARCHITECTURES OFF) + if (LLAVA_BUILD) + # Building llava + add_subdirectory(vendor/llama.cpp/examples/llava) + set_target_properties(llava_shared PROPERTIES OUTPUT_NAME "llava") + # Set CUDA_ARCHITECTURES to OFF on windows + if (WIN32) + set_target_properties(llava_shared PROPERTIES CUDA_ARCHITECTURES OFF) + endif() + install( + TARGETS llava_shared + LIBRARY DESTINATION ${SKBUILD_PLATLIB_DIR}/llama_cpp + RUNTIME DESTINATION ${SKBUILD_PLATLIB_DIR}/llama_cpp + ARCHIVE DESTINATION ${SKBUILD_PLATLIB_DIR}/llama_cpp + FRAMEWORK DESTINATION ${SKBUILD_PLATLIB_DIR}/llama_cpp + RESOURCE DESTINATION ${SKBUILD_PLATLIB_DIR}/llama_cpp + ) + # Temporary fix for https://github.com/scikit-build/scikit-build-core/issues/374 + install( + TARGETS llava_shared + LIBRARY DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/llama_cpp + RUNTIME DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/llama_cpp + ARCHIVE DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/llama_cpp + FRAMEWORK DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/llama_cpp + RESOURCE DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/llama_cpp + ) endif() - install( - TARGETS llava_shared - LIBRARY DESTINATION ${SKBUILD_PLATLIB_DIR}/llama_cpp - RUNTIME DESTINATION ${SKBUILD_PLATLIB_DIR}/llama_cpp - ARCHIVE DESTINATION ${SKBUILD_PLATLIB_DIR}/llama_cpp - FRAMEWORK DESTINATION ${SKBUILD_PLATLIB_DIR}/llama_cpp - RESOURCE DESTINATION ${SKBUILD_PLATLIB_DIR}/llama_cpp - ) - # Temporary fix for https://github.com/scikit-build/scikit-build-core/issues/374 - install( - TARGETS llava_shared - LIBRARY DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/llama_cpp - RUNTIME DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/llama_cpp - ARCHIVE DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/llama_cpp - FRAMEWORK DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/llama_cpp - RESOURCE DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/llama_cpp - ) endif() diff --git a/llama_cpp/llava_cpp.py b/llama_cpp/llava_cpp.py index 72f6a12..b1f90b9 100644 --- a/llama_cpp/llava_cpp.py +++ b/llama_cpp/llava_cpp.py @@ -48,8 +48,8 @@ def _load_shared_library(lib_base_name: str): else: raise RuntimeError("Unsupported platform") - if "LLAMA_CPP_LIB" in os.environ: - lib_base_name = os.environ["LLAMA_CPP_LIB"] + if "LLAVA_CPP_LIB" in os.environ: + lib_base_name = os.environ["LLAVA_CPP_LIB"] _lib = pathlib.Path(lib_base_name) _base_path = _lib.parent.resolve() _lib_paths = [_lib.resolve()]