-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_arm_docker.sh
More file actions
executable file
·159 lines (141 loc) · 4.21 KB
/
Copy pathrun_arm_docker.sh
File metadata and controls
executable file
·159 lines (141 loc) · 4.21 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
152
153
154
155
156
157
158
159
#!/bin/bash
# run_arm_docker.sh
# Build and run QSoftmax on ARM via Docker
#
# Usage:
# ./run_arm_docker.sh # Build and run full benchmark
# ./run_arm_docker.sh --build # Force rebuild
# ./run_arm_docker.sh --onnx # ONNX benchmark only
# ./run_arm_docker.sh --shell # Interactive shell
# ./run_arm_docker.sh --clean # Remove container and images
set -e
IMAGE_NAME="qsoftmax-arm"
CONTAINER_NAME="qsoftmax-benchmark"
RESULTS_DIR="$(pwd)/results"
# Detect architecture
ARCH=$(uname -m)
OS=$(uname -s)
echo "=============================================="
echo "QSoftmax ARM Docker Runner"
echo "=============================================="
echo "Architecture: $ARCH"
echo "OS: $OS"
echo ""
# Check if running on ARM
if [[ "$ARCH" != "arm64" && "$ARCH" != "aarch64" ]]; then
echo "Warning: Not running on native ARM architecture."
echo "Docker will use emulation (slower performance)."
echo ""
read -p "Continue anyway? [y/N] " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 1
fi
fi
# Set Docker platform for ARM
export DOCKER_DEFAULT_PLATFORM=linux/arm64
# Create results directory
mkdir -p "$RESULTS_DIR/benchmark" "$RESULTS_DIR/onnx" "$RESULTS_DIR/llama2"
# Parse arguments
FORCE_BUILD=false
ONNX_ONLY=false
INTERACTIVE=false
CLEAN=false
for arg in "$@"; do
case $arg in
--build)
FORCE_BUILD=true
;;
--onnx)
ONNX_ONLY=true
;;
--shell)
INTERACTIVE=true
;;
--clean)
CLEAN=true
;;
--help|-h)
echo "Usage: $0 [options]"
echo ""
echo "Options:"
echo " --build Force rebuild of Docker image"
echo " --onnx Run ONNX benchmark only"
echo " --shell Start interactive shell"
echo " --clean Remove container and images"
echo " --help Show this help"
exit 0
;;
esac
done
# Clean command
if [ "$CLEAN" = true ]; then
echo "Cleaning up..."
docker rm -f "$CONTAINER_NAME" 2>/dev/null || true
docker rmi -f "$IMAGE_NAME" 2>/dev/null || true
echo "Done."
exit 0
fi
# Check if image exists or force build
if [ "$FORCE_BUILD" = true ] || ! docker image inspect "$IMAGE_NAME" > /dev/null 2>&1; then
echo "Building Docker image for ARM64..."
echo ""
docker build \
--platform linux/arm64 \
--tag "$IMAGE_NAME:latest" \
--progress=plain \
.
echo ""
echo "Build complete."
echo ""
fi
# Remove existing container if present
docker rm -f "$CONTAINER_NAME" 2>/dev/null || true
# Run based on mode
if [ "$INTERACTIVE" = true ]; then
echo "Starting interactive shell..."
docker run \
--rm \
-it \
--platform linux/arm64 \
--name "$CONTAINER_NAME" \
-v "$(pwd):/app/workspace" \
-v "$RESULTS_DIR:/app/results" \
-e OMP_NUM_THREADS=4 \
-w /app/workspace \
"$IMAGE_NAME" \
bash
elif [ "$ONNX_ONLY" = true ]; then
echo "Running ONNX benchmark..."
docker run \
--rm \
--platform linux/arm64 \
--name "$CONTAINER_NAME" \
-v "$RESULTS_DIR:/app/results" \
-e OMP_NUM_THREADS=4 \
"$IMAGE_NAME" \
bash -c "
python3 qsoftmax_onnx.py --info &&
python3 qsoftmax_onnx.py --export /app/results/onnx/qsoftmax.onnx --seq-len 512 --head-dim 64 &&
echo '' &&
echo 'Benchmarking across sequence lengths...' &&
for seq in 128 256 512 1024 2048; do
echo \"=== seq_len=\$seq ===\" &&
python3 qsoftmax_onnx.py --benchmark /app/results/onnx/qsoftmax.onnx --seq-len \$seq --head-dim 64 --iterations 50
done
"
else
echo "Running full benchmark suite..."
docker run \
--rm \
--platform linux/arm64 \
--name "$CONTAINER_NAME" \
-v "$RESULTS_DIR:/app/results" \
-e OMP_NUM_THREADS=4 \
"$IMAGE_NAME"
fi
echo ""
echo "=============================================="
echo "Results saved to: $RESULTS_DIR"
echo "=============================================="
ls -la "$RESULTS_DIR"