Skip to content

File tree

9 files changed

+557
-2
lines changed

9 files changed

+557
-2
lines changed
 

‎.github/workflows/genai_lib.yml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: genai_lib
2+
on: pull_request
3+
jobs:
4+
genai_lib_ubuntu:
5+
runs-on: ubuntu-20.04
6+
steps:
7+
- uses: actions/checkout@v4
8+
with:
9+
submodules: recursive
10+
- uses: actions/setup-python@v4
11+
with:
12+
python-version: 3.8
13+
- run: mkdir ./ov/
14+
- run: curl https://storage.openvinotoolkit.org/repositories/openvino/packages/nightly/2024.1.0-14758-22bd6ff0494/l_openvino_toolkit_centos7_2024.1.0.dev20240315_x86_64.tgz | tar --directory ./ov/ --strip-components 1 -xz # Install CentOS7 instead of Ubuntu to match PyPI distribution ABI
15+
- run: sudo ./ov/install_dependencies/install_openvino_dependencies.sh
16+
- run: source ./ov/setupvars.sh && cmake -DCMAKE_BUILD_TYPE=Release -S ./ -B ./build/
17+
- run: source ./ov/setupvars.sh && cmake --build ./build/ --config Release -j
18+
- run: python -m pip install openvino # Can't load CenOS libraries from the archive
19+
- run: PYTHONPATH=./src/python/ python -c "from openvino_genai.py_generate_pipeline import LLMPipeline"
20+
- run: source ./ov/setupvars.sh && python -m pip install --pre --upgrade . --extra-index-url https://storage.openvinotoolkit.org/simple/wheels/nightly
21+
- run: python -c "from openvino_genai.py_generate_pipeline import LLMPipeline"
22+
23+
genai_lib_windows:
24+
runs-on: windows-latest
25+
defaults:
26+
run:
27+
shell: cmd
28+
steps:
29+
- uses: actions/checkout@v4
30+
with:
31+
submodules: recursive
32+
- uses: actions/setup-python@v4
33+
with:
34+
python-version: 3.8
35+
- run: curl --output ov.zip https://storage.openvinotoolkit.org/repositories/openvino/packages/nightly/2024.1.0-14645-e6dc0865128/w_openvino_toolkit_windows_2024.1.0.dev20240304_x86_64.zip
36+
- run: unzip ov.zip
37+
- run: call w_openvino_toolkit_windows_2024.1.0.dev20240304_x86_64\setupvars.bat && cmake -DCMAKE_BUILD_TYPE=Release -S ./ -B ./build/
38+
- run: call w_openvino_toolkit_windows_2024.1.0.dev20240304_x86_64\setupvars.bat && cmake --build ./build/ --config Release -j
39+
- run: python -m pip install "numpy<1.27"
40+
- run: set "PYTHONPATH=./src/python;" && call w_openvino_toolkit_windows_2024.1.0.dev20240304_x86_64\setupvars.bat && python -c "from openvino_genai.py_generate_pipeline import LLMPipeline" # cmd evaluates variables in a different way. Setting PYTHONPATH before setupvars.bat instead of doing that after solves that.
41+
- run: call w_openvino_toolkit_windows_2024.1.0.dev20240304_x86_64\setupvars.bat && python -m pip install .
42+
- run: python -c "from openvino_genai.py_generate_pipeline import LLMPipeline"

‎.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# They are copied to python folder during the build to allow skipping wheel installation
2+
src/python/openvino/genai/*generate_pipeline_lib*
3+
src/python/openvino/genai/py_generate_pipeline*
4+
15
# build/artifact dirs
26
_*
37
[Bb]uild*/

‎CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Release" "Debug" "RelWithD
99

1010
project(openvino_genai)
1111

12+
add_subdirectory(./thirdparty/openvino_tokenizers/ "${CMAKE_CURRENT_BINARY_DIR}/openvino_tokenizers/")
1213
add_subdirectory(src)
1314
add_subdirectory(text_generation/causal_lm/cpp)

‎pyproject.toml

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
[project]
2+
name = "openvino_genai"
3+
version = "2024.2.0.0"
4+
description = "Python bindings for https://github.com/openvinotoolkit/openvino.genai"
5+
requires-python = ">=3.8"
6+
readme = {file = "text_generation/causal_lm/cpp/README.md", content-type="text/markdown"}
7+
license = {text = "OSI Approved :: Apache Software License"}
8+
authors = [
9+
{ name = "OpenVINO Developers", email = "openvino@intel.com" },
10+
]
11+
classifiers = [
12+
"Programming Language :: Python :: 3.8",
13+
"Programming Language :: Python :: 3.9",
14+
"Programming Language :: Python :: 3.10",
15+
"Programming Language :: Python :: 3.11",
16+
"Programming Language :: Python :: 3.12",
17+
]
18+
dependencies = [
19+
"openvino_tokenizers~=2024.1.0.0"
20+
]
21+
22+
[tool.scikit-build]
23+
cmake.source-dir = "./"
24+
cmake.build-type = "Release"
25+
cmake.targets = ["py_generate_pipeline", "generate_pipeline_lib"]
26+
install.components = ["genai", "genai_python"]
27+
sdist.cmake = true
28+
wheel.packages = ["src/python/openvino_genai"]
29+
wheel.install-dir = "openvino_genai"
30+
wheel.build-tag = "000"
31+
wheel.license-files = ["LICENSE", "SECURITY.md", "third-party-programs.txt"]
32+
33+
[[tool.scikit-build.generate]]
34+
path = "openvino_genai/__version__.py"
35+
template = '''
36+
__version__ = "${version}"
37+
'''
38+
39+
[build-system]
40+
requires = ["scikit-build-core~=0.8.0"] # See https://github.com/openvinotoolkit/openvino_tokenizers/pull/123
41+
build-backend = "scikit_build_core.build"

‎src/cpp/CMakeLists.txt

+14-2
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,16 @@ function(ov_genai_build_jinja2cpp)
3030
set(JINJA2CPP_PIC ON CACHE BOOL "")
3131

3232
add_subdirectory("${jinja2cpp_SOURCE_DIR}" "${jinja2cpp_BINARY_DIR}" EXCLUDE_FROM_ALL)
33+
# openvino::runtime exports _GLIBCXX_USE_CXX11_ABI=0 on CentOS7.
34+
# It needs to be propagated to every library GenAI links with.
35+
# It's enough to propagate to fmt, because fmt propagates to
36+
# jinja2cpp.
37+
target_compile_definitions(fmt PUBLIC $<TARGET_PROPERTY:openvino::runtime,INTERFACE_COMPILE_DEFINITIONS>)
3338
endif()
3439
endfunction()
3540

3641
ov_genai_build_jinja2cpp()
3742

38-
add_subdirectory(../../thirdparty/openvino_tokenizers/ "${CMAKE_CURRENT_BINARY_DIR}/openvino_tokenizers/")
39-
4043
# Library
4144

4245
file(GLOB SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp")
@@ -54,3 +57,12 @@ target_link_libraries(${TARGET_NAME} PUBLIC openvino::runtime PRIVATE nlohmann_j
5457
target_compile_definitions(${TARGET_NAME} PRIVATE OPENVINO_TOKENIZERS_PATH=\"$<TARGET_FILE:openvino_tokenizers>\")
5558

5659
target_compile_features(${TARGET_NAME} PUBLIC cxx_std_17)
60+
61+
install(TARGETS ${TARGET_NAME} LIBRARY DESTINATION . COMPONENT genai RUNTIME DESTINATION . COMPONENT genai)
62+
63+
# Populate python with the libraries to allow skipping wheel installation
64+
add_custom_command(TARGET generate_pipeline_lib POST_BUILD
65+
COMMAND "${CMAKE_COMMAND}" -E copy
66+
"$<TARGET_FILE:generate_pipeline_lib>"
67+
"${CMAKE_CURRENT_SOURCE_DIR}/../python/openvino_genai/$<TARGET_FILE_NAME:generate_pipeline_lib>"
68+
COMMENT "Copy generate_pipeline_lib to src/python/openvino_genai")

‎src/python/CMakeLists.txt

+26
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,29 @@ endif()
1717

1818
pybind11_add_module(py_generate_pipeline py_generate_pipeline.cpp)
1919
target_link_libraries(py_generate_pipeline PRIVATE generate_pipeline_lib)
20+
21+
install(TARGETS py_generate_pipeline LIBRARY DESTINATION . COMPONENT genai_python)
22+
23+
# setting RPATH / LC_RPATH depending on platform
24+
if(LINUX)
25+
# to find libgenerate_pipeline_lib.so in the same folder
26+
set(rpaths "$ORIGIN")
27+
elseif(APPLE)
28+
# to find libgenerate_pipeline_lib.dylib in the same folder
29+
set(rpaths "@loader_path")
30+
if(DEFINED SKBUILD)
31+
# in case we build pip package, we need to refer to libopenvino.dylib from 'openvino' package
32+
list(APPEND rpaths "@loader_path/../openvino/libs")
33+
endif()
34+
endif()
35+
36+
if(rpaths)
37+
set_target_properties(py_generate_pipeline PROPERTIES INSTALL_RPATH "${rpaths}")
38+
endif()
39+
40+
# Populate python with the libraries to allow skipping wheel installation
41+
add_custom_command(TARGET py_generate_pipeline POST_BUILD
42+
COMMAND "${CMAKE_COMMAND}" -E copy
43+
"$<TARGET_FILE:py_generate_pipeline>"
44+
"${CMAKE_CURRENT_SOURCE_DIR}/openvino_genai/$<TARGET_FILE_NAME:py_generate_pipeline>"
45+
COMMENT "Copy py_generate_pipeline to src/python/openvino_genai/")

‎src/python/openvino_genai/__init__.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copyright (C) 2024 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
import openvino # add_dll_directory for openvino lib
5+
import os
6+
from .__version__ import __version__
7+
8+
9+
if hasattr(os, "add_dll_directory"):
10+
os.add_dll_directory(os.path.dirname(__file__))
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# this property will be overwritten by value from pyproject.toml
2+
__version__ = "0.0.0.0"

‎third-party-programs.txt

+417
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.