Skip to content

Commit 4fb48de

Browse files
[JS] Add GenAI Node.js bindings (openvinotoolkit#1193)
Adding Node.js bindings for GenAI pipelines. - 155187 - 158132 ## Limitations Current version it's primary backbone of future development. Supports bindings of `LLMPipeline` only. ## TODO - [x] Test build configuration - [x] Integrate unit tests run into GHA - [ ] Add script to download runtime binaries (after binaries publication) --------- Co-authored-by: Vladimir Zlobin <vladimir.zlobin@intel.com>
1 parent 4521bb6 commit 4fb48de

39 files changed

+2062
-37
lines changed

.github/workflows/linux.yml

+116-32
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
runs-on: aks-linux-2-cores-8gb
4343
container:
4444
image: 'openvinogithubactions.azurecr.io/openvino_provider:0.1.0'
45-
volumes:
45+
volumes:
4646
- /mount:/mount
4747
- ${{ github.workspace }}:${{ github.workspace }}
4848

@@ -114,11 +114,11 @@ jobs:
114114
cmake -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} -S ${{ env.SRC_DIR}} -B ${{ env.BUILD_DIR }}
115115
cmake --build ${{ env.BUILD_DIR}} --config ${{ matrix.build-type }} --parallel $(nproc) --verbose
116116
cmake --install ${{ env.BUILD_DIR }} --config ${{ matrix.build-type }} --prefix ${{ env.INSTALL_DIR }}
117-
117+
118118
- name: Pack Artifacts
119119
run: tar -cvf - * | pigz > ${{ env.BUILD_DIR }}/${{ env.GENAI_ARCHIVE_NAME }}
120120
working-directory: ${{ env.INSTALL_DIR }}
121-
121+
122122
- name: Upload Archive Distribution Package
123123
if: ${{ always() }}
124124
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
@@ -137,7 +137,7 @@ jobs:
137137
runs-on: aks-linux-4-cores-16gb
138138
container:
139139
image: openvinogithubactions.azurecr.io/ov_build/ubuntu_22_04_x64:${{ needs.openvino_download.outputs.docker_tag }}
140-
volumes:
140+
volumes:
141141
- /mount:/mount
142142
- ${{ github.workspace }}:${{ github.workspace }}
143143
options: -e SCCACHE_AZURE_BLOB_CONTAINER -e SCCACHE_AZURE_CONNECTION_STRING
@@ -161,35 +161,35 @@ jobs:
161161
name: ${{ needs.openvino_download.outputs.ov_artifact_name }}
162162
path: ${{ env.OV_INSTALL_DIR }}
163163
merge-multiple: true
164-
164+
165165
- name: Build Tokenizers Wheel
166166
run: |
167167
python -m pip wheel -v --no-deps --wheel-dir ${{ env.WHEELS_DIR }} \
168168
--config-settings=override=cross.arch="manylinux_2_31_x86_64" \
169169
${{ needs.openvino_download.outputs.ov_wheel_source }} \
170170
${{ env.SRC_DIR }}/thirdparty/openvino_tokenizers
171171
working-directory: ${{ env.OV_INSTALL_DIR }}
172-
172+
173173
- name: Build GenAI Wheel
174174
run: |
175175
python -m pip wheel -v --no-deps --wheel-dir ${{ env.WHEELS_DIR }} \
176176
--config-settings=override=cross.arch="manylinux_2_31_x86_64" \
177177
${{ needs.openvino_download.outputs.ov_wheel_source }} \
178178
${{ env.SRC_DIR }}
179179
working-directory: ${{ env.OV_INSTALL_DIR }}
180-
180+
181181
- name: Build WWB Wheel
182182
run: python -m pip wheel -v --no-deps --wheel-dir ${{ env.WHEELS_DIR }} ${{ env.SRC_DIR }}/tools/who_what_benchmark
183183
working-directory: ${{ env.OV_INSTALL_DIR }}
184-
184+
185185
- name: Upload Wheels
186186
if: ${{ always() }}
187187
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
188188
with:
189189
name: genai_wheels
190190
path: ${{ env.INSTALL_DIR }}
191191
if-no-files-found: 'error'
192-
192+
193193
genai_build_samples:
194194
name: Build Samples - ${{ matrix.build-type }}
195195
strategy:
@@ -204,7 +204,7 @@ jobs:
204204
runs-on: aks-linux-2-cores-8gb
205205
container:
206206
image: openvinogithubactions.azurecr.io/ov_build/ubuntu_22_04_x64:${{ needs.openvino_download.outputs.docker_tag }}
207-
volumes:
207+
volumes:
208208
- /mount:/mount
209209
- ${{ github.workspace }}:${{ github.workspace }}
210210
options: -e SCCACHE_AZURE_BLOB_CONTAINER -e SCCACHE_AZURE_CONNECTION_STRING
@@ -228,25 +228,25 @@ jobs:
228228
pattern: "{${{ needs.openvino_download.outputs.ov_artifact_name }},genai_archive_${{ matrix.build-type }}}"
229229
path: ${{ env.OV_INSTALL_DIR }}
230230
merge-multiple: true
231-
231+
232232
- name: Extract Artifacts
233233
run: pigz -dc ${{ env.GENAI_ARCHIVE_NAME }} | tar -xf - -C ${{ env.OV_INSTALL_DIR }}
234234
working-directory: ${{ env.OV_INSTALL_DIR }}
235-
235+
236236
- name: Build Samples (Release)
237237
if: ${{ 'Release' == matrix.build-type }}
238238
run: |
239239
chmod +x ${{ env.OV_INSTALL_DIR }}/samples/cpp/build_samples.sh
240240
${{ env.OV_INSTALL_DIR }}/samples/cpp/build_samples.sh -i ${{ env.INSTALL_DIR }}
241-
241+
242242
- name: Build Samples (${{ matrix.build-type }})
243243
if: ${{ 'Release' != matrix.build-type }}
244244
run: |
245245
source ${{ env.OV_INSTALL_DIR }}/setupvars.sh
246246
cmake -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} -S ${{ env.OV_INSTALL_DIR }}/samples/cpp/ -B ${{ env.BUILD_DIR }}
247247
cmake --build ${{ env.BUILD_DIR }} --config ${{ matrix.build-type }} --parallel $(nproc)
248248
cmake --install ${{ env.BUILD_DIR }} --config ${{ matrix.build-type }} --component samples_bin --prefix ${{ env.INSTALL_DIR }}
249-
249+
250250
- name: Pack Artifacts
251251
run: tar -cvf - * | pigz > ${{ env.INSTALL_DIR }}/${{ env.GENAI_SAMPLES_NAME }}
252252
working-directory: ${{ env.INSTALL_DIR }}
@@ -258,7 +258,7 @@ jobs:
258258
name: genai_samples_${{ matrix.build-type }}
259259
path: ${{ env.INSTALL_DIR }}/*.tar.gz
260260
if-no-files-found: 'error'
261-
261+
262262
genai_tests_wheel:
263263
name: Python (${{ matrix.test.name}}) Tests (wheel)
264264
needs: [ openvino_download, genai_build_wheel ]
@@ -279,7 +279,7 @@ jobs:
279279
runs-on: aks-linux-4-cores-16gb
280280
container:
281281
image: openvinogithubactions.azurecr.io/ov_test/ubuntu_22_04_x64:${{ needs.openvino_download.outputs.docker_tag }}
282-
volumes:
282+
volumes:
283283
- /mount:/mount
284284
- ${{ github.workspace }}:${{ github.workspace }}
285285

@@ -289,47 +289,47 @@ jobs:
289289
BUILD_DIR: ${{ github.workspace }}/build
290290
TRANSFORMERS_CACHE: ${{ github.workspace }}/models # Hugging Face transformers cache
291291
HF_HOME: ${{ github.workspace }}/datasets # Hugging Face datasets cache
292-
292+
293293
steps:
294294
- name: Clone openvino.genai
295295
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
296296
with:
297297
path: ${{ env.SRC_DIR }}
298298
submodules: recursive
299-
299+
300300
- name: Download Build Artifacts
301301
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
302302
with:
303303
pattern: "{${{ needs.openvino_download.outputs.ov_artifact_name }},genai_wheels}"
304304
path: ${{ env.INSTALL_DIR }}
305305
merge-multiple: true
306-
306+
307307
- name: Install GenAI Wheels
308308
uses: ./src/.github/actions/install_wheel
309309
with:
310310
packages: "openvino;openvino_tokenizers[transformers];openvino_genai;whowhatbench"
311311
requirements_files: "${{ env.SRC_DIR }}/tests/python_tests/requirements.txt"
312312
local_wheel_dir: ${{ env.INSTALL_DIR }}/wheels
313-
313+
314314
- name: Tests
315315
run: python -m pytest -v ./${{ matrix.test.cmd }}
316316
working-directory: ${{ env.SRC_DIR }}
317-
317+
318318
genai_samples_tests:
319319
name: Samples Tests - ${{ matrix.build-type }}
320320
strategy:
321321
fail-fast: false
322322
matrix:
323323
build-type: [Release]
324-
needs: [ openvino_download, genai_build_cmake, genai_build_wheel, genai_build_samples ]
324+
needs: [ openvino_download, genai_build_cmake, genai_build_wheel, genai_build_samples ]
325325
timeout-minutes: 45
326326
defaults:
327327
run:
328328
shell: bash
329329
runs-on: aks-linux-2-cores-8gb
330330
container:
331331
image: openvinogithubactions.azurecr.io/ov_test/ubuntu_22_04_x64:${{ needs.openvino_download.outputs.docker_tag }}
332-
volumes:
332+
volumes:
333333
- /mount:/mount
334334
- ${{ github.workspace }}:${{ github.workspace }}
335335

@@ -338,41 +338,41 @@ jobs:
338338
SRC_DIR: ${{ github.workspace }}/src
339339
BUILD_DIR: ${{ github.workspace }}/build
340340
MODELS_DIR: ${{ github.workspace }}/models
341-
341+
342342
steps:
343343
- name: Clone openvino.genai
344344
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
345345
with:
346346
path: ${{ env.SRC_DIR }}
347347
submodules: recursive
348-
348+
349349
- name: Download Build Artifacts
350350
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
351351
with:
352352
pattern: "{${{ needs.openvino_download.outputs.ov_artifact_name }},genai_archive_${{ matrix.build-type }},genai_samples_${{ matrix.build-type }},genai_wheels}"
353353
path: ${{ env.INSTALL_DIR }}
354354
merge-multiple: true
355-
355+
356356
- name: Extract Artifacts
357357
run: |
358358
pigz -dc ${{ env.GENAI_ARCHIVE_NAME }} | tar -xf - -C ${{ env.INSTALL_DIR }}
359359
pigz -dc ${{ env.GENAI_SAMPLES_NAME }} | tar -xf - -C ${{ env.INSTALL_DIR }}
360360
working-directory: ${{ env.INSTALL_DIR }}
361-
361+
362362
- name: Install Wheels
363363
uses: ./src/.github/actions/install_wheel
364364
with:
365365
packages: "openvino;openvino_tokenizers[transformers];openvino_genai"
366366
requirements_files: "${{ env.SRC_DIR }}/samples/requirements.txt"
367367
local_wheel_dir: ${{ env.INSTALL_DIR }}/wheels
368-
368+
369369
- name: Download & convert Models and data
370370
run: |
371371
mkdir -p ${{ env.MODELS_DIR }}
372372
optimum-cli export openvino --trust-remote-code --model TinyLlama/TinyLlama-1.1B-Chat-v1.0 ${{ env.MODELS_DIR }}/TinyLlama-1.1B-Chat-v1.0
373373
optimum-cli export openvino --trust-remote-code --model openai/whisper-tiny ${{ env.MODELS_DIR }}/whisper-tiny
374374
wget https://storage.openvinotoolkit.org/models_contrib/speech/2021.2/librispeech_s5/how_are_you_doing_today.wav -O ${{ env.MODELS_DIR }}/how_are_you_doing_today.wav
375-
375+
376376
- name: Test multinomial_causal_lm.py
377377
if: ${{ 'Release' == matrix.build-type }} # Python bindings can be built in Release only
378378
timeout-minutes: 1
@@ -384,10 +384,10 @@ jobs:
384384
timeout-minutes: 1
385385
run: ${{ env.INSTALL_DIR }}/samples/python/whisper_speech_recognition/whisper_speech_recognition.py ./whisper-tiny/ how_are_you_doing_today.wav
386386
working-directory: ${{ env.MODELS_DIR }}
387-
387+
388388
- name: C++ Tests Prerequisites
389389
run: python -m pip uninstall openvino openvino-tokenizers openvino-genai -y
390-
390+
391391
- name: Test greedy_causal_lm
392392
run: |
393393
source ${{ env.INSTALL_DIR }}/setupvars.sh
@@ -400,9 +400,93 @@ jobs:
400400
${{ env.INSTALL_DIR }}/samples_bin/whisper_speech_recognition ./whisper-tiny/ how_are_you_doing_today.wav
401401
working-directory: ${{ env.MODELS_DIR }}
402402

403+
genai_build_nodejs_bindings:
404+
name: Build Node.js bindings
405+
strategy:
406+
fail-fast: false
407+
matrix:
408+
build-type: [Release]
409+
needs: [ openvino_download ]
410+
timeout-minutes: 20
411+
defaults:
412+
run:
413+
shell: bash
414+
runs-on: aks-linux-4-cores-16gb
415+
container:
416+
image: openvinogithubactions.azurecr.io/ov_build/ubuntu_22_04_x64:${{ needs.openvino_download.outputs.docker_tag }}
417+
volumes:
418+
- /mount:/mount
419+
options: -e SCCACHE_AZURE_BLOB_CONTAINER -e SCCACHE_AZURE_CONNECTION_STRING -v ${{ github.workspace }}:${{ github.workspace }}
420+
env:
421+
CMAKE_GENERATOR: Unix Makefiles
422+
OV_INSTALL_DIR: ${{ github.workspace }}/ov
423+
BUILD_DIR: ${{ github.workspace }}/build
424+
SRC_DIR: ${{ github.workspace }}/src
425+
426+
steps:
427+
- name: Clone openvino.genai
428+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
429+
with:
430+
path: ${{ env.SRC_DIR }}
431+
submodules: recursive
432+
433+
- name: Download OpenVINO package
434+
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
435+
with:
436+
name: ${{ needs.openvino_download.outputs.ov_artifact_name }}
437+
path: ${{ env.OV_INSTALL_DIR }}
438+
merge-multiple: true
439+
440+
- name: Build with ENABLE_JS=ON
441+
run: |
442+
source ${{ env.OV_INSTALL_DIR }}/setupvars.sh
443+
cmake -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} -DENABLE_JS=ON -S ${{ env.SRC_DIR }} -B ${{ env.BUILD_DIR }}
444+
cmake --build ${{ env.BUILD_DIR }} --config ${{ matrix.build-type }} --parallel $(nproc) --verbose
445+
cmake --install ${{ env.BUILD_DIR }} --config ${{ matrix.build-type }} --prefix ${{ env.OV_INSTALL_DIR }}
446+
447+
- name: Combine binaries for Node.js package
448+
run: |
449+
mkdir -p nodejs
450+
cp -r runtime/lib/intel64/* nodejs
451+
cp -r runtime/3rdparty/tbb/lib/* nodejs
452+
cp genai_node_addon.node nodejs
453+
GENAI_VERSION=$(grep -oP '(?<=CMAKE_PROJECT_VERSION:STATIC=)[^"]*' ${{ env.BUILD_DIR }}/CMakeCache.txt)
454+
OV_VERSION=$(echo $GENAI_VERSION | sed 's/..$//')
455+
patchelf --set-rpath '$ORIGIN' nodejs/libopenvino.so.$OV_VERSION nodejs/libopenvino_genai.so.$GENAI_VERSION
456+
working-directory: ${{ env.OV_INSTALL_DIR }}
457+
458+
- name: Pack Node.js bindings libs
459+
run: tar -cvf - * | pigz > ${{ env.BUILD_DIR }}/genai_nodejs_bindings.tar.gz
460+
working-directory: ${{ env.OV_INSTALL_DIR }}/nodejs
461+
462+
- name: Upload Archive Package with Node.js bindings
463+
if: ${{ always() }}
464+
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
465+
with:
466+
name: genai_nodejs_bindings
467+
path: ${{ env.BUILD_DIR }}/genai_nodejs_bindings.tar.gz
468+
if-no-files-found: 'error'
469+
470+
- name: Run npm package tests
471+
working-directory: ${{ env.SRC_DIR }}/src/js
472+
run: |
473+
cp -R ${{ env.OV_INSTALL_DIR }}/nodejs bin
474+
npm install
475+
npm test
476+
477+
- name: Install genai-node samples dependencies
478+
run: npm install
479+
working-directory: ${{ env.SRC_DIR }}/samples/js/text_generation
480+
481+
- name: Run samples tests
482+
run: npm test
483+
env:
484+
MODEL_PATH: ${{ env.SRC_DIR }}/src/js/tests/models/Llama-3.1-8B-Instruct-FastDraft-150M-int8-ov
485+
working-directory: ${{ env.SRC_DIR }}/samples/js/text_generation
486+
403487
Overall_Status:
404488
name: ci/gha_overall_status_linux
405-
needs: [openvino_download, genai_build_cmake, genai_build_wheel, genai_build_samples, genai_tests_wheel, genai_samples_tests]
489+
needs: [openvino_download, genai_build_cmake, genai_build_wheel, genai_build_samples, genai_tests_wheel, genai_samples_tests, genai_build_nodejs_bindings]
406490
if: ${{ always() }}
407491
runs-on: ubuntu-latest
408492
steps:

CMakeLists.txt

+4-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ endif()
8888

8989
add_subdirectory(thirdparty)
9090
add_subdirectory(src)
91-
if(EXISTS "${OpenVINOGenAI_SOURCE_DIR}/samples")
91+
if(EXISTS "${OpenVINOGenAI_SOURCE_DIR}/samples" AND ENABLE_SAMPLES)
9292
add_subdirectory(samples)
9393
endif()
9494
if(EXISTS "${OpenVINOGenAI_SOURCE_DIR}/tools/continuous_batching")
@@ -109,6 +109,9 @@ set(CPACK_COMPONENTS_ALL core_genai core_genai_dev cpp_samples_genai licensing_g
109109
if(ENABLE_PYTHON)
110110
list(APPEND CPACK_COMPONENTS_ALL pygenai_${Python3_VERSION_MAJOR}_${Python3_VERSION_MINOR})
111111
endif()
112+
if(ENABLE_JS)
113+
list(APPEND CPACK_COMPONENTS_ALL genai_node_addon)
114+
endif()
112115
if(WIN32 AND NOT DEFINED CPACK_GENERATOR)
113116
set(CPACK_GENERATOR "ZIP")
114117
endif()

cmake/features.cmake

+7
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,10 @@
33
#
44

55
option(ENABLE_PYTHON "Enable Python API build" ON)
6+
option(ENABLE_JS "Enable JS API build" OFF)
7+
option(ENABLE_SAMPLES "Enable samples build" ON)
8+
9+
# Disable building samples for NPM package
10+
if(CPACK_GENERATOR STREQUAL "NPM")
11+
set(ENABLE_SAMPLES OFF)
12+
endif()

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ find_python3 = true
4747
build_args = ["--parallel", "--target", "py_openvino_genai_stub"]
4848
install_args = ["--strip"]
4949
install_components = ["wheel_genai"]
50-
options = {"BUILD_TOKENIZERS" = "OFF"}
50+
options = {"BUILD_TOKENIZERS" = "OFF", "ENABLE_SAMPLES" = "OFF"}
5151

5252
[build-system]
5353
requires = [

samples/js/text_generation/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

0 commit comments

Comments
 (0)