-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNPU_setup.sh
More file actions
107 lines (88 loc) · 3.04 KB
/
NPU_setup.sh
File metadata and controls
107 lines (88 loc) · 3.04 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
#!/usr/bin/env bash
set -euo pipefail
# Config
VENV_DIR="tosa-compatibility-ethos-lab-env"
WHEEL_URL="https://drive.usercontent.google.com/uc?id=1pNhHJcviX493iObHD8Lci9MLEaS1Um84&export=download"
WHEEL_FILE="tosa_checker-0.2.0-cp310-cp310-linux_x86_64.whl"
have() { command -v "$1" >/dev/null 2>&1; }
pkg_installed() { dpkg -s "$1" >/dev/null 2>&1; }
echo "Auto Python 3.10 venv setup (Ubuntu)"
# 0) Basics
sudo apt-get update -y
sudo apt-get install -y wget curl ca-certificates software-properties-common
# 1) Decide which Python to use (prefer system python3 if it's 3.10)
PYCMD="python3"
if have python3; then
PY_MAJ_MIN="$(python3 - <<'PY'
import sys; print(".".join(map(str, sys.version_info[:2])))
PY
)"
else
PY_MAJ_MIN=""
fi
if [[ "$PY_MAJ_MIN" == "3.10" ]]; then
echo "Detected default python3 == 3.10 → will use python3"
# Ensure venv module for default python3
if ! pkg_installed python3-venv; then
echo "Installing python3-venv for default python3..."
sudo apt-get install -y python3-venv
fi
else
echo "Default python3 is '$PY_MAJ_MIN' (not 3.10). Installing python3.10 + python3.10-venv..."
PYCMD="python3.10"
if ! have python3.10 || ! pkg_installed python3.10-venv; then
# Try native repos first
if ! sudo apt-get install -y python3.10 python3.10-venv; then
echo "Enabling deadsnakes PPA to get Python 3.10..."
sudo add-apt-repository -y ppa:deadsnakes/ppa
sudo apt-get update -y
sudo apt-get install -y python3.10 python3.10-venv
fi
fi
fi
echo "Using interpreter: $PYCMD ($( $PYCMD -V ))"
# 2) Create venv (idempotent) and activate
if [ -d "$VENV_DIR" ]; then
echo "Virtual environment '$VENV_DIR' already exists. Reusing it."
else
echo "Creating virtual environment at ./$VENV_DIR ..."
"$PYCMD" -m venv "$VENV_DIR"
fi
# Activate for this script session
# shellcheck disable=SC1090
source "$VENV_DIR/bin/activate"
# 3) Verify Python is 3.10.* (major.minor only)
VENV_PY_MAJ_MIN="$(python - <<'PY'
import sys; print(".".join(map(str, sys.version_info[:2])))
PY
)"
if [ "$VENV_PY_MAJ_MIN" != "3.10" ]; then
echo "ERROR: Virtualenv Python is not 3.10 (got $(python -V))."
exit 1
fi
echo "Venv active: $(python -V)"
# 4) Install libraries into THIS venv
python -m pip install --upgrade pip setuptools wheel
# Correct names: ethos-u-vela (provides 'vela' CLI), tensorflow-datasets (hyphen), matplotlib (not matplotlib.pyplot)
python -m pip install --upgrade \
tensorflow \
numpy \
ethos-u-vela \
notebook \
tensorflow-datasets \
matplotlib
# 5) Download the wheel and install
echo "Downloading wheel..."
wget -O "$WHEEL_FILE" "$WHEEL_URL"
test -s "$WHEEL_FILE" || { echo "Download failed or empty file: $WHEEL_FILE"; exit 1; }
echo "Installing wheel..."
python -m pip install "./$WHEEL_FILE"
python <<EOF
import tensorflow_datasets as tfds
import os
DATA_DIR = "/home/ubuntu/tensorflow_datasets"
os.makedirs(DATA_DIR, exist_ok=True)
# Download and prepare the dataset
tfds.load("imagenette/320px-v2", data_dir=DATA_DIR, download=True)
print("Dataset downloaded and ready at:", DATA_DIR)
EOF