Skip to content

Commit 831e0f0

Browse files
Add running greedy_causal_lm for JS to the sample tests (#1930)
## Tickets: - CVS-155716 - CVS-155718 --------- Signed-off-by: Kirill Suvorov <kirill.suvorov@intel.com>
1 parent e0ce5bf commit 831e0f0

File tree

6 files changed

+134
-6
lines changed

6 files changed

+134
-6
lines changed

.github/workflows/linux.yml

+33-1
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ jobs:
435435
cmd: 'tests/python_tests/samples'
436436
runner: 'aks-linux-8-cores-64gb'
437437

438-
needs: [ openvino_download, genai_build_cmake, genai_build_wheel, genai_build_samples ]
438+
needs: [ openvino_download, genai_build_cmake, genai_build_wheel, genai_build_samples, genai_build_nodejs ]
439439
timeout-minutes: 60
440440
defaults:
441441
run:
@@ -465,6 +465,14 @@ jobs:
465465
pattern: "{${{ needs.openvino_download.outputs.ov_artifact_name }},genai_archive_${{ matrix.build-type }},genai_samples_${{ matrix.build-type }},genai_wheels}"
466466
path: ${{ env.INSTALL_DIR }}
467467
merge-multiple: true
468+
469+
- name: Download GenAI JS Bildings Artifacts
470+
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
471+
if: ${{ 'LLM' == matrix.test.name }}
472+
with:
473+
name: genai_nodejs_bindings
474+
path: ${{ env.SRC_DIR }}/src/js/bin
475+
merge-multiple: true
468476

469477
- name: Extract Artifacts
470478
run: |
@@ -484,11 +492,35 @@ jobs:
484492
requirements_files: "${{ env.SRC_DIR }}/samples/requirements.txt"
485493
local_wheel_dir: ${{ env.INSTALL_DIR }}/wheels
486494

495+
- name: Setup Node
496+
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
497+
if: ${{ 'LLM' == matrix.test.name }}
498+
with:
499+
node-version: 21
500+
501+
- name: Install GenAI NPM package
502+
working-directory: ${{ env.SRC_DIR }}/src/js
503+
if: ${{ 'LLM' == matrix.test.name }}
504+
run: |
505+
npm install --verbose
506+
rm -rf node_modules/openvino-node/bin
507+
cp -R ${{ env.INSTALL_DIR }}/openvino_js_package node_modules/openvino-node/bin
508+
cd ${{ env.SRC_DIR }}/samples/js/text_generation
509+
510+
- name: Install NPM dependencies for samples
511+
working-directory: ${{ env.SRC_DIR }}/samples/js/text_generation
512+
if: ${{ 'LLM' == matrix.test.name }}
513+
run: |
514+
npm install --verbose
515+
rm -rf node_modules/openvino-node/bin
516+
cp -R ${{ env.INSTALL_DIR }}/openvino_js_package node_modules/openvino-node/bin
517+
487518
- name: Test Samples (Python and C++)
488519
run: python -m pytest -vs ${{ env.SRC_DIR }}/${{ matrix.test.cmd }} -m "${{ matrix.test.marker }}"
489520
env:
490521
LD_LIBRARY_PATH: "${{ env.INSTALL_DIR }}/runtime/lib/intel64:${{ env.INSTALL_DIR }}/runtime/3rdparty/tbb/lib:$LD_LIBRARY_PATH" # Required for C++ samples
491522
SAMPLES_PY_DIR: "${{ env.INSTALL_DIR }}/samples/python"
523+
SAMPLES_JS_DIR: "${{ env.SRC_DIR }}/samples/js"
492524
SAMPLES_CPP_DIR: "${{ env.INSTALL_DIR }}/samples_bin"
493525
SAMPLES_C_DIR: "${{ env.INSTALL_DIR }}/samples_bin"
494526

.github/workflows/mac.yml

+36-1
Original file line numberDiff line numberDiff line change
@@ -435,14 +435,15 @@ jobs:
435435
- name: 'Whisper'
436436
marker: 'whisper'
437437
cmd: 'tests/python_tests/samples'
438-
needs: [ openvino_download, genai_build_cmake, genai_build_wheel, genai_build_samples ]
438+
needs: [ openvino_download, genai_build_cmake, genai_build_wheel, genai_build_samples, genai_build_nodejs ]
439439
timeout-minutes: 45
440440
defaults:
441441
run:
442442
shell: bash
443443
runs-on: macos-13
444444
env:
445445
INSTALL_DIR: ${{ github.workspace }}/ov
446+
LATEST_OV_DIR: ${{ github.workspace }}/ov_latest
446447
SRC_DIR: ${{ github.workspace }}/src
447448
BUILD_DIR: ${{ github.workspace }}/build
448449

@@ -460,6 +461,20 @@ jobs:
460461
path: ${{ env.INSTALL_DIR }}
461462
merge-multiple: true
462463

464+
- name: Download OpenVINO JS Bildings Artifacts
465+
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
466+
with:
467+
name: ${{ needs.openvino_download.outputs.ov_latest_artifact_name }}
468+
path: ${{ env.LATEST_OV_DIR }}
469+
merge-multiple: true
470+
471+
- name: Download GenAI JS Bildings Artifacts
472+
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
473+
with:
474+
name: genai_nodejs_bindings
475+
path: ${{ env.SRC_DIR }}/src/js/bin
476+
merge-multiple: true
477+
463478
- name: Setup Python ${{ env.PYTHON_VERSION }}
464479
uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5.4.0
465480
with:
@@ -481,12 +496,32 @@ jobs:
481496
- name: Fix C++ samples permissions
482497
run: chmod +x ${{ env.INSTALL_DIR }}/samples_bin/*
483498

499+
- name: Setup NodeJS
500+
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
501+
with:
502+
node-version: 21
503+
504+
- name: Install GenAI NPM package
505+
working-directory: ${{ env.SRC_DIR }}/src/js
506+
run: |
507+
npm install --verbose
508+
rm -rf node_modules/openvino-node/bin
509+
cp -R ${{ env.LATEST_OV_DIR }}/openvino_js_package node_modules/openvino-node/bin
510+
511+
- name: Install NPM dependencies for samples
512+
working-directory: ${{ env.SRC_DIR }}/samples/js/text_generation
513+
run: |
514+
npm install --verbose
515+
rm -rf node_modules/openvino-node/bin
516+
cp -R ${{ env.LATEST_OV_DIR }}/openvino_js_package node_modules/openvino-node/bin
517+
484518
- name: Test Samples (Python and C++)
485519
run: |
486520
source ${{ env.INSTALL_DIR }}/setupvars.sh
487521
python -m pytest -vs ${{ env.SRC_DIR }}/${{ matrix.test.cmd }} -m "${{ matrix.test.marker }}"
488522
env:
489523
SAMPLES_PY_DIR: "${{ env.INSTALL_DIR }}/samples/python"
524+
SAMPLES_JS_DIR: "${{ env.SRC_DIR }}/samples/js"
490525
SAMPLES_CPP_DIR: "${{ env.INSTALL_DIR }}/samples_bin"
491526
SAMPLES_C_DIR: "${{ env.INSTALL_DIR }}/samples_bin"
492527

.github/workflows/windows.yml

+29-2
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ jobs:
473473
marker: 'image_generation'
474474
cmd: 'tests/python_tests/samples'
475475
runner: 'aks-win-8-cores-16gb'
476-
needs: [ openvino_download, genai_build_cpack, genai_build_wheel, genai_build_samples ]
476+
needs: [ openvino_download, genai_build_cpack, genai_build_wheel, genai_build_samples, genai_build_nodejs ]
477477
timeout-minutes: 60
478478
defaults:
479479
run:
@@ -499,7 +499,14 @@ jobs:
499499
pattern: "{${{ needs.openvino_download.outputs.ov_artifact_name }},genai_cpack_${{ matrix.build-type }},genai_samples_${{ matrix.build-type }},genai_wheels}"
500500
path: ${{ env.INSTALL_DIR }}
501501
merge-multiple: true
502-
502+
503+
- name: Download GenAI JS Bildings Artifacts
504+
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
505+
with:
506+
name: genai_nodejs_bindings
507+
path: ${{ env.SRC_DIR }}/src/js/bin
508+
merge-multiple: true
509+
503510
- name: Setup Python ${{ env.PYTHON_VERSION }}
504511
uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5.4.0
505512
with:
@@ -517,11 +524,31 @@ jobs:
517524
requirements_files: "${{ env.SRC_DIR }}/samples/requirements.txt"
518525
local_wheel_dir: ${{ env.INSTALL_DIR }}/wheels
519526

527+
- name: Setup NodeJS
528+
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
529+
with:
530+
node-version: 21
531+
532+
- name: Install GenAI NPM package
533+
working-directory: ${{ env.SRC_DIR }}/src/js
534+
run: |
535+
npm install --verbose
536+
Remove-Item -Recurse -Force node_modules/openvino-node/bin
537+
Copy-Item -Recurse ${{ env.INSTALL_DIR }}/openvino_js_package node_modules/openvino-node/bin
538+
539+
- name: Install NPM dependencies for samples
540+
working-directory: ${{ env.SRC_DIR }}/samples/js/text_generation
541+
run: |
542+
npm install --verbose
543+
Remove-Item -Recurse -Force node_modules/openvino-node/bin
544+
Copy-Item -Recurse ${{ env.INSTALL_DIR }}/openvino_js_package node_modules/openvino-node/bin
545+
520546
- name: Test Samples (Python and C++)
521547
run: python -m pytest -vs ${{ env.SRC_DIR }}/${{ matrix.test.cmd }} -m "${{ matrix.test.marker }}"
522548
env:
523549
PATH: "${{ env.INSTALL_DIR }}/runtime/bin/intel64/${{ matrix.build-type }};${{ env.INSTALL_DIR }}/runtime/3rdparty/tbb/bin;%PATH%" # Required for C++ samples
524550
SAMPLES_PY_DIR: "${{ env.INSTALL_DIR }}/samples/python"
551+
SAMPLES_JS_DIR: "${{ env.SRC_DIR }}/samples/js"
525552
SAMPLES_CPP_DIR: "${{ env.INSTALL_DIR }}/samples_bin"
526553
SAMPLES_C_DIR: "${{ env.INSTALL_DIR }}/samples_bin"
527554

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { LLMPipeline } from 'openvino-genai-node';
2+
3+
main();
4+
5+
async function main() {
6+
const modelPath = process.argv[2];
7+
const prompt = process.argv[3];
8+
9+
if (!modelPath) {
10+
console.error('Please specify path to model directory\n'
11+
+ 'Run command must be: `node chat_sample.js *path_to_model_dir* *prompt*`');
12+
process.exit(1);
13+
}
14+
if (!modelPath) {
15+
console.error('Please specify prompt\n'
16+
+ 'Run command must be: `node chat_sample.js *path_to_model_dir* *prompt*`');
17+
process.exit(1);
18+
}
19+
20+
const device = 'CPU'; // GPU can be used as well
21+
const pipe = await LLMPipeline(modelPath, device);
22+
23+
const config = { 'max_new_tokens': 100 };
24+
const result = await pipe.generate(prompt, config);
25+
26+
console.log(result);
27+
}

tests/python_tests/samples/conftest.py

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
SAMPLES_PY_DIR = os.environ.get("SAMPLES_PY_DIR", os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../samples/python")))
105105
SAMPLES_CPP_DIR = os.environ.get("SAMPLES_CPP_DIR", os.getcwd())
106106
SAMPLES_C_DIR = os.environ.get("SAMPLES_CPP_DIR", os.getcwd())
107+
SAMPLES_JS_DIR = os.environ.get("SAMPLES_JS_DIR", os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../samples/js")))
107108

108109
@pytest.fixture(scope="session", autouse=True)
109110
def setup_and_teardown(request, tmp_path_factory):

tests/python_tests/samples/test_greedy_causal_lm.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import pytest
66
import sys
77

8-
from conftest import logger, MODELS, SAMPLES_PY_DIR, SAMPLES_CPP_DIR, SAMPLES_C_DIR
8+
from conftest import logger, MODELS, SAMPLES_PY_DIR, SAMPLES_CPP_DIR, SAMPLES_C_DIR, SAMPLES_JS_DIR
99
from test_utils import run_sample
1010

1111
class TestGreedyCausalLM:
@@ -41,9 +41,15 @@ def test_sample_greedy_causal_lm(self, request, convert_model, sample_args):
4141
c_command =[c_sample, convert_model, sample_args]
4242
c_result = run_sample(c_command)
4343

44+
# Test JS sample
45+
js_sample = os.path.join(SAMPLES_JS_DIR, "text_generation/greedy_causal_lm.js")
46+
js_command =['node', js_sample, convert_model, sample_args]
47+
js_result = run_sample(js_command)
48+
4449
# Compare results
4550
assert py_result.stdout == cpp_result.stdout, f"Results should match"
4651
assert cpp_result.stdout == c_result.stdout, f"Results should match"
52+
assert c_result.stdout == js_result.stdout, f"Results should match"
4753

4854
model_name = request.node.callspec.params['convert_model']
4955
model = MODELS[model_name]
@@ -61,4 +67,4 @@ def test_sample_greedy_causal_lm(self, request, convert_model, sample_args):
6167

6268
idx = cpp_predictions.find(ref)
6369
assert -1 != idx, f'Missing "{ref=}" from predictions'
64-
cpp_predictions = cpp_predictions[:idx] + cpp_predictions[idx + len(ref):]
70+
cpp_predictions = cpp_predictions[:idx] + cpp_predictions[idx + len(ref):]

0 commit comments

Comments
 (0)