Skip to content

Commit bbc7936

Browse files
authored
Replace openvino_contrib with openvino_tokenizers (openvinotoolkit#231)
Close openvinotoolkit#228
1 parent dac0b9d commit bbc7936

File tree

14 files changed

+36
-74
lines changed

14 files changed

+36
-74
lines changed

.github/workflows/causal_lm_cpp.yml

+5-37
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
- .github/workflows/causal_lm_cpp.yml
66
- llm_bench/python/**
77
- text_generation/causal_lm/cpp/*
8-
- thirdparty/openvino_contrib
8+
- thirdparty/openvino_tokenizers
99
- '!**.md'
1010
concurrency:
1111
group: ${{ github.workflow }}-${{ github.ref }}
@@ -28,7 +28,7 @@ jobs:
2828
- name: Download, convert and build
2929
run: |
3030
source ./ov/setupvars.sh
31-
python -m pip install --upgrade-strategy eager "optimum>=1.14" -r ./llm_bench/python/requirements.txt ./thirdparty/openvino_contrib/modules/custom_operations/[transformers] --extra-index-url https://download.pytorch.org/whl/cpu && python ./llm_bench/python/convert.py --model_id openlm-research/open_llama_3b_v2 --output_dir ./open_llama_3b_v2/ --precision FP16 --stateful &
31+
python -m pip install --upgrade-strategy eager "optimum>=1.14" -r ./llm_bench/python/requirements.txt ./thirdparty/openvino_tokenizers/[transformers] --extra-index-url https://download.pytorch.org/whl/cpu && python ./llm_bench/python/convert.py --model_id openlm-research/open_llama_3b_v2 --output_dir ./open_llama_3b_v2/ --precision FP16 --stateful &
3232
cmake -DCMAKE_BUILD_TYPE=Release -S ./text_generation/causal_lm/cpp/ -B ./build/
3333
cmake --build ./build/ --config Release -j
3434
wait
@@ -54,7 +54,7 @@ jobs:
5454
- name: Download, convert and build
5555
run: |
5656
source ./ov/setupvars.sh
57-
python -m pip install --upgrade-strategy eager transformers==4.35.2 "optimum>=1.14" -r ./llm_bench/python/requirements.txt ./thirdparty/openvino_contrib/modules/custom_operations/[transformers] --extra-index-url https://download.pytorch.org/whl/cpu && python ./llm_bench/python/convert.py --model_id TinyLlama/TinyLlama-1.1B-Chat-v1.0 --output_dir ./TinyLlama-1.1B-Chat-v1.0/ --precision FP16 --stateful &
57+
python -m pip install --upgrade-strategy eager "optimum>=1.14" -r ./llm_bench/python/requirements.txt ./thirdparty/openvino_tokenizers/[transformers] --extra-index-url https://download.pytorch.org/whl/cpu && python ./llm_bench/python/convert.py --model_id TinyLlama/TinyLlama-1.1B-Chat-v1.0 --output_dir ./TinyLlama-1.1B-Chat-v1.0/ --precision FP16 --stateful &
5858
cmake -DCMAKE_BUILD_TYPE=Release -S ./text_generation/causal_lm/cpp/ -B ./build/
5959
cmake --build ./build/ --config Release -j
6060
wait
@@ -94,38 +94,6 @@ jobs:
9494
predictions = predictions[:idx] + predictions[idx + len(ref):]
9595
"
9696
echo Hi passed
97-
98-
timeout 25s ./build/beam_search_causal_lm ./TinyLlama-1.1B-Chat-v1.0/pytorch/dldt/FP16/ "return 0" > ./pred.txt
99-
python -c "
100-
import transformers
101-
with open('pred.txt', 'r') as file:
102-
predictions = file.read()
103-
tokenizer = transformers.LlamaTokenizer.from_pretrained('TinyLlama/TinyLlama-1.1B-Chat-v1.0')
104-
tokenized = tokenizer('return 0', return_tensors='pt')
105-
for beam in transformers.LlamaForCausalLM.from_pretrained('TinyLlama/TinyLlama-1.1B-Chat-v1.0').generate(**tokenized, num_beam_groups=3, num_beams=15, num_return_sequences=15, diversity_penalty=1.0, max_new_tokens=20, early_stopping=False, length_penalty=1.0, no_repeat_ngram_size=9**9, do_sample=False):
106-
ref = ': ' + tokenizer.decode(beam[tokenized['input_ids'].numel():], skip_special_tokens=True) + '\n'
107-
idx = predictions.find(ref)
108-
if -1 == idx:
109-
raise RuntimeError(f'Missing "{ref=}" from predictions')
110-
predictions = predictions[:idx] + predictions[idx + len(ref):]
111-
"
112-
echo return 0 passed
113-
114-
./build/beam_search_causal_lm ./TinyLlama-1.1B-Chat-v1.0/pytorch/dldt/FP16/ "你好! 你好嗎?" > ./pred.txt
115-
python -c "
116-
import transformers
117-
with open('pred.txt', 'r') as file:
118-
predictions = file.read()
119-
tokenizer = transformers.LlamaTokenizer.from_pretrained('TinyLlama/TinyLlama-1.1B-Chat-v1.0')
120-
tokenized = tokenizer('你好! 你好嗎?', return_tensors='pt')
121-
for beam in transformers.LlamaForCausalLM.from_pretrained('TinyLlama/TinyLlama-1.1B-Chat-v1.0').generate(**tokenized, num_beam_groups=3, num_beams=15, num_return_sequences=15, diversity_penalty=1.0, max_new_tokens=20, early_stopping=False, length_penalty=1.0, no_repeat_ngram_size=9**9, do_sample=False):
122-
ref = ': ' + tokenizer.decode(beam[tokenized['input_ids'].numel():], skip_special_tokens=True) + '\n'
123-
idx = predictions.find(ref)
124-
if -1 == idx:
125-
raise RuntimeError(f'Missing "{ref=}" from predictions')
126-
predictions = predictions[:idx] + predictions[idx + len(ref):]
127-
"
128-
echo 你好! 你好嗎? passed
12997
cpp-beam_search_causal_lm-windows:
13098
runs-on: windows-latest
13199
steps:
@@ -144,7 +112,7 @@ jobs:
144112
shell: cmd
145113
run: |
146114
call w_openvino_toolkit_windows_2023.3.0.13775.ceeafaf64f3_x86_64\setupvars.bat
147-
python -m pip install --upgrade-strategy eager transformers==4.35.2 "optimum>=1.14" -r ./llm_bench/python/requirements.txt ./thirdparty/openvino_contrib/modules/custom_operations/[transformers] --extra-index-url https://download.pytorch.org/whl/cpu
115+
python -m pip install --upgrade-strategy eager "optimum>=1.14" -r ./llm_bench/python/requirements.txt ./thirdparty/openvino_tokenizers/[transformers] --extra-index-url https://download.pytorch.org/whl/cpu
148116
python ./llm_bench/python/convert.py --model_id TinyLlama/TinyLlama-1.1B-Chat-v1.0 --output_dir ./TinyLlama-1.1B-Chat-v1.0/ --precision FP16 --stateful
149117
cmake -DCMAKE_BUILD_TYPE=Release -S ./text_generation/causal_lm/cpp/ -B ./build/
150118
cmake --build ./build/ --config Release -j
@@ -183,7 +151,7 @@ jobs:
183151
- name: Download, convert and build
184152
run: |
185153
source ./ov/setupvars.sh
186-
python -m pip install --upgrade-strategy eager transformers==4.35.2 "optimum>=1.14" -r ./llm_bench/python/requirements.txt ./thirdparty/openvino_contrib/modules/custom_operations/[transformers] --extra-index-url https://download.pytorch.org/whl/cpu && python ./llm_bench/python/convert.py --model_id Qwen/Qwen-7B-Chat --output_dir ./Qwen-7B-Chat/ --precision FP16 --stateful &
154+
python -m pip install --upgrade-strategy eager "optimum>=1.14" -r ./llm_bench/python/requirements.txt ./thirdparty/openvino_tokenizers/[transformers] --extra-index-url https://download.pytorch.org/whl/cpu && python ./llm_bench/python/convert.py --model_id Qwen/Qwen-7B-Chat --output_dir ./Qwen-7B-Chat/ --precision FP16 --stateful &
187155
cmake -DCMAKE_BUILD_TYPE=Release -S ./text_generation/causal_lm/cpp/ -B ./build/
188156
cmake --build ./build/ --config Release -j
189157
wait

.github/workflows/lcm_dreamshaper_cpp.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
- image_generation/lcm_dreamshaper_v7/cpp/**
66
- image_generation/common/**
77
- .github/workflows/lcm_dreamshaper_cpp.yml
8-
- thirdparty/openvino_contrib
8+
- thirdparty/openvino_tokenizers
99
concurrency:
1010
group: ${{ github.workflow }}-${{ github.ref }}
1111
cancel-in-progress: true
@@ -30,7 +30,7 @@ jobs:
3030
cd ./image_generation/lcm_dreamshaper_v7/cpp/scripts/
3131
python -m pip install -U pip
3232
python -m pip install -r ./requirements.txt
33-
python -m pip install ../../../../thirdparty/openvino_contrib/modules/custom_operations/
33+
python -m pip install ../../../../thirdparty/openvino_tokenizers/
3434
python convert_model.py -lcm "SimianLuo/LCM_Dreamshaper_v7" -t "FP16"
3535
- name: Build app
3636
run: |
@@ -63,7 +63,7 @@ jobs:
6363
call w_openvino_toolkit_windows_2023.3.0.13775.ceeafaf64f3_x86_64/setupvars.bat
6464
cd ./image_generation/lcm_dreamshaper_v7/cpp/scripts/
6565
python -m pip install -r ./requirements.txt
66-
python -m pip install ../../../../thirdparty/openvino_contrib/modules/custom_operations/
66+
python -m pip install ../../../../thirdparty/openvino_tokenizers/
6767
python convert_model.py -lcm "SimianLuo/LCM_Dreamshaper_v7" -t "FP16"
6868
- name: Build app
6969
shell: cmd

.github/workflows/stable_diffusion_1_5_cpp.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
- image_generation/stable_diffusion_1_5/cpp/**
66
- image_generation/common/**
77
- .github/workflows/stable_diffusion_1_5_cpp.yml
8-
- thirdparty/openvino_contrib
8+
- thirdparty/openvino_tokenizers
99
concurrency:
1010
group: ${{ github.workflow }}-${{ github.ref }}
1111
cancel-in-progress: true
@@ -32,7 +32,7 @@ jobs:
3232
cd ./image_generation/stable_diffusion_1_5/cpp/scripts/
3333
python -m pip install -U pip
3434
python -m pip install -r ./requirements.txt
35-
python -m pip install ../../../../thirdparty/openvino_contrib/modules/custom_operations/
35+
python -m pip install ../../../../thirdparty/openvino_tokenizers/
3636
python convert_model.py -sd runwayml/stable-diffusion-v1-5 -b 1 -t FP16 -dyn True
3737
- name: Build app
3838
run: |
@@ -67,7 +67,7 @@ jobs:
6767
call w_openvino_toolkit_windows_2023.3.0.13775.ceeafaf64f3_x86_64/setupvars.bat
6868
cd ./image_generation/stable_diffusion_1_5/cpp/scripts/
6969
python -m pip install -r ./requirements.txt
70-
python -m pip install ../../../../thirdparty/openvino_contrib/modules/custom_operations/
70+
python -m pip install ../../../../thirdparty/openvino_tokenizers/
7171
python convert_model.py -sd runwayml/stable-diffusion-v1-5 -b 1 -t FP16 -dyn True
7272
- name: Build app
7373
shell: cmd

.gitmodules

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
[submodule "thirdparty/openvino_contrib"]
2-
path = thirdparty/openvino_contrib
3-
url = https://github.com/openvinotoolkit/openvino_contrib.git
1+
[submodule "thirdparty/openvino_tokenizers"]
2+
path = thirdparty/openvino_tokenizers
3+
url = https://github.com/openvinotoolkit/openvino_tokenizers.git

image_generation/lcm_dreamshaper_v7/cpp/CMakeLists.txt

+3-5
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ FetchContent_MakeAvailable(cxxopts)
2727

2828
add_subdirectory(../../common/imwrite _deps/imwrite)
2929
add_subdirectory(../../common/diffusers _deps/diffusers)
30-
31-
set(CUSTOM_OPERATIONS tokenizer)
32-
add_subdirectory(../../../thirdparty/openvino_contrib/modules/custom_operations/ _deps/tokenizers)
30+
add_subdirectory(../../../thirdparty/openvino_tokenizers/ _deps/tokenizers)
3331

3432
# create executable
3533

@@ -41,6 +39,6 @@ target_link_libraries(${PROJECT_NAME} PRIVATE
4139
diffusers::diffusers
4240
imwrite::imwrite)
4341

44-
add_dependencies(${PROJECT_NAME} user_ov_extensions)
42+
add_dependencies(${PROJECT_NAME} openvino_tokenizers)
4543

46-
target_compile_definitions(${PROJECT_NAME} PRIVATE TOKENIZERS_LIBRARY_PATH=\"$<TARGET_FILE:user_ov_extensions>\")
44+
target_compile_definitions(${PROJECT_NAME} PRIVATE TOKENIZERS_LIBRARY_PATH=\"$<TARGET_FILE:openvino_tokenizers>\")

image_generation/lcm_dreamshaper_v7/cpp/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# OpenVINO Latent Consistency Model C++ image generation pipeline
2-
The pure C++ text-to-image pipeline, driven by the OpenVINO native API for SD v1.5 Latent Consistency Model with LCM Scheduler. It includes advanced features like LoRA integration with safetensors and [OpenVINO extension for tokenizers](https://github.com/openvinotoolkit/openvino_contrib/blob/master/modules/custom_operations/user_ie_extensions/tokenizer/python/README.md). Loading `user_ov_extensions` provided by `openvino-tokenizers` to `ov::Core` enables tokenization. [The common folder](../../common/) contains schedulers for image generation and `imwrite()` for saving `bmp` images. This demo has been tested for Linux platform only. There is also a Jupyter [notebook](https://github.com/openvinotoolkit/openvino_notebooks/blob/main/notebooks/263-latent-consistency-models-image-generation/263-lcm-lora-controlnet.ipynb) which provides an example of image generaztion in Python.
2+
The pure C++ text-to-image pipeline, driven by the OpenVINO native API for SD v1.5 Latent Consistency Model with LCM Scheduler. It includes advanced features like LoRA integration with safetensors and [OpenVINO Tokenizers](https://github.com/openvinotoolkit/openvino_tokenizers). Loading `openvino_tokenizers` to `ov::Core` enables tokenization. [The common folder](../../common/) contains schedulers for image generation and `imwrite()` for saving `bmp` images. This demo has been tested for Linux platform only. There is also a Jupyter [notebook](https://github.com/openvinotoolkit/openvino_notebooks/blob/main/notebooks/263-latent-consistency-models-image-generation/263-lcm-lora-controlnet.ipynb) which provides an example of image generaztion in Python.
33

44
> [!NOTE]
55
>This tutorial assumes that the current working directory is `<openvino.genai repo>/image_generation/lcm_dreamshaper_v7/cpp/` and all paths are relative to this folder.
@@ -26,7 +26,7 @@ conda install -c conda-forge openvino c-compiler cxx-compiler make
2626
```shell
2727
conda activate openvino_lcm_cpp
2828
python -m pip install -r scripts/requirements.txt
29-
python -m pip install ../../../thirdparty/openvino_contrib/modules/custom_operations/[transformers]
29+
python -m pip install ../../../thirdparty/openvino_tokenizers/[transformers]
3030
```
3131

3232
2. Run model conversion script to download and convert PyTorch model to OpenVINO IR via [optimum-intel](https://github.com/huggingface/optimum-intel). Please, use the script `scripts/convert_model.py` to convert the model:
@@ -80,7 +80,7 @@ Usage:
8080
* `-h, --help` Print usage
8181
8282
> [!NOTE]
83-
> The tokenizer model will always be loaded to CPU: [OpenVINO tokenizers](https://github.com/openvinotoolkit/openvino_contrib/tree/master/modules/custom_operations/user_ie_extensions/tokenizer/python#readme) can be inferred on a CPU device only.
83+
> The tokenizer model will always be loaded to CPU: [OpenVINO Tokenizers](https://github.com/openvinotoolkit/openvino_tokenizers) can be inferred on a CPU device only.
8484
8585
Example:
8686

image_generation/stable_diffusion_1_5/cpp/CMakeLists.txt

+3-5
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ FetchContent_MakeAvailable(cxxopts)
2727

2828
add_subdirectory(../../common/imwrite _deps/imwrite)
2929
add_subdirectory(../../common/diffusers _deps/diffusers)
30-
31-
set(CUSTOM_OPERATIONS tokenizer)
32-
add_subdirectory(../../../thirdparty/openvino_contrib/modules/custom_operations/ _deps/tokenizers)
30+
add_subdirectory(../../../thirdparty/openvino_tokenizers/ _deps/tokenizers)
3331

3432
# create executable
3533

@@ -45,6 +43,6 @@ target_link_libraries(${PROJECT_NAME} PRIVATE
4543
diffusers::diffusers
4644
imwrite::imwrite)
4745

48-
add_dependencies(${PROJECT_NAME} user_ov_extensions)
46+
add_dependencies(${PROJECT_NAME} openvino_tokenizers)
4947

50-
target_compile_definitions(${PROJECT_NAME} PRIVATE TOKENIZERS_LIBRARY_PATH=\"$<TARGET_FILE:user_ov_extensions>\")
48+
target_compile_definitions(${PROJECT_NAME} PRIVATE TOKENIZERS_LIBRARY_PATH=\"$<TARGET_FILE:openvino_tokenizers>\")

image_generation/stable_diffusion_1_5/cpp/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# OpenVINO Stable Diffusion (with LoRA) C++ image generation pipeline
2-
The pure C++ text-to-image pipeline, driven by the OpenVINO native C++ API for Stable Diffusion v1.5 with LMS Discrete Scheduler, supports both static and dynamic model inference. It includes advanced features like [LoRA](https://huggingface.co/docs/peft/conceptual_guides/lora) integration with [safetensors](https://huggingface.co/docs/safetensors/index#format) and [OpenVINO extension for tokenizers](https://github.com/openvinotoolkit/openvino_contrib/blob/master/modules/custom_operations/user_ie_extensions/tokenizer/python/README.md). Loading `user_ov_extensions` provided by `openvino-tokenizers` to `ov::Core` enables tokenization. The sample uses [diffusers](../../common/diffusers) for image generation and [imwrite](../../common/imwrite) for saving `.bmp` images. This demo has been tested on Windows and Unix platforms. There is also a Jupyter [notebook](https://github.com/openvinotoolkit/openvino_notebooks/blob/main/notebooks/225-stable-diffusion-text-to-image/225-stable-diffusion-text-to-image.ipynb) which provides an example of image generation in Python.
2+
The pure C++ text-to-image pipeline, driven by the OpenVINO native C++ API for Stable Diffusion v1.5 with LMS Discrete Scheduler, supports both static and dynamic model inference. It includes advanced features like [LoRA](https://huggingface.co/docs/peft/conceptual_guides/lora) integration with [safetensors](https://huggingface.co/docs/safetensors/index#format) and [OpenVINO Tokenizers](https://github.com/openvinotoolkit/openvino_tokenizers). Loading `openvino_tokenizers` to `ov::Core` enables tokenization. The sample uses [diffusers](../../common/diffusers) for image generation and [imwrite](../../common/imwrite) for saving `.bmp` images. This demo has been tested on Windows and Unix platforms. There is also a Jupyter [notebook](https://github.com/openvinotoolkit/openvino_notebooks/blob/main/notebooks/225-stable-diffusion-text-to-image/225-stable-diffusion-text-to-image.ipynb) which provides an example of image generation in Python.
33

44
> [!NOTE]
55
>This tutorial assumes that the current working directory is `<openvino.genai repo>/image_generation/stable_diffusion_1_5/cpp/` and all paths are relative to this folder.
@@ -25,7 +25,7 @@ conda install openvino c-compiler cxx-compiler make
2525
```shell
2626
conda activate openvino_sd_cpp
2727
python -m pip install -r scripts/requirements.txt
28-
python -m pip install ../../../thirdparty/openvino_contrib/modules/custom_operations/[transformers]
28+
python -m pip install ../../../thirdparty/openvino_tokenizers/[transformers]
2929
```
3030
2. Download a huggingface SD v1.5 model like:
3131
- [runwayml/stable-diffusion-v1-5](https://huggingface.co/runwayml/stable-diffusion-v1-5)
@@ -92,7 +92,7 @@ Usage:
9292
* `-h, --help` Print usage
9393

9494
> [!NOTE]
95-
> The tokenizer model will always be loaded to CPU: [OpenVINO tokenizers](https://github.com/openvinotoolkit/openvino_contrib/tree/master/modules/custom_operations/user_ie_extensions/tokenizer/python#readme) can be inferred on a CPU device only.
95+
> The tokenizer model will always be loaded to CPU: [OpenVINO Tokenizers](https://github.com/openvinotoolkit/openvino_tokenizers) can be inferred on a CPU device only.
9696
9797
#### Examples
9898

text_generation/causal_lm/cpp/CMakeLists.txt

+3-5
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,17 @@
44
cmake_minimum_required(VERSION 3.15)
55
project(causal_lm)
66

7-
# Build user_ov_extensions
8-
list(APPEND CUSTOM_OPERATIONS tokenizer)
9-
add_subdirectory(../../../thirdparty/openvino_contrib/modules/custom_operations/ "${CMAKE_CURRENT_BINARY_DIR}/custom_operations/")
7+
add_subdirectory(../../../thirdparty/openvino_tokenizers/ "${CMAKE_CURRENT_BINARY_DIR}/openvino_tokenizers/")
108

119
add_executable(greedy_causal_lm greedy_causal_lm.cpp)
12-
target_compile_definitions(greedy_causal_lm PRIVATE USER_OV_EXTENSIONS_PATH=\"$<TARGET_FILE:user_ov_extensions>\")
10+
target_compile_definitions(greedy_causal_lm PRIVATE OPENVINO_TOKENIZERS_PATH=\"$<TARGET_FILE:openvino_tokenizers>\")
1311
find_package(OpenVINO REQUIRED COMPONENTS Runtime)
1412
target_link_libraries(greedy_causal_lm PRIVATE openvino::runtime)
1513
set_target_properties(greedy_causal_lm PROPERTIES CXX_STANDARD 17)
1614
set_target_properties(greedy_causal_lm PROPERTIES CXX_STANDARD_REQUIRED ON)
1715

1816
add_executable(beam_search_causal_lm beam_search_causal_lm.cpp)
19-
target_compile_definitions(beam_search_causal_lm PRIVATE USER_OV_EXTENSIONS_PATH=\"$<TARGET_FILE:user_ov_extensions>\")
17+
target_compile_definitions(beam_search_causal_lm PRIVATE OPENVINO_TOKENIZERS_PATH=\"$<TARGET_FILE:openvino_tokenizers>\")
2018
target_include_directories(beam_search_causal_lm PRIVATE ./)
2119
find_package(OpenVINO REQUIRED COMPONENTS Runtime)
2220
target_link_libraries(beam_search_causal_lm PRIVATE openvino::runtime)

0 commit comments

Comments
 (0)