From 5bc6eb63e6f52974b91a10ae0d533d18b7257692 Mon Sep 17 00:00:00 2001 From: Jonathan Davies Date: Wed, 27 May 2026 19:35:50 +0000 Subject: [PATCH] openvino-genai: init at 2026.2.0.0 --- ...ove-gguf-format-template-into-header.patch | 37 ++++ pkgs/by-name/op/openvino-genai/package.nix | 205 ++++++++++++++++++ 2 files changed, 242 insertions(+) create mode 100644 pkgs/by-name/op/openvino-genai/move-gguf-format-template-into-header.patch create mode 100644 pkgs/by-name/op/openvino-genai/package.nix diff --git a/pkgs/by-name/op/openvino-genai/move-gguf-format-template-into-header.patch b/pkgs/by-name/op/openvino-genai/move-gguf-format-template-into-header.patch new file mode 100644 index 000000000000..075bab44213f --- /dev/null +++ b/pkgs/by-name/op/openvino-genai/move-gguf-format-template-into-header.patch @@ -0,0 +1,37 @@ +--- a/src/cpp/src/gguf_utils/gguf.hpp ++++ b/src/cpp/src/gguf_utils/gguf.hpp +@@ -28,7 +28,12 @@ + std::unordered_map>; + + template +-std::string format(std::string fmt, Args... args); ++std::string format(std::string fmt, Args... args) { ++ char buf[1000]; ++ int n = snprintf(buf, sizeof(buf), fmt.c_str(), args...); ++ assert(n >= 0 && n < static_cast(sizeof(buf))); ++ return std::string(buf); ++} + + ov::Shape get_shape(const gguf_tensor& tensor); + +--- a/src/cpp/src/gguf_utils/gguf.cpp ++++ b/src/cpp/src/gguf_utils/gguf.cpp +@@ -13,18 +13,6 @@ + // https://github.com/antirez/gguf-tools/blob/af7d88d808a7608a33723fba067036202910acb3/gguflib.h#L102-L108 + constexpr int gguf_array_header_size = 12; + +-template +-std::string format(std::string fmt, Args... args) { +- size_t bufferSize = 1000; +- char* buffer = new char[bufferSize]; +- int n = sprintf(buffer, fmt.c_str(), args...); +- assert(n >= 0 && n < (int)bufferSize - 1); +- +- std::string fmtStr(buffer); +- delete[] buffer; +- return fmtStr; +-} +- + std::optional dtype_to_gguf_tensor_type(const ov::element::Type& dtype) { + switch (dtype) { + case ov::element::f64: diff --git a/pkgs/by-name/op/openvino-genai/package.nix b/pkgs/by-name/op/openvino-genai/package.nix new file mode 100644 index 000000000000..0606317d2164 --- /dev/null +++ b/pkgs/by-name/op/openvino-genai/package.nix @@ -0,0 +1,205 @@ +{ + lib, + stdenv, + fetchFromGitHub, + autoPatchelfHook, + cmake, + gtest, + nix-update-script, + nlohmann_json, + ocl-icd, + opencl-clhpp, + opencl-headers, + onetbb, + openvino, + openvino-tokenizers, + pkg-config, + python3Packages, +}: + +let + inherit (lib) cmakeBool cmakeFeature; + + minja-src = fetchFromGitHub { + owner = "google"; + repo = "minja"; + rev = "3e4c61c616eda133cfb1e440fc7a14bf1729bbee"; + hash = "sha256-aqOpLNB7XiY/W2gDRtnAqx37gMhHMRCJQmcX24vGIxA="; + }; + + safetensors-h-src = fetchFromGitHub { + owner = "hsnyder"; + repo = "safetensors.h"; + rev = "974a85d7dfd6e010558353226638bb26d6b9d756"; + hash = "sha256-sBgm4panHB9X2RghC3Qi0wEL0k9uUz+h60pfxTGZ0BA="; + }; + + gguflib-src = fetchFromGitHub { + owner = "Lourdle"; + repo = "gguf-tools"; + rev = "bac796ada809ac293e685db59b075971181cb008"; + hash = "sha256-yoIjTATYs2IzT/LnCz+G6PtxVXZ27B0mZOIipZbaOI8="; + }; + + python = python3Packages.python.withPackages (ps: [ ps.pybind11 ]); +in + +stdenv.mkDerivation (finalAttrs: { + pname = "openvino-genai"; + version = "2026.2.0.0"; + + __structuredAttrs = true; + + src = + assert lib.hasPrefix openvino.version finalAttrs.version; + fetchFromGitHub { + owner = "openvinotoolkit"; + repo = "openvino.genai"; + tag = finalAttrs.version; + hash = "sha256-C60e4F+NuUPA4pQ/o2+EekOmp47QH1fTGDyXYqPJ57s="; + }; + + outputs = [ + "out" + "dev" + "python" + ]; + + nativeBuildInputs = [ + autoPatchelfHook + cmake + pkg-config + python + ]; + + buildInputs = [ + nlohmann_json + ocl-icd + opencl-clhpp + opencl-headers + onetbb + openvino + ]; + + strictDeps = true; + + patches = [ + # gguf_utils' format() is a function template declared in gguf.hpp but + # defined in gguf.cpp, so instantiations from other TUs are unresolved at + # link time (surfaces as an ImportError on libopenvino_genai.so load). + # Move the definition into the header. + ./move-gguf-format-template-into-header.patch + ]; + + postPatch = '' + # pybind11 3.0 removed keep_alive support from def_property/def_readwrite. + # parsers is vector> so shared_ptr ref-counting is sufficient. + substituteInPlace src/python/py_generation_config.cpp \ + --replace-fail ', py::keep_alive<1, 2>()' "" + ''; + + cmakeFlags = [ + # Point cmake's FetchContent at pre-packaged nixpkgs sources so nothing is + # downloaded at build time. + (cmakeFeature "FETCHCONTENT_SOURCE_DIR_NLOHMANN_JSON" "${nlohmann_json.src}") + (cmakeFeature "FETCHCONTENT_SOURCE_DIR_MINJA" "${minja-src}") + (cmakeFeature "FETCHCONTENT_SOURCE_DIR_SAFETENSORS.H" "${safetensors-h-src}") + (cmakeFeature "FETCHCONTENT_SOURCE_DIR_PYBIND11" "${python3Packages.pybind11.src}") + (cmakeFeature "FETCHCONTENT_SOURCE_DIR_GGUFLIB" "${gguflib-src}") + (cmakeFeature "FETCHCONTENT_SOURCE_DIR_GOOGLETEST" "${gtest.src}") + (cmakeFeature "Python3_EXECUTABLE" "${python.interpreter}") + (cmakeFeature "OpenVINO_DIR" "${openvino}/runtime/cmake") + + # Normalise install destinations to the standard Nix layout. + (cmakeFeature "ARCHIVE_DESTINATION" "lib") + (cmakeFeature "LIBRARY_DESTINATION" "lib") + (cmakeFeature "RUNTIME_DESTINATION" "bin") + + (cmakeBool "ENABLE_SYSTEM_OPENCL" true) + # Tokenizers are provided at runtime by openvino-tokenizers (C++) and + # python3Packages.openvino-tokenizers; don't build them into this output. + (cmakeBool "BUILD_TOKENIZERS" false) + (cmakeBool "ENABLE_GGUF" true) + (cmakeBool "ENABLE_PYTHON" true) + (cmakeBool "ENABLE_SAMPLES" false) + (cmakeBool "ENABLE_TESTS" true) + (cmakeBool "ENABLE_TOOLS" false) + (cmakeBool "ENABLE_XGRAMMAR" false) + ]; + + postInstall = '' + # cmake installs to runtime/{include,cmake,lib/...}; move to standard paths. + mkdir -p $dev/include $dev/lib/cmake $out/lib + cp -r $out/runtime/include/. $dev/include/ + cp -r $out/runtime/cmake/. $dev/lib/cmake/ + + # Copy any shared libraries cmake put in runtime/lib subdirs (e.g. intel64/) + # before we remove the runtime/ tree. + find $out/runtime \( -name '*.so' -o -name '*.so.*' \) -print0 \ + | xargs -0r cp -Pft $out/lib/ + rm -rf $out/runtime + + # The generated cmake targets files compute _IMPORT_PREFIX relative to + # their location and use it to reference headers and libraries; fix those + # paths to absolute nix store paths since we've reorganised the tree. + substituteInPlace $dev/lib/cmake/OpenVINOGenAITargets.cmake \ + --replace-fail \ + "\''${_IMPORT_PREFIX}/runtime/include" "$dev/include" + substituteInPlace $dev/lib/cmake/OpenVINOGenAITargets-release.cmake \ + --replace-fail \ + "\''${_IMPORT_PREFIX}/runtime/lib/intel64/" "$out/lib/" + ''; + + postFixup = '' + # Split Python module into its own output. + mkdir -p $python + cp -r $out/python/. $python/ + rm -rf $out/python + + # Help autoPatchelfHook find: (1) libopenvino_genai.so.* in our own $out/lib + # when patching the $python output, (2) libopenvino.so.* which openvino + # installs to runtime/lib/intel64/ instead of lib/. + autoPatchelfLibs+=("$out/lib" "${openvino}/runtime/lib/intel64") + ''; + + nativeCheckInputs = [ openvino-tokenizers ]; + + doCheck = true; + + preCheck = '' + mkdir -p tests/cpp/data + cp -r ${finalAttrs.src}/tests/cpp/data/. tests/cpp/data/ + export OPENVINO_TOKENIZERS_PATH_GENAI="${openvino-tokenizers}/lib/libopenvino_tokenizers.so" + ''; + + checkPhase = '' + runHook preCheck + # GetCacheTypesRealModel and LLMPipelineBackendRealModel require on-disk + # model data (CACHE_TYPES_CSV + TEST_MODELS_BASE_DIR) unavailable in the + # Nix sandbox; with zero ValuesIn entries GTest ≥ 1.12 reports them via + # GoogleTestVerification.UninstantiatedParameterizedTestSuite<*>, so + # exclude that verification check for these two suites. + ./tests/cpp/tests_continuous_batching \ + --gtest_filter="-GoogleTestVerification.UninstantiatedParameterizedTestSuite*" + runHook postCheck + ''; + + enableParallelBuilding = true; + + passthru.updateScript = nix-update-script { }; + + meta = { + description = "Generative AI inference pipeline library built on OpenVINO Runtime"; + longDescription = '' + OpenVINO GenAI provides a high-level C++ and Python API for running large + language models and other generative AI workloads using OpenVINO Runtime as + the inference backend. It supports continuous batching, speculative decoding, + and a range of text, image, and speech generation pipelines. + ''; + homepage = "https://github.com/openvinotoolkit/openvino.genai"; + changelog = "https://github.com/openvinotoolkit/openvino.genai/releases/tag/${finalAttrs.src.tag}"; + license = lib.licenses.asl20; + platforms = lib.platforms.linux; + maintainers = with lib.maintainers; [ jpds ]; + }; +})