-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
89817e9
commit 6f3f640
Showing
7 changed files
with
272 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Copyright 2023 The OpenXLA Authors | ||
# | ||
# Licensed under the Apache License v2.0 with LLVM Exceptions. | ||
# See https://llvm.org/LICENSE.txt for license information. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
# An image for cross-compiling towards Android. | ||
|
||
FROM gcr.io/iree-oss/openxla-benchmark/base@sha256:1bf3e319465ec8fb465baae3f6ba9a5b09cb84a5349a675c671a552fc77f2251 | ||
|
||
ARG NDK_VERSION=r25c | ||
WORKDIR /install-ndk | ||
|
||
ENV ANDROID_NDK "/usr/src/android-ndk-${NDK_VERSION}" | ||
|
||
RUN wget -q "https://dl.google.com/android/repository/android-ndk-${NDK_VERSION}-linux.zip" \ | ||
&& unzip -q "android-ndk-${NDK_VERSION}-linux.zip" -d /usr/src/ \ | ||
&& rm -rf /install-ndk | ||
|
||
WORKDIR / |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#!/bin/bash | ||
# | ||
# Copyright 2023 The OpenXLA Authors | ||
# | ||
# Licensed under the Apache License v2.0 with LLVM Exceptions. | ||
# See https://llvm.org/LICENSE.txt for license information. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
# | ||
# Environment variables: | ||
# PYTHON: Python interpreter, default: /usr/bin/python3 | ||
# OOBI_VENV_DIR: path to create Python virtualenv, default: ggml-benchmarks.venv | ||
# OOBI_TARGET_DEVICE: target benchmark device, can also be specified the first | ||
# argument. | ||
# OOBI_BUILD_DIR: path to the GGMl build directory. | ||
# OOBI_OUTPUT: path to output benchmark results, can also be specified the | ||
# second argument. | ||
# | ||
# Example usage: | ||
# ./benchmark_ggml_android.sh <target-device> <build-dir> <result-path> | ||
|
||
set -xeuo pipefail | ||
|
||
VENV_DIR="${OOBI_VENV_DIR:-ggml-benchmarks.venv}" | ||
PYTHON="${PYTHON:-/usr/bin/python3}" | ||
TARGET_DEVICE="${1:-${OOBI_TARGET_DEVICE}}" | ||
BUILD_DIR="${2:-${OOBI_BUILD_DIR}}" | ||
OUTPUT_PATH="${3:-${OOBI_OUTPUT}}" | ||
|
||
TD="$(cd $(dirname $0) && pwd)" | ||
|
||
# Setup virtual environment. | ||
VENV_DIR="${VENV_DIR}" PYTHON="${PYTHON}" source "${TD}/setup_venv.sh" | ||
|
||
# Initialize results json. | ||
OUTPUT_PATH="$(realpath ${OUTPUT_PATH})" | ||
"${TD}/../../comparative_benchmark/scripts/create_results_json.sh" "${OUTPUT_PATH}" | ||
|
||
pushd "${BUILD_DIR}" | ||
|
||
PROMPT="Once upon a time" | ||
BENCHMARK_BINARY="$(realpath bin/gpt-2)" | ||
WARMUP_ITERAIONS=2 | ||
NUM_ITERATIONS=10 | ||
declare -a NUM_THREADS=(1 8 16) | ||
|
||
MODEL="$(realpath models/gpt-2-117M/ggml-model-f32.bin)" | ||
|
||
declare -a BENCHMARK_NAMES=( | ||
"models/GPT2LMHEAD_FP32_GGML/inputs/INPUT_DATA_MODEL_DEFAULT" | ||
"models/GPT2LMHEAD_FP16_GGML/inputs/INPUT_DATA_MODEL_DEFAULT" | ||
"models/GPT2LMHEAD_INT4_GGML/inputs/INPUT_DATA_MODEL_DEFAULT" | ||
) | ||
declare -a MODELS=( | ||
ggml-model-f32.bin | ||
ggml-model-f16.bin | ||
ggml-model-q4_0.bin | ||
) | ||
declare -a DATA_TYPES=( | ||
"fp32" | ||
"fp16" | ||
"int4" | ||
) | ||
|
||
for i in ${!BENCHMARK_NAMES[@]}; do | ||
MODEL="$(realpath models/gpt-2-117M/${MODELS[$i]})" | ||
|
||
for threads in "${NUM_THREADS[@]}"; do | ||
"${TD}/benchmark.py" \ | ||
--benchmark_name "${BENCHMARK_NAMES[$i]}" \ | ||
--warmup_iterations "${WARMUP_ITERAIONS}" \ | ||
--iterations "${NUM_ITERATIONS}" \ | ||
--benchmark_binary "${BENCHMARK_BINARY}" \ | ||
--model "${MODEL}" \ | ||
--data_type "${DATA_TYPES[$i]}" \ | ||
--prompt "${PROMPT}" \ | ||
--seed 0 \ | ||
--threads "${threads}" \ | ||
--output "${OUTPUT_PATH}" \ | ||
--target_device "${TARGET_DEVICE}" \ | ||
--verbose | ||
done | ||
done | ||
|
||
popd # BUILD_DIR |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#!/bin/bash | ||
# | ||
# Copyright 2023 The OpenXLA Authors | ||
# | ||
# Licensed under the Apache License v2.0 with LLVM Exceptions. | ||
# See https://llvm.org/LICENSE.txt for license information. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
# | ||
# Environment variables: | ||
# PYTHON: Python interpreter, default: /usr/bin/python3 | ||
# ANDROID_NDK: the path to the Android NDK if building for Android. | ||
# OOBI_VENV_DIR: path to create Python virtualenv, default: ggml-build.venv | ||
# OOBI_TARGET_DEVICE: target benchmark device, can also be specified the first | ||
# argument. | ||
# OOBI_OUTPUT: path to output benchmark results, can also be specified the | ||
# second argument. | ||
# OOBI_SCRATCH_DIR: the directory to place temporary benchmarking artifacts. | ||
# | ||
# Example usage: | ||
# ./build_ggml.sh <target-device>> <build-dir> | ||
|
||
set -xeuo pipefail | ||
|
||
VENV_DIR="${OOBI_VENV_DIR:-ggml-build.venv}" | ||
ROOT_DIR="${OOBI_SCRATCH_DIR:-/tmp}" | ||
PYTHON="${PYTHON:-/usr/bin/python3}" | ||
TARGET_DEVICE_NAME="${1:-${OOBI_TARGET_DEVICE}}" | ||
BUILD_DIR="${2:-/tmp/ggml-build}" | ||
|
||
TD="$(cd $(dirname $0) && pwd)" | ||
BUILD_DIR="$(realpath ${BUILD_DIR})" | ||
|
||
# Setup virtual environment. | ||
VENV_DIR="${VENV_DIR}" PYTHON="${PYTHON}" source "${TD}/setup_venv.sh" | ||
|
||
pushd "${ROOT_DIR}" | ||
|
||
# We clone a fork of ggml which includes additional benchmark logging. | ||
git clone --branch benchmark https://github.com/mariecwhite/ggml.git | ||
pushd ggml | ||
|
||
REPO_DIR="$(pwd)" | ||
|
||
# Build. | ||
if [[ "${TARGET_DEVICE_NAME}" =~ ^(pixel-4|pixel-6-pro|moto-edge-x30)$ ]]; then | ||
cmake -GNinja -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK}/build/cmake/android.toolchain.cmake -DANDROID_ABI=arm64-v8a -DANDROID_PLATFORM=android-23 -DCMAKE_C_FLAGS=-march=armv8.4a+dotprod -B "${BUILD_DIR}" . | ||
cmake --build "${BUILD_DIR}" -t gpt-2 gpt-2-quantize | ||
else | ||
cmake -G Ninja -B "${BUILD_DIR}" . | ||
cmake --build "${BUILD_DIR}" -t gpt-2 gpt-2-quantize | ||
fi | ||
|
||
popd # ggml | ||
popd # ROOT_DIR | ||
|
||
# Generate FP32 and FP16 versions of GPT2 117M (Small). | ||
pushd "${BUILD_DIR}" | ||
|
||
GPT_VARIANT="117M" | ||
${REPO_DIR}/examples/gpt-2/download-model.sh "${GPT_VARIANT}" | ||
# Generate FP32. | ||
python ${REPO_DIR}/examples/gpt-2/convert-ckpt-to-ggml.py models/gpt-2-${GPT_VARIANT}/ 0 | ||
# Generate FP16. | ||
python ${REPO_DIR}/examples/gpt-2/convert-ckpt-to-ggml.py models/gpt-2-${GPT_VARIANT}/ 1 | ||
# Generate INT4. Keep this disabled until we want to use it. | ||
#./bin/gpt-2-quantize models/gpt-2-${GPT_VARIANT}/ggml-model-f16.bin models/gpt-2-${GPT_VARIANT}/ggml-model-q4_0.bin 2 | ||
|
||
popd # BUILD_DIR |