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

[fix] remove useless runtime #303

Merged
merged 1 commit into from
Apr 3, 2024
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
104 changes: 0 additions & 104 deletions docs/runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ The Wespeaker runtime supports the following platforms.
- [TensorRT GPU](https://github.com/wenet-e2e/wespeaker/tree/master/runtime/server/x86_gpu)

- Device
- [Horizon X3 PI](https://github.com/wenet-e2e/wespeaker/tree/master/runtime/horizonbpu)
- [Onnxruntime](https://github.com/wenet-e2e/wespeaker/tree/master/runtime/onnxruntime)
- linux_x86_cpu
- linux_x86_gpu
Expand Down Expand Up @@ -85,109 +84,6 @@ onnx_dir=your_model_dir
--embedding_size 256
```

## Horizonbpu

* Step 1. Setup environment (install horizon packages and cross compile tools) in the PC.

```sh
# Conda env (This conda env is only used for converting bpu models, not for training torch models,
# It's OK to install cpu-version pytorch)
conda create -n horizonbpu python=3.8
conda activate horizonbpu
git clone https://github.com/wenet-e2e/wespeaker.git
cd wespeaker/runtime/horizonbpu
pip install -r ../../requirements.txt -i https://mirrors.aliyun.com/pypi/simple
pip install torch==1.13.0 torchaudio==0.13.0 torchvision==0.14.0 onnx onnxruntime -i https://mirrors.aliyun.com/pypi/simple

# Horizon packages
wget https://gitee.com/xcsong-thu/toolchain_pkg/releases/download/resource/wheels.tar.gz
tar -xzf wheels.tar.gz
pip install wheels/* -i https://mirrors.aliyun.com/pypi/simple

# Cross compile tools
sudo apt-get install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
```

* Step 2. Build extract_emb_main. It requires cmake 3.14 or above. and Send the binary/libraries to Horizon X3PI.

```bash
# Assume current dir is `wespeaker/runtime/horizonbpu`
cmake -B build -DBPU=ON -DONNX=OFF -DCMAKE_TOOLCHAIN_FILE=toolchains/aarch64-linux-gnu.toolchain.cmake
cmake --build build

# Send binary and libraries
export BPUIP=xxx.xxx.xxx.xxx
export DEMO_PATH_ON_BOARD=/path/to/demo
scp -r build/bin/ root@$BPUIP:$DEMO_PATH_ON_BOARD
scp fc_base/easy_dnn-src/dnn/*j3*/*/*/lib/libdnn.so root@$BPUIP:$DEMO_PATH_ON_BOARD
scp fc_base/easy_dnn-src/easy_dnn/*j3*/*/*/lib/libeasy_dnn.so root@$BPUIP:$DEMO_PATH_ON_BOARD
scp fc_base/easy_dnn-src/hlog/*j3*/*/*/lib/libhlog.so root@$BPUIP:$DEMO_PATH_ON_BOARD
```

* Step 3. Export model to ONNX and convert ONNX to Horizon .bin and Send the model/test_wav to Horizon X3PI.


```bash
# stage 1: export onnx
export WESPEAKER_DIR=$PWD/../../
export PYTHONPATH=$WESPEAKER_DIR:$PYTHONPATH
mkdir -p output
python $WESPEAKER_DIR/wespeaker/bin/export_onnx_bpu.py \
--config the_path_train_yaml \
--checkpoint the_path_pt_model \
--output_model the_path_onnx_model \
--num_frames num_frames
# egs:
# python $WESPEAKER_DIR/wespeaker/bin/export_onnx_bpu.py \
# --config resnet_34/train.yaml \
# --checkpoint resnet_34/avg_model.pt \
# --output_model resnet_34/resnet34.onnx \
# --num_frames 198

# stage 2: export bin model
python $WESPEAKER_DIR/tools/onnx2horizonbin.py \
--config the_path_train_yaml \
--output_dir output_dir \
--cali_datalist data_list \
--onnx_path fp_onnx_path \
--cali_data_type "shard/raw" \
--input_name input_name \
--input_shape input_shape

# egs:
# python $WESPEAKER_DIR/tools/onnx2horizonbin.py \
# --config resnet_34/config.yaml \
# --output_dir output/ \
# --cali_datalist cali_data/raw.list \
# --onnx_path resnet_34/resnet34.onnx \
# --cali_data_type "raw" \
# --input_name "feats" \
# --input_shape "1x1x198x80"

# scp test wav file
scp test_wav.wav root@$BPUIP:$DEMO_PATH_ON_BOARD
# scp bpu models
scp ./output/hb_makertbin_output_speaker/speaker.bin root@$BPUIP:$DEMO_PATH_ON_BOARD
```

* Step 4. Testing on X3PI, the RTF(real time factor) is shown in Horizon X3PI's console.

```bash
cd /path/to/demo
export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH \
export GLOG_logtostderr=1
export GLOG_v=2
wav_scp=your_test_wav_scp
embed_out=your_embedding_txt
./build/bin/extract_emb_main \
--wav_scp $wav_scp \
--result $embed_out \
--speaker_model_path speaker.bin \
--embedding_size 256 \
--SamplesPerChunk 32000 # 2s
```


## Server (tensorrt gpu)

### Introduction
Expand Down
1 change: 1 addition & 0 deletions runtime/core/bin/extract_emb_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

#include <fstream>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
Expand Down
4 changes: 0 additions & 4 deletions runtime/core/speaker/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,12 @@ if(NOT ONNX AND NOT BPU)
endif()
if(ONNX)
list(APPEND speaker_srcs onnx_speaker_model.cc)
else()
list(APPEND speaker_srcs bpu_speaker_model.cc)
endif()

add_library(speaker STATIC ${speaker_srcs})
target_link_libraries(speaker PUBLIC frontend)

if(ONNX)
target_link_libraries(speaker PUBLIC onnxruntime)
else()
target_link_libraries(speaker PUBLIC easy_dnn dnn)
endif()

153 changes: 0 additions & 153 deletions runtime/core/speaker/bpu_speaker_model.cc

This file was deleted.

57 changes: 0 additions & 57 deletions runtime/core/speaker/bpu_speaker_model.h

This file was deleted.

2 changes: 0 additions & 2 deletions runtime/core/speaker/speaker_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

#ifdef USE_ONNX
#include "speaker/onnx_speaker_model.h"
#elif USE_BPU
#include "speaker/bpu_speaker_model.h"
#endif

namespace wespeaker {
Expand Down
4 changes: 0 additions & 4 deletions runtime/horizonbpu/.gitignore

This file was deleted.

Loading
Loading