-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·70 lines (55 loc) · 2.23 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#/bin/bash
# TODO:
# - intel mac build
set -e
# target should be one of:
# osx-arm64
# linux-x64
# osx-x86_64
target=$1
# build
mkdir -p build
cd build
# fetch onnx runtime
wget -q https://github.com/microsoft/onnxruntime/releases/download/v1.16.3/onnxruntime-$target-1.16.3.tgz -O onnxruntime-$target-1.16.3.tgz
tar -xvf ./onnxruntime-$target-1.16.3.tgz
# fetch model
mkdir -p all-MiniLM-L6-v2
wget -q https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2/resolve/main/pytorch_model.bin?download=true -O all-MiniLM-L6-v2/pytorch_model.bin
wget -q https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2/resolve/main/tokenizer.json?download=true -O all-MiniLM-L6-v2/tokenizer.json
wget -q https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2/resolve/main/config.json?download=true -O all-MiniLM-L6-v2/config.json
if [[ -z "${RUNNING_IN_DOCKER-}" ]]; then
python3.10 -m venv venv && source venv/bin/activate
# this is to avoid downloading cuda
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
pip install -r ../requirements-dev.txt
fi
python ../export_model_onnx.py
xxd -i all-MiniLM-L6-v2.onnx > model.h
input_size=128 # NOTE: model specific config - read from model files if possible
output_size=384
# write tokenizer to header file
echo -e "#pragma once\nauto input_size=$input_size;\nauto output_size=$output_size;\n" > tokenizer.h
# remove truncation and padding from tokenizer config
jq -c 'del(.truncation, .padding)' all-MiniLM-L6-v2/tokenizer.json > tokenizer.json
xxd -i tokenizer.json >> tokenizer.h
if [ -n "$RUNNING_IN_DOCKER" ]; then
# TODO does this do anything? an attempt to fix the flakiness of the build
source $HOME/.cargo/env && rustup default 1.71.0 && rustup toolchain remove stable
fi
cmake .. -DONNXRUNTIME_ROOTDIR=$PWD/onnxruntime-$target-1.16.3 -DCMAKE_BUILD_TYPE=Release
make -j8
if [[ -z "${RUNNING_IN_DOCKER-}" ]]; then
deactivate
fi
cd ..
mkdir -p dist
cp build/hae dist
cp LICENSE dist
cp NOTICES dist
if [[ "$target" != "linux-x64" ]]; then
cp build/onnxruntime-$target-1.16.3/lib/libonnxruntime.1.16.3.dylib dist/
fi
if [[ "$target" == "linux-x64" ]]; then
cp build/onnxruntime-$target-1.16.3/lib/libonnxruntime.so.1.16.3 dist/
fi