Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[runtime] To upgrade libtorch CPU runtime with IPEX version #1893

Merged
merged 18 commits into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion runtime/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Here is a brief summary of all platforms and OSs. please note the corresponding
| ios | ios | libtorch | ios demo, [link](TODO) |
| kunlun | linux | xpu runtime | Kunlun XPU runtime |
| libtorch | linux, windows, mac | libtorch | c++ build with libtorch |
| ipex | linux | libtorch + ipex | c++ build with libtorch with ipex optimization |
| ipex | linux | libtorch + ipex | c++ build with libtorch and ipex optimization |
| onnxrutnime | linux, windows, mac | onnxruntime | c++ build with onnxruntime |
| openvino | linux, windows, mac | openvino | c++ build with openvino |
| raspberrypi | linux | onnxruntime | c++ build on raspberrypi with onnxruntime |
Expand Down
3 changes: 3 additions & 0 deletions runtime/core/bin/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
add_executable(decoder_main decoder_main.cc)
target_link_libraries(decoder_main PUBLIC decoder)
if(IPEX)
target_link_libraries(decoder_main PUBLIC "-Wl,--no-as-needed ${IPEX_CPU_CORE_LIBRARY}")
endif()

add_executable(label_checker_main label_checker_main.cc)
target_link_libraries(label_checker_main PUBLIC decoder)
Expand Down
22 changes: 11 additions & 11 deletions runtime/core/cmake/ipex.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
endif()

if(CXX11_ABI)
set(LIBTORCH_URL "https://download.pytorch.org/libtorch/cpu/libtorch-cxx11-abi-shared-with-deps-1.13.0%2Bcpu.zip")
set(URL_HASH "SHA256=d52f63577a07adb0bfd6d77c90f7da21896e94f71eb7dcd55ed7835ccb3b2b59")
set(LIBTORCH_URL "https://download.pytorch.org/libtorch/cpu/libtorch-cxx11-abi-shared-with-deps-2.0.1%2Bcpu.zip")
set(URL_HASH "SHA256=137a842d1cf1e9196b419390133a1623ef92f8f84dc7a072f95ada684f394afd")
else()
set(LIBTORCH_URL "https://download.pytorch.org/libtorch/cpu/libtorch-shared-with-deps-1.13.0%2Bcpu.zip")
set(URL_HASH "SHA256=bee1b7be308792aa60fc95a4f5274d9658cb7248002d0e333d49eb81ec88430c")
set(LIBTORCH_URL "https://download.pytorch.org/libtorch/cpu/libtorch-shared-with-deps-2.0.1%2Bcpu.zip")
set(URL_HASH "SHA256=90d50350fd24ce5cf9dfbf47888d0cfd9f943eb677f481b86fe1b8e90f7fda5d")
endif()
FetchContent_Declare(libtorch
URL ${LIBTORCH_URL}
Expand All @@ -19,13 +19,13 @@ FetchContent_MakeAvailable(libtorch)
find_package(Torch REQUIRED PATHS ${libtorch_SOURCE_DIR} NO_DEFAULT_PATH)

if(CXX11_ABI)
set(LIBIPEX_URL "https://intel-optimized-pytorch.s3.cn-north-1.amazonaws.com.cn/libipex/cpu/libintel-ext-pt-cxx11-abi-1.13.100%2Bcpu.run")
set(URL_HASH "SHA256=e26778d68a5b76e5d4e540812433ade4f3e917bafc7a252a1fc1c0d1e0ed9c73")
set(LIBIPEX_SCRIPT_NAME "libintel-ext-pt-cxx11-abi-1.13.100%2Bcpu.run")
set(LIBIPEX_URL "https://intel-optimized-pytorch.s3.cn-north-1.amazonaws.com.cn/libipex/cpu/libintel-ext-pt-cxx11-abi-2.0.100%2Bcpu.run")
set(URL_HASH "SHA256=f172d9ebc2ca0c39cc93bb395721194f79767e1bc3f82b13e1edc07d1530a600")
set(LIBIPEX_SCRIPT_NAME "libintel-ext-pt-cxx11-abi-2.0.100%2Bcpu.run")
else()
set(LIBIPEX_URL "https://intel-optimized-pytorch.s3.cn-north-1.amazonaws.com.cn/libipex/cpu/libintel-ext-pt-1.13.100%2Bcpu.run")
set(URL_HASH "SHA256=0e0e09384106a1f00f4dbd9b543ff42643b769f654c693ff9ecdaba04c607987")
set(LIBIPEX_SCRIPT_NAME "libintel-ext-pt-1.13.100%2Bcpu.run")
set(LIBIPEX_URL "https://intel-optimized-pytorch.s3.cn-north-1.amazonaws.com.cn/libipex/cpu/libintel-ext-pt-2.0.100%2Bcpu.run")
set(URL_HASH "SHA256=8392f965dd9b8f6c0712acbb805c7e560e4965a0ade279b47a5f5a8363888268")
set(LIBIPEX_SCRIPT_NAME "libintel-ext-pt-2.0.100%2Bcpu.run")
endif()
FetchContent_Declare(intel_ext_pt
URL ${LIBIPEX_URL}
Expand All @@ -35,6 +35,6 @@ DOWNLOAD_NO_EXTRACT TRUE
PATCH_COMMAND bash ${FETCHCONTENT_BASE_DIR}/${LIBIPEX_SCRIPT_NAME} install ${libtorch_SOURCE_DIR}
)
FetchContent_MakeAvailable(intel_ext_pt)
find_package(intel_ext_pt_cpu REQUIRED PATHS ${libtorch_SOURCE_DIR} NO_DEFAULT_PATH)
find_package(IPEX REQUIRED PATHS ${libtorch_SOURCE_DIR} NO_DEFAULT_PATH)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS} -DC10_USE_GLOG")
3 changes: 2 additions & 1 deletion runtime/ipex/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ option(GRPC "whether to build with gRPC" OFF)
option(WEBSOCKET "whether to build with websocket" OFF)
option(HTTP "whether to build with http" OFF)
option(TORCH "whether to build with Torch" ON)
option(IPEX "whether to build with Torch+IPEX" ON)

set(CMAKE_VERBOSE_MAKEFILE OFF)

Expand Down Expand Up @@ -63,4 +64,4 @@ add_subdirectory(bin)
if(BUILD_TESTING)
include(gtest)
add_subdirectory(test)
endif()
endif()
11 changes: 7 additions & 4 deletions runtime/ipex/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pip install -r requirements.txt
```
Installation of IPEX
``` sh
pip install intel_extension_for_pytorch==1.13.100 -f https://developer.intel.com/ipex-whl-stable-cpu
pip install intel_extension_for_pytorch==2.0.100 -f https://developer.intel.com/ipex-whl-stable-cpu
```

Installation of related tools: Intel® OpenMP and TCMalloc
Expand All @@ -36,14 +36,16 @@ based on the package manager of your system.
For exporting FP32 runtime model
``` sh
source examples/aishell/s0/path.sh
export OMP_NUM_THREADS=1
python wenet/bin/export_ipex.py \
--config <model_config_yaml_filename> \
--checkpoint <model_ckpt_filename> \
--output_file <runtime_model_output_filename>
```
If you have an Intel® 4th Generation Xeon (Sapphire Rapids) server, you can export a BF16 runtime model and get better performance by virtue of AMX instructions
If you have an Intel® 4th Generation Xeon (Sapphire Rapids) server, you can export a BF16 runtime model and get better performance by virtue of [AMX instructions](https://en.wikipedia.org/wiki/Advanced_Matrix_Extensions)
``` sh
source examples/aishell/s0/path.sh
export OMP_NUM_THREADS=1
python wenet/bin/export_ipex.py \
--config <model_config_yaml_filename> \
--checkpoint <model_ckpt_filename> \
Expand All @@ -53,6 +55,7 @@ python wenet/bin/export_ipex.py \
And for exporting int8 quantized runtime model
``` sh
source examples/aishell/s0/path.sh
export OMP_NUM_THREADS=1
python wenet/bin/export_ipex.py \
--config <model_config_yaml_filename> \
--checkpoint <model_ckpt_filename> \
Expand All @@ -73,13 +76,13 @@ export GLOG_logtostderr=1
export GLOG_v=2
wav_path=your_test_wav_path
model_dir=your_model_dir
ipexrun --no_python \
ipexrun --no-python \
./build/bin/decoder_main \
--chunk_size -1 \
--wav_path $wav_path \
--model_path $model_dir/final.zip \
--unit_path $model_dir/units.txt 2>&1 | tee log.txt
```
NOTE: Please refer [IPEX Launch Script Usage Guide](https://intel.github.io/intel-extension-for-pytorch/cpu/1.13.100+cpu/tutorials/performance_tuning/launch_script.html) for usage of advanced features.
NOTE: Please refer [IPEX Launch Script Usage Guide](https://intel.github.io/intel-extension-for-pytorch/cpu/2.0.100+cpu/tutorials/performance_tuning/launch_script.html) for usage of advanced features.

For advanced usage of WeNet, such as building Web/RPC/HTTP services, please refer [LibTorch Tutorial](../libtorch#advanced-usage). The difference is that the executables should be invoked via IPEX launch script `ipexrun`.