-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·151 lines (134 loc) · 5.56 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·151 lines (134 loc) · 5.56 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/env bash
set -euo pipefail
lw_project_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
lw_bin_dir="${HOME}/.local/bin"
lw_lib_dir="${HOME}/.local/lib/local-wisper"
lw_target="${lw_bin_dir}/lw"
lw_ort_shared="libonnxruntime_providers_shared.so"
lw_ort_cuda="libonnxruntime_providers_cuda.so"
lw_config_dir="${HOME}/.config/local-wisper"
lw_env_path="${lw_config_dir}/env"
lw_glossary_path="${lw_config_dir}/glossary.txt"
lw_cache_base="${XDG_CACHE_HOME:-${HOME}/.cache}"
lw_package_cache="${lw_cache_base}/local-wisper/packages"
if [[ "$(uname -s)" != "Linux" || "$(uname -m)" != "x86_64" ]]; then
echo "This experiment supports x86_64 Linux only." >&2
exit 1
fi
for lw_command in baml cargo curl readlink sha256sum; do
if ! command -v "${lw_command}" >/dev/null 2>&1; then
echo "Missing required command: ${lw_command}" >&2
exit 1
fi
done
echo "Generating the BAML Rust SDK..."
"${lw_project_dir}/scripts/baml" generate -q --project "${lw_project_dir}"
echo "Building the release binary..."
cargo build --release --locked --manifest-path "${lw_project_dir}/Cargo.toml"
for lw_ort_library in "${lw_ort_shared}" "${lw_ort_cuda}"; do
if [[ ! -f "${lw_project_dir}/target/release/${lw_ort_library}" ]]; then
echo "Release build did not produce ${lw_ort_library}." >&2
exit 1
fi
done
mkdir -p "${lw_bin_dir}" "${lw_lib_dir}" "${lw_config_dir}" "${lw_package_cache}"
chmod 700 "${lw_config_dir}"
lw_has_nvidia=false
if command -v nvidia-smi >/dev/null 2>&1 && nvidia-smi -L >/dev/null 2>&1; then
lw_has_nvidia=true
fi
if [[ "${lw_has_nvidia}" == true && ! -f /usr/lib/libcudnn.so.9 && ! -f "${lw_lib_dir}/libcudnn.so.9" ]]; then
for lw_command in bsdtar pacman pacman-key; do
if ! command -v "${lw_command}" >/dev/null 2>&1; then
echo "CUDA is available, but cuDNN 9 is missing and ${lw_command} cannot install it." >&2
echo "Install cuDNN 9 for this system, then rerun install.sh." >&2
exit 1
fi
done
echo "Downloading the signed Manjaro cuDNN package..."
lw_cudnn_url="$(pacman -Sp --print-format '%l' cudnn | tail -n 1)"
if [[ -z "${lw_cudnn_url}" ]]; then
echo "Could not resolve the cudnn package from the configured pacman repositories." >&2
exit 1
fi
lw_cudnn_package="${lw_package_cache}/${lw_cudnn_url##*/}"
curl --fail --location --continue-at - --output "${lw_cudnn_package}" "${lw_cudnn_url}"
curl --fail --location --output "${lw_cudnn_package}.sig" "${lw_cudnn_url}.sig"
pacman-key --verify "${lw_cudnn_package}.sig" "${lw_cudnn_package}"
lw_extract_dir="$(mktemp -d)"
trap 'rm -rf -- "${lw_extract_dir}"' EXIT
bsdtar -xf "${lw_cudnn_package}" -C "${lw_extract_dir}"
cp -a "${lw_extract_dir}"/usr/lib/libcudnn*.so.9* "${lw_lib_dir}/"
rm -rf -- "${lw_extract_dir}"
trap - EXIT
fi
# Stage complete files beside their destinations. The running installation is
# untouched until every build artifact is ready, and the executable moves last.
lw_stage_suffix=".part-$$"
lw_staged_target="${lw_target}${lw_stage_suffix}"
lw_cleanup_staging() {
rm -f -- "${lw_staged_target}"
for lw_staged_library in "${lw_ort_shared}" "${lw_ort_cuda}"; do
rm -f -- "${lw_lib_dir}/${lw_staged_library}${lw_stage_suffix}"
done
}
trap lw_cleanup_staging EXIT
install -m755 "${lw_project_dir}/target/release/lw" "${lw_staged_target}"
for lw_ort_library in "${lw_ort_shared}" "${lw_ort_cuda}"; do
install -m755 \
-T "$(readlink -f "${lw_project_dir}/target/release/${lw_ort_library}")" \
"${lw_lib_dir}/${lw_ort_library}${lw_stage_suffix}"
done
while read -r lw_legacy_pid; do
[[ -n "${lw_legacy_pid}" ]] || continue
lw_legacy_command="$(tr '\0' ' ' <"/proc/${lw_legacy_pid}/cmdline" 2>/dev/null || true)"
if [[ "${lw_legacy_command}" == *"/local-wisper/"*"transcribe_daemon.py"* ]]; then
echo "Stopping legacy Python model process ${lw_legacy_pid}..."
kill "${lw_legacy_pid}" 2>/dev/null || true
fi
done < <(pgrep -u "$(id -u)" -f 'transcribe_daemon\.py' || true)
while read -r lw_native_pid; do
[[ -n "${lw_native_pid}" ]] || continue
lw_native_exe="$(readlink -f "/proc/${lw_native_pid}/exe" 2>/dev/null || true)"
if [[ "${lw_native_exe}" == "${lw_target}" ]]; then
echo "Stopping installed native model process ${lw_native_pid}..."
kill "${lw_native_pid}" 2>/dev/null || true
for _ in {1..50}; do
[[ ! -e "/proc/${lw_native_pid}" ]] && break
sleep 0.1
done
if [[ -e "/proc/${lw_native_pid}" ]]; then
kill -KILL "${lw_native_pid}" 2>/dev/null || true
fi
fi
done < <(pgrep -u "$(id -u)" -f '(^|/)lw __daemon( |$)' || true)
for lw_ort_library in "${lw_ort_shared}" "${lw_ort_cuda}"; do
mv -fT \
"${lw_lib_dir}/${lw_ort_library}${lw_stage_suffix}" \
"${lw_lib_dir}/${lw_ort_library}"
ln -sfn \
"../lib/local-wisper/${lw_ort_library}" \
"${lw_bin_dir}/${lw_ort_library}"
done
mv -fT "${lw_staged_target}" "${lw_target}"
trap - EXIT
if [[ ! -f "${lw_env_path}" ]]; then
{
echo "export OPENAI_API_KEY=''"
echo "export LW_POST_PROCESS_MODEL=''"
echo "export LW_POST_PROCESS_TIMEOUT='20'"
echo "export LW_POST_PROCESS_GLOSSARY_FILE='${lw_glossary_path}'"
echo "export LW_BACKEND='parakeet'"
echo "export LW_DEVICE='auto'"
echo "export LW_VAD_FILTER='false'"
echo "export LW_OUTPUT_MODE='type'"
} >"${lw_env_path}"
chmod 600 "${lw_env_path}"
fi
if [[ ! -f "${lw_glossary_path}" ]]; then
install -m600 "${lw_project_dir}/glossary.example.txt" "${lw_glossary_path}"
fi
echo "Caching the BAML runtime..."
"${lw_target}" sway-cancel
echo "Installed ${lw_target}"
echo "Run 'lw preload' to select the best available runtime and load Parakeet Unified."