Skip to content
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

Package #58

Merged
merged 41 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
5543cee
init
Wovchena May 6, 2024
abb8835
add_subdirectory
Wovchena May 7, 2024
0998abc
add files
Wovchena May 8, 2024
15492c4
add __init__.py
Wovchena May 8, 2024
95c1bfb
rm generate_pipeline/python
Wovchena May 9, 2024
59c3e0b
Merge branch 'generate_pipeline' into package
Wovchena May 10, 2024
be84345
align names
Wovchena May 10, 2024
bced64a
Dont modify text_generation/causal_lm/cpp/CMakeLists.txt
Wovchena May 10, 2024
f4e82b6
rm -r text_generation/causal_lm/cpp/generate_pipeline/python-bindings/
Wovchena May 10, 2024
5b2b0ca
fix build
Wovchena May 10, 2024
0dd8f59
add tokenizers only once
Wovchena May 10, 2024
23638ff
change cmake.source-dir
Wovchena May 10, 2024
d8c5349
restore openvino/genai inits
Wovchena May 10, 2024
598dda3
install genai lib
Wovchena May 10, 2024
02d0eae
import openvino for win and lin
Wovchena May 10, 2024
e6695f3
Merge branch 'generate_pipeline' into package
Wovchena May 10, 2024
a27c5a7
put the line back
Wovchena May 10, 2024
34cddff
one line properties
Wovchena May 10, 2024
a9332f0
Merge branch 'generate_pipeline' into package
Wovchena May 10, 2024
9ef488c
rename
Wovchena May 10, 2024
4fad7d5
add .github/workflows/genai_lib.yml
Wovchena May 10, 2024
51e03a2
on: pull_request
Wovchena May 10, 2024
e23a7bb
spelling
Wovchena May 10, 2024
fc5b753
install openvino
Wovchena May 10, 2024
e7db7e8
update
Wovchena May 13, 2024
f279363
add rpath
Wovchena May 13, 2024
83d77c8
add rpath to libopenvino.so
Wovchena May 13, 2024
167f924
py_generate_pipeline
Wovchena May 13, 2024
813d80a
install centos7
Wovchena May 13, 2024
6227b65
install nightly
Wovchena May 13, 2024
74fc107
Merge branch 'generate_pipeline' into package
Wovchena May 13, 2024
9b83a7e
propagate _GLIBCXX_USE_CXX11_ABI
Wovchena May 13, 2024
2d15752
Populate python with the libraries to allow skipping wheel installation
Wovchena May 13, 2024
8025554
run setupvars
Wovchena May 13, 2024
2b14286
update .gitignore, install numpy
Wovchena May 13, 2024
1c11bc7
quotes
Wovchena May 13, 2024
e7fce82
fix PYTHONPATH
Wovchena May 13, 2024
64608d1
fix PYTHONPATH
Wovchena May 13, 2024
43b87c7
quotes
Wovchena May 13, 2024
fef9674
reorder vars
Wovchena May 14, 2024
b21286c
openvino.genai-
Wovchena May 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .github/workflows/genai_lib.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: genai_lib
on: pull_request
jobs:
genai_lib_ubuntu:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: actions/setup-python@v4
with:
python-version: 3.8
- run: mkdir ./ov/
- 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
- run: sudo ./ov/install_dependencies/install_openvino_dependencies.sh
- run: source ./ov/setupvars.sh && cmake -DCMAKE_BUILD_TYPE=Release -S ./ -B ./build/
- run: source ./ov/setupvars.sh && cmake --build ./build/ --config Release -j
- run: python -m pip install openvino # Can't load CenOS libraries from the archive
- run: PYTHONPATH=./src/python/ python -c "from openvino_genai.py_generate_pipeline import LLMPipeline"
- run: source ./ov/setupvars.sh && python -m pip install --pre --upgrade . --extra-index-url https://storage.openvinotoolkit.org/simple/wheels/nightly
- run: python -c "from openvino_genai.py_generate_pipeline import LLMPipeline"

genai_lib_windows:
runs-on: windows-latest
defaults:
run:
shell: cmd
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: actions/setup-python@v4
with:
python-version: 3.8
- 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
- run: unzip ov.zip
- run: call w_openvino_toolkit_windows_2024.1.0.dev20240304_x86_64\setupvars.bat && cmake -DCMAKE_BUILD_TYPE=Release -S ./ -B ./build/
- run: call w_openvino_toolkit_windows_2024.1.0.dev20240304_x86_64\setupvars.bat && cmake --build ./build/ --config Release -j
- run: python -m pip install "numpy<1.27"
- 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.
- run: call w_openvino_toolkit_windows_2024.1.0.dev20240304_x86_64\setupvars.bat && python -m pip install .
- run: python -c "from openvino_genai.py_generate_pipeline import LLMPipeline"
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# They are copied to python folder during the build to allow skipping wheel installation
src/python/openvino/genai/*generate_pipeline_lib*
src/python/openvino/genai/py_generate_pipeline*

# build/artifact dirs
_*
[Bb]uild*/
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Release" "Debug" "RelWithD

project(openvino_genai)

add_subdirectory(./thirdparty/openvino_tokenizers/ "${CMAKE_CURRENT_BINARY_DIR}/openvino_tokenizers/")
add_subdirectory(src)
add_subdirectory(text_generation/causal_lm/cpp)
41 changes: 41 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[project]
name = "openvino_genai"
version = "2024.2.0.0"
description = "Python bindings for https://github.com/openvinotoolkit/openvino.genai"
requires-python = ">=3.8"
readme = {file = "text_generation/causal_lm/cpp/README.md", content-type="text/markdown"}
license = {text = "OSI Approved :: Apache Software License"}
authors = [
{ name = "OpenVINO Developers", email = "openvino@intel.com" },
]
classifiers = [
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]
dependencies = [
"openvino_tokenizers~=2024.1.0.0"
]

[tool.scikit-build]
cmake.source-dir = "./"
cmake.build-type = "Release"
cmake.targets = ["py_generate_pipeline", "generate_pipeline_lib"]
install.components = ["genai", "genai_python"]
sdist.cmake = true
wheel.packages = ["src/python/openvino_genai"]
wheel.install-dir = "openvino_genai"
wheel.build-tag = "000"
wheel.license-files = ["LICENSE", "SECURITY.md", "third-party-programs.txt"]

[[tool.scikit-build.generate]]
path = "openvino_genai/__version__.py"
template = '''
__version__ = "${version}"
'''

[build-system]
requires = ["scikit-build-core~=0.8.0"] # See https://github.com/openvinotoolkit/openvino_tokenizers/pull/123
build-backend = "scikit_build_core.build"
16 changes: 14 additions & 2 deletions src/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@ function(ov_genai_build_jinja2cpp)
set(JINJA2CPP_PIC ON CACHE BOOL "")

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

ov_genai_build_jinja2cpp()

add_subdirectory(../../thirdparty/openvino_tokenizers/ "${CMAKE_CURRENT_BINARY_DIR}/openvino_tokenizers/")

# Library

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

target_compile_features(${TARGET_NAME} PUBLIC cxx_std_17)

install(TARGETS ${TARGET_NAME} LIBRARY DESTINATION . COMPONENT genai RUNTIME DESTINATION . COMPONENT genai)

# Populate python with the libraries to allow skipping wheel installation
add_custom_command(TARGET generate_pipeline_lib POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E copy
"$<TARGET_FILE:generate_pipeline_lib>"
"${CMAKE_CURRENT_SOURCE_DIR}/../python/openvino_genai/$<TARGET_FILE_NAME:generate_pipeline_lib>"
COMMENT "Copy generate_pipeline_lib to src/python/openvino_genai")
26 changes: 26 additions & 0 deletions src/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,29 @@ endif()

pybind11_add_module(py_generate_pipeline py_generate_pipeline.cpp)
target_link_libraries(py_generate_pipeline PRIVATE generate_pipeline_lib)

install(TARGETS py_generate_pipeline LIBRARY DESTINATION . COMPONENT genai_python)

# setting RPATH / LC_RPATH depending on platform
if(LINUX)
# to find libgenerate_pipeline_lib.so in the same folder
set(rpaths "$ORIGIN")
elseif(APPLE)
# to find libgenerate_pipeline_lib.dylib in the same folder
set(rpaths "@loader_path")
if(DEFINED SKBUILD)
# in case we build pip package, we need to refer to libopenvino.dylib from 'openvino' package
list(APPEND rpaths "@loader_path/../openvino/libs")
endif()
endif()

if(rpaths)
set_target_properties(py_generate_pipeline PROPERTIES INSTALL_RPATH "${rpaths}")
endif()

# Populate python with the libraries to allow skipping wheel installation
add_custom_command(TARGET py_generate_pipeline POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E copy
"$<TARGET_FILE:py_generate_pipeline>"
"${CMAKE_CURRENT_SOURCE_DIR}/openvino_genai/$<TARGET_FILE_NAME:py_generate_pipeline>"
COMMENT "Copy py_generate_pipeline to src/python/openvino_genai/")
10 changes: 10 additions & 0 deletions src/python/openvino_genai/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

import openvino # add_dll_directory for openvino lib
import os
from .__version__ import __version__


if hasattr(os, "add_dll_directory"):
os.add_dll_directory(os.path.dirname(__file__))
2 changes: 2 additions & 0 deletions src/python/openvino_genai/__version__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# this property will be overwritten by value from pyproject.toml
__version__ = "0.0.0.0"
Loading
Loading