-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# Buddy Compiler WHISPER Example | ||
|
||
## Introduction | ||
This example shows how to use Buddy Compiler to compile a WHISPER model to MLIR code then run it. The [model](https://huggingface.co/openai/whisper-base) is a pre-trained model for automatic speech recognition (ASR) and speech translation (ST). | ||
|
||
|
||
## How to run | ||
|
||
0. Enter Python virtual environment. | ||
|
||
We recommend you to use anaconda3 to create python virtual environment. You should install python packages as buddy-mlir/requirements. | ||
|
||
``` | ||
$ conda activate <your virtual environment name> | ||
$ cd buddy-mlir | ||
$ pip install -r requirements.txt | ||
``` | ||
|
||
1. Build and check LLVM/MLIR | ||
|
||
``` | ||
$ cd buddy-mlir | ||
$ mkdir llvm/build | ||
$ cd llvm/build | ||
$ cmake -G Ninja ../llvm \ | ||
-DLLVM_ENABLE_PROJECTS="mlir;clang;openmp" \ | ||
-DLLVM_TARGETS_TO_BUILD="host;RISCV" \ | ||
-DLLVM_ENABLE_ASSERTIONS=ON \ | ||
-DOPENMP_ENABLE_LIBOMPTARGET=OFF \ | ||
-DCMAKE_BUILD_TYPE=RELEASE \ | ||
-DMLIR_ENABLE_BINDINGS_PYTHON=ON \ | ||
-DPython3_EXECUTABLE=$(which python3) | ||
$ ninja check-clang check-mlir omp | ||
``` | ||
|
||
2. Build and check buddy-mlir | ||
|
||
``` | ||
$ cd buddy-mlir | ||
$ mkdir build | ||
$ cd build | ||
$ cmake -G Ninja .. \ | ||
-DMLIR_DIR=$PWD/../llvm/build/lib/cmake/mlir \ | ||
-DLLVM_DIR=$PWD/../llvm/build/lib/cmake/llvm \ | ||
-DLLVM_ENABLE_ASSERTIONS=ON \ | ||
-DCMAKE_BUILD_TYPE=RELEASE \ | ||
-DBUDDY_MLIR_ENABLE_PYTHON_PACKAGES=ON \ | ||
-DPython3_EXECUTABLE=$(which python3) | ||
$ ninja | ||
$ ninja check-buddy | ||
``` | ||
|
||
Set the `PYTHONPATH` environment variable. Make sure that the `PYTHONPATH` variable includes the directory of LLVM/MLIR python bindings and the directory of Buddy MLIR python packages. | ||
|
||
```bash | ||
$ export PYTHONPATH=/path-to-buddy-mlir/llvm/build/tools/mlir/python_packages/mlir_core:/path-to-buddy-mlir/build/python_packages:${PYTHONPATH} | ||
|
||
// For example: | ||
// Navigate to your buddy-mlir/build directory | ||
$ cd buddy-mlir/build | ||
$ export BUDDY_MLIR_BUILD_DIR=$PWD | ||
$ export LLVM_MLIR_BUILD_DIR=$PWD/../llvm/build | ||
$ export PYTHONPATH=${LLVM_MLIR_BUILD_DIR}/tools/mlir/python_packages/mlir_core:${BUDDY_MLIR_BUILD_DIR}/python_packages:${PYTHONPATH} | ||
``` | ||
|
||
3. Set model environment variable. | ||
|
||
```bash | ||
$ export WHISPER_MODEL_PATH=/path-to-whisper-model/ | ||
|
||
// For example: | ||
$ export WHISPER_MODEL_PATH=/home/xxx/whisper-base | ||
``` | ||
Alternatively, you can leave the path blank, and import-whisper.py will automatically download the model for you. | ||
|
||
4. Build and run the WHISPER example | ||
|
||
```bash | ||
$ cmake -G Ninja .. -DBUDDY_WHISPER_EXAMPLES=ON | ||
$ ninja buddy-whisper-run | ||
$ cd bin | ||
$ ./buddy-whisper-run | ||
``` | ||
|
||
5. Enjoy it! |