Zipformer
This document describes how to run the Zipformer ASR example on the NPU.
Refer to Model Zoo Download for the example.
Zipformer uses encoder, decoder, and joiner sub-models for automatic speech recognition.
Zipformer example directory structure:
$ tree ./
./
├── CMakeLists.txt
├── convert_model_decoder
├── convert_model_encoder
├── convert_model_joiner
├── model
│ ├── decoder_int16_a733.nb
│ ├── encoder_int16_a733.nb
│ ├── joiner_int16_a733.nb
│ ├── test.wav
│ └── tokens.txt
└── README.md
Model Conversion
Enter the container development environment first. See Create and Start Container in the Model Zoo download page.
Select the Docker image that matches the NPU:
- A733: ubuntu-npu:v2.0.10.2
- T527: ubuntu-npu:v1.8.13
Download the floating-point ONNX models from the Allwinner netdisk:
- encoder: http://netstorage.allwinnertech.com:5000/sharing/8WWXoUfoy
- decoder: http://netstorage.allwinnertech.com:5000/sharing/1km0Q1YgK
- joiner: http://netstorage.allwinnertech.com:5000/sharing/GUTAIo774
docker exec -it model-zoo /bin/bash
Set this environment variable before converting the encoder:
export VIV_VX_ENABLE_GRAPH_TRANSFORM="-Dump[transform.rewrite.gather_to_stride_slice=0]"
Convert encoder
cd /workspace/examples/zipformer/convert_model_encoder/
./convert_model_env.sh
./pegasus_import.sh encoder
./pegasus_quantize.sh encoder int16 10
- A733
- T527
./pegasus_export_ovx_nbg.sh encoder int16 a733
./pegasus_export_ovx_nbg.sh encoder int16 t527
Convert decoder
cd /workspace/examples/zipformer/convert_model_decoder/
./convert_model_env.sh
./pegasus_import.sh decoder
./pegasus_quantize.sh decoder int16 10
- A733
- T527
./pegasus_export_ovx_nbg.sh decoder int16 a733
./pegasus_export_ovx_nbg.sh decoder int16 t527
Convert joiner
cd /workspace/examples/zipformer/convert_model_joiner/
./convert_model_env.sh
./pegasus_import.sh joiner
./pegasus_quantize.sh joiner int16 10
- A733
- T527
./pegasus_export_ovx_nbg.sh joiner int16 a733
./pegasus_export_ovx_nbg.sh joiner int16 t527
The exported models are stored in the ../model directory.
Build the Example
Then compile the example. Exit the container first, then run the commands below.
Configure the cross-compilation toolchain first.
Skip this step if you have already configured it in another example.
cd ../../../0-toolchains/
Download the toolchain from this link, put it in 0-toolchains/, then run:
tar -xvf gcc-arm-10.2-2020.11-x86_64-aarch64-none-linux-gnu.tar.xz
cd ../examples/zipformer/
- A733
- T527
../build_linux.sh -t a733 -s debian11
../build_linux.sh -t t527 -s debian11
Model Deployment
After compilation, the example will be installed in the install directory. You can use scp to transfer it to the board.
Configure NPU Driver
You can skip this step if you have already configured NPU driver in other examples.
Transfer the driver library to the board's lib directory via scp.
- A733 corresponds to the common/npuruntime/lib_linux_aarch64/A733 directory
- T527 corresponds to the common/npuruntime/lib_linux_aarch64/T527 directory
Then execute the following command to export to environment variables.
echo 'export LD_LIBRARY_PATH=$HOME/lib:$LD_LIBRARY_PATH' >> ~/.bashrc
Run Example
After configuring the driver, you can run the example.
For T527 platform, you need to first enable NPU by referring to the A5E's "Enable NPU on Board" documentation, then use the following command to grant the current user permission to use /dev/vipcore.
sudo chmod 777 /dev/vipcore
- A733
- T527
cd zipformer_demo_linux_a733/
chmod +x ./zipformer_demo_a733
./zipformer_demo_a733 -nb0 model/encoder_int16_a733.nb -nb1 model/decoder_int16_a733.nb -nb2 model/joiner_int16_a733.nb -i model/test.wav
The running result is as follows:
$ ./zipformer_demo_a733 -nb0 model/encoder_int16_a733.nb -nb1 model/decoder_int16_a733.nb -nb2 model/joiner_int16_a733.nb -i model/test.wav
encoder_path=model/encoder_int16_a733.nb, decoder_path=model/decoder_int16_a733.nb, joiner_path=model/joiner_int16_a733.nb, audio_path=model/test.wav
VIPLite driver software version 2.0.3.2-AW-2024-08-30
nbg name=model/encoder_int16_a733.nb, size: 37228136.
create network 0: 25435 us.
prepare network: 3858 us.
nbg name=model/decoder_int16_a733.nb, size: 6973440.
create network 1: 3971 us.
prepare network: 244 us.
nbg name=model/joiner_int16_a733.nb, size: 5509168.
create network 2: 2820 us.
prepare network: 56 us.
Real Time Factor(RTF): 0.053 = 0.309s(infer_time) / 5.840s(audio_length)
Timestamp (s): 0.96, 1.04, 1.24, 1.32, 1.44, 1.72, 1.80, 2.04, 2.56, 3.04, 3.08, 3.48, 3.84, 4.68, 4.76, 5.00, 5.24, 5.48
Zipformer output: 这是第一种第二种叫呃嗯与 ALWAYS什么意思啊
destroy npu finished.
~NpuUint.
This performance data only calculates the time consumption of model inference. Unless otherwise specified, it does not include the time consumption of pre-processing and post-processing.
| SoC | NPU | Model | Input Resolution | Network Creation Time | Network Preparation Time | Single Frame Inference Time | Post-processing Time | Total Time | Frame Rate |
|---|---|---|---|---|---|---|---|---|---|
| Allwinner A733 | Vivante VIP9000 | zipformer | 5.84 s | 32.2 ms | 4.2 ms | 309.0 ms | 345.4 ms | RTF 0.053 |
cd zipformer_demo_linux_t527/
chmod +x ./zipformer_demo_t527
./zipformer_demo_t527 -nb0 model/encoder_int16_t527.nb -nb1 model/decoder_int16_t527.nb -nb2 model/joiner_int16_t527.nb -i model/test.wav
The running result is as follows:
$ ./zipformer_demo_t527 -nb0 model/encoder_int16_t527.nb -nb1 model/decoder_int16_t527.nb -nb2 model/joiner_int16_t527.nb -i model/test.wav
encoder_path=model/encoder_int16_t527.nb, decoder_path=model/decoder_int16_t527.nb, joiner_path=model/joiner_int16_t527.nb, audio_path=model/test.wav
VIPLite driver software version 1.13.0.0-AW-2023-10-19
nbg name=model/encoder_int16_t527.nb, size: 37232320.
create network 0: 48424 us.
prepare network: 8934 us.
nbg name=model/decoder_int16_t527.nb, size: 7010624.
create network 1: 9543 us.
prepare network: 1251 us.
nbg name=model/joiner_int16_t527.nb, size: 5539648.
create network 2: 5803 us.
prepare network: 763 us.
Real Time Factor(RTF): 0.161 = 0.942s(infer_time) / 5.840s(audio_length)
Timestamp (s): 0.96, 1.04, 1.24, 1.32, 1.44, 1.72, 1.80, 2.04, 2.56, 3.04, 3.08, 3.48, 3.84, 4.68, 4.76, 5.00, 5.24, 5.48
Zipformer output: 这是第一种第二种叫呃嗯与 ALWAYS什么意思啊
destroy npu finished.
~NpuUint.
This performance data only calculates the time consumption of model inference. Unless otherwise specified, it does not include the time consumption of pre-processing and post-processing.
| SoC | NPU | Model | Input Resolution | Network Creation Time | Network Preparation Time | Single Frame Inference Time | Post-processing Time | Total Time | Frame Rate |
|---|---|---|---|---|---|---|---|---|---|
| Allwinner T527 | Vivante VIP9000 | zipformer | 5.84 s | 63.8 ms | 10.9 ms | 942.0 ms | 1016.7 ms | RTF 0.161 |