aboutsummaryrefslogtreecommitdiff
path: root/ai/whisper.sh
blob: 3a2234c32fb0eb96e8acc6f6394ad7d0770e86f9 (plain) (blame)
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
#!/bin/sh
# Install whisper on Fedora targeting ROCm devices under its own user account.
set -e
un=whisper

printR() {
	printf '\033[1;31m%s\033[0m\n' "$@"
}

setupNote() {
	printR "The user $un was created for whisper"
	printR "To switch to that user and run whsiper commands run:"
	printR "sudo su - $un"
}

if [ "$(id -un)" != "$un" ] ; then
	if [ "$(id -un)" != "root" ] ; then
		echo "Re run this as root/with sudo to create the user"
		exit 1
	fi

	set -x
	if ! grep '^'"$un" /etc/passwd ; then
		sudo adduser "$un"
	fi
	for group in video render ; do
		sudo gpasswd -a "$un" "$group"
	done
	set +x

	cp "$0" /home/"$un"/whisper.sh
	su - "$un" /home/"$un"/whisper.sh

	trap setupNote EXIT

	exit 0;
fi

set -ex
miniconda=1
miniconda_sha256='b978856ec3c826eb495b60e3fffe621f670c101150ebcbdeede4f961f22dc438'
rocm_version="5.7" # rpm -qa | grep -i rocm # or so

if [ -d ~/miniconda3 ] ; then miniconda=0 ; fi

if [ $miniconda -eq 1 ] ; then
miniconda_out=/tmp/miniconda3.sh
trap "rm -f \"$miniconda_out\"" EXIT INT

wget -O "$miniconda_out" \
	https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh

if ! sha256sum "$miniconda_out" | grep -q "$miniconda_sha256" ; then
	echo "Bad checksum for miniconda installer, perhaps a network issue or out of date checksum?"
	exit 1
fi

bash "$miniconda_out" -b -u -p ~/miniconda3
~/miniconda3/bin/conda init bash
fi


if ! conda env list | grep -q '^whisper' ; then
	conda create -y --name whisper python=3.9
fi

set +ex
. ~/.bashrc
set -ex

conda activate whisper
# https://rocm.docs.amd.com/projects/install-on-linux/en/latest/how-to/3rd-party/pytorch-install.html
conda install -y pytorch==2.0.0 torchaudio==2.0.0 -c pytorch
pip install -U openai-whisper
pip3 install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/rocm5.7/
pip install --upgrade --no-deps --force-reinstall git+https://github.com/openai/whisper.git

if ! grep '^conda activate whisper' ~/.bashrc ; then
	echo conda activate whisper >> ~/.bashrc
fi