Skip to content

Commit 35c8193

Browse files
committed
Add greedy_causal_lm js running into sample tests
Signed-off-by: Kirill Suvorov <kirill.suvorov@intel.com>
1 parent f274cb3 commit 35c8193

File tree

4 files changed

+56
-2
lines changed

4 files changed

+56
-2
lines changed

.github/workflows/linux.yml

+20
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,13 @@ 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+
with:
472+
name: genai_nodejs_bindings
473+
path: ${{ env.SRC_DIR }}/src/js/bin
474+
merge-multiple: true
468475

469476
- name: Extract Artifacts
470477
run: |
@@ -484,11 +491,24 @@ jobs:
484491
requirements_files: "${{ env.SRC_DIR }}/samples/requirements.txt"
485492
local_wheel_dir: ${{ env.INSTALL_DIR }}/wheels
486493

494+
- name: Setup Node
495+
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
496+
with:
497+
node-version: 21
498+
499+
- name: Install npm package tests dependencies
500+
working-directory: ${{ env.SRC_DIR }}/samples/js/text_generation
501+
run: |
502+
npm install --verbose
503+
rm -rf node_modules/openvino-node/bin
504+
cp -R ${{ env.INSTALL_DIR }}/openvino_js_package node_modules/openvino-node/bin
505+
487506
- name: Test Samples (Python and C++)
488507
run: python -m pytest -vs ${{ env.SRC_DIR }}/${{ matrix.test.cmd }} -m "${{ matrix.test.marker }}"
489508
env:
490509
LD_LIBRARY_PATH: "${{ env.INSTALL_DIR }}/runtime/lib/intel64:${{ env.INSTALL_DIR }}/runtime/3rdparty/tbb/lib:$LD_LIBRARY_PATH" # Required for C++ samples
491510
SAMPLES_PY_DIR: "${{ env.INSTALL_DIR }}/samples/python"
511+
SAMPLES_JS_DIR: "${{ env.INSTALL_DIR }}/samples/js"
492512
SAMPLES_CPP_DIR: "${{ env.INSTALL_DIR }}/samples_bin"
493513
SAMPLES_C_DIR: "${{ env.INSTALL_DIR }}/samples_bin"
494514

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)