Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge branch 'submission-v4.1' into 'master' #949

Draft
wants to merge 21 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
513dcf1
Enable stable_diffusion tests
anhappdev Sep 6, 2024
d92f069
Merge branch 'refs/heads/master' into submission-v4.1
anhappdev Sep 11, 2024
723d323
Add a caption_id to coco_gen dataset (#918)
anhappdev Sep 17, 2024
eea4595
Final Submission for code for Qualcomm
mohitmundhragithub Sep 20, 2024
bcf4215
Addressing review comments
mohitmundhragithub Sep 27, 2024
0ae020e
Update seed and num_steps for TFLite SD task (#16)
anhappdev Oct 3, 2024
acb17bf
Ran make format
mohitmundhragithub Oct 3, 2024
b6ee8e7
Applying linter changes
mohitmundhragithub Oct 3, 2024
c811734
Merge pull request #9 from mlcommons/submission_v4.1_qti
freedomtan Oct 8, 2024
786a485
Update QTI backend for submission v4.1 (#13)
anhappdev Oct 15, 2024
fad6765
Update tflite_settings_mtk_mt6989.pbtxt
anhappdev Oct 16, 2024
f74b27c
enable stable diffusion in Pixel backend (#936)
freedomtan Dec 17, 2024
aab2697
feat: add icon and description for Stable Diffusion benchmark (#917)
anhappdev Dec 17, 2024
48654bd
use time step embedding from file (#928)
RSMNYS Jan 14, 2025
f7fc2e8
Update model_path for stable_diffusion (#946)
anhappdev Jan 15, 2025
30483df
Merge branch 'submission-v4.1' into anh/merge-v4.1-into-master
anhappdev Jan 15, 2025
46c839a
Use CloudFare link for qti model_path
anhappdev Jan 15, 2025
6648c56
Use CloudFare link for tflite model_path
anhappdev Jan 15, 2025
dcd283f
Fix build error
anhappdev Jan 15, 2025
67f24a4
Add missing model_checksum
anhappdev Jan 15, 2025
ef6e4eb
Update expected_throughput
anhappdev Jan 16, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ build:android_x86_64 --fat_apk_cpu=x86_64

# iOS configs
build:ios --apple_platform_type=ios
build:ios --apple_bitcode=embedded --copt=-fembed-bitcode
build:ios --copt=-Wno-c++11-narrowing
build:ios --cxxopt=-fobjc-arc

Expand Down
17 changes: 13 additions & 4 deletions .github/workflows/android-build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,22 @@ jobs:
rm /tmp/${SAMSUNG_LIB}.zip && \
mkdir -p mobile_back_samsung/samsung/lib/internal && \
mv /tmp/${SAMSUNG_LIB}/* mobile_back_samsung/samsung/lib/internal/
- name: Download QTI SDK
env:
QTI_SDK: qairt-2.25.0.240728-linux
run: |
gsutil cp gs://mobile-app-build-290400_github-actions/lib/v4.1/${QTI_SDK}.zip /tmp/ && \
unzip /tmp/${QTI_SDK}.zip -d /tmp/${QTI_SDK} && \
rm /tmp/${QTI_SDK}.zip && \
mv /tmp/${QTI_SDK}/* mobile_back_qti/
- name: Download QTI libraries
env:
QTI_LIB: qaisw-2.20.0.240223_linux
QTI_LIB: StableDiffusionShared
run: |
gsutil cp gs://mobile-app-build-290400_github-actions/lib/v4.0/${QTI_LIB}.zip /tmp/ && \
gsutil cp gs://mobile-app-build-290400_github-actions/lib/v4.1/${QTI_LIB}.zip /tmp/ && \
unzip /tmp/${QTI_LIB}.zip -d /tmp/${QTI_LIB} && \
rm /tmp/${QTI_LIB}.zip && \
mkdir -p mobile_back_qti/${QTI_LIB} && \
mv /tmp/${QTI_LIB}/* mobile_back_qti/${QTI_LIB}/
mv /tmp/${QTI_LIB}/* mobile_back_qti/cpp/backend_qti/StableDiffusionShared/
- name: Cache bazel
uses: actions/cache@v4
with:
Expand Down Expand Up @@ -143,6 +150,7 @@ jobs:
PERF_TEST: true
WITH_TFLITE: 0
WITH_QTI: 1
WITH_STABLEDIFFUSION: 1
run: |
make flutter/android/release flutter/android/apk flutter/android/test-apk
gsutil mv output/android-apks/test-main.apk $GCLOUD_BUCKET_PATH/test-main-qti.apk
Expand Down Expand Up @@ -191,6 +199,7 @@ jobs:
WITH_QTI: 1
WITH_SAMSUNG: 1
WITH_APPLE: 0
WITH_STABLEDIFFUSION: 1
run: |
make flutter/android/release
gsutil cp flutter/build/app/outputs/bundle/release/app-release.aab $GCLOUD_BUCKET_PATH/app-release.aab
Expand Down
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
.ijwb
.idea
.vscode
.fvm
/bazel-*
/output
/output_logs
/datasets/output
/datasets/downloads
/mobile_back_qti/snpe-*
/mobile_back_qti/qaisw-*
*.so
* .apk
* .tflite
Expand All @@ -22,3 +21,7 @@ __pycache__/
*.log
*.iml
*.env

*.g.dart
*.gen.dart
*.gen.h
11 changes: 9 additions & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
workspace(name = "mlperf_app")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "bazel_skylib",
Expand Down Expand Up @@ -49,11 +49,11 @@ http_archive(
],
)

load("@rules_python//python:repositories.bzl", "python_register_toolchains")
load(
"@org_tensorflow//tensorflow/tools/toolchains/python:python_repo.bzl",
"python_repository",
)
load("@rules_python//python:repositories.bzl", "python_register_toolchains")

python_repository(name = "python_version_repo")

Expand Down Expand Up @@ -107,3 +107,10 @@ snpe_version_loader(
name = "snpe_version_loader",
workspace_dir = __workspace_dir__,
)

load("//mobile_back_qti/cpp/backend_qti/StableDiffusionShared:variables.bzl", "stable_diffusion_external_deps_shared")

stable_diffusion_external_deps_shared(
name = "stable_diffusion_external_deps_shared",
workspace_dir = __workspace_dir__,
)
3 changes: 2 additions & 1 deletion flutter/android/android-docker.mk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020-2022 The MLPerf Authors. All Rights Reserved.
# Copyright 2020-2024 The MLPerf Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -42,6 +42,7 @@ flutter_common_docker_flags= \
--env WITH_PIXEL=${WITH_PIXEL} \
--env WITH_MEDIATEK=${WITH_MEDIATEK} \
--env proxy_bazel_args=${proxy_bazel_args} \
--env BAZEL_OUTPUT_ROOT_ARG="--output_user_root=/image-workdir/cache/bazel" \
--env OFFICIAL_BUILD=${OFFICIAL_BUILD} \
--env FIREBASE_CRASHLYTICS_ENABLED=${FIREBASE_CRASHLYTICS_ENABLED} \
--env FLUTTER_BUILD_NUMBER=${FLUTTER_BUILD_NUMBER} \
Expand Down
6 changes: 5 additions & 1 deletion flutter/android/android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ANDROID_NDK_API_LEVEL?=33

flutter/android: flutter/android/libs
flutter/android/release: flutter/check-release-env flutter/android flutter/prepare flutter/android/apk flutter/android/appbundle
flutter/android/libs: flutter/android/libs/checksum flutter/android/libs/build flutter/android/libs/copy
flutter/android/libs: flutter/android/libs/deps flutter/android/libs/checksum flutter/android/libs/build flutter/android/libs/copy
# run `make flutter/android/apk` before `flutter/android/test-apk`
flutter/android/test-apk: flutter/android/test-apk/main flutter/android/test-apk/helper

Expand All @@ -35,6 +35,10 @@ else
@echo "Skip checksum validation"
endif

.PHONY: flutter/android/libs/deps
flutter/android/libs/deps:
${backend_qti_libs_deps}

.PHONY: flutter/android/libs/build
flutter/android/libs/build:
bazel ${BAZEL_OUTPUT_ROOT_ARG} ${proxy_bazel_args} ${sonar_bazel_startup_options} \
Expand Down
92 changes: 92 additions & 0 deletions flutter/android/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ RUN curl --proto '=https' -L https://github.com/bazelbuild/bazelisk/releases/dow
chmod +x /usr/local/bin/bazel

ENV ANDROID_SDK_ROOT=/opt/android
ENV ANDROID_HOME=/opt/android
WORKDIR $ANDROID_SDK_ROOT/cmdline-tools
# sdkmanager expects to be placed into `$ANDROID_SDK_ROOT/cmdline-tools/tools`
RUN curl --proto '=https' -L https://dl.google.com/android/repository/commandlinetools-linux-7583922_latest.zip | jar x && \
Expand Down Expand Up @@ -73,3 +74,94 @@ RUN mkdir $ANDROID_SDK_HOME && \

# Git repo will be mounted at '/image-workdir/project'
RUN git config --global --add safe.directory /image-workdir/project

# Add 32-bit support since the adb in our sdk's are 32-bit binaries
RUN dpkg --add-architecture i386
ARG DEBIAN_FRONTEND=noninteractive
ARG APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=DontWarn

# build-essential: for rest-kit(rest-kit needed for crad-repo)
# file : used by ndk to determine if host is 32 or 64 bit
# libtbb-dev: used for parallelization of postprocessing for pose-estimation
# libcanberra-gtk-module, libgtk2.0-dev: required by opencv runtime
# libstdc++6:i386: to add support for 32 bit binaries.
# libxtst6 : required to run ide(e.g intellij) inside docker
RUN apt-get update && apt-get install --no-install-recommends -y build-essential \
cmake \
curl \
git \
emacs \
file \
less \
libcanberra-gtk-module \
libgtk2.0-dev \
libtbb-dev \
libstdc++6:i386 \
libxtst6

# pkg-config: required by opencv runtime
# software-properties-common: for curl
# xterm : to make resize available for avoiding line wrapping
# zip : required when sourcing snpe envsetup
RUN apt-get update && apt-get install --no-install-recommends -y mc \
meld \
pkg-config \
python3-dev \
software-properties-common \
sudo \
tmux \
tree \
unzip \
vim \
wget \
xterm \
zip \
ffmpeg \
libjpeg-dev \
zlib1g-dev && \
apt-get clean autoclean

# Get cmake-3.19.3
# apt has 3.10.2 as latest version, so remove it
RUN apt-get remove --no-install-recommends -y cmake
RUN wget -q https://github.com/Kitware/CMake/releases/download/v3.19.3/cmake-3.19.3-Linux-x86_64.sh -O /opt/cmake-3.19.3-Linux-x86_64.sh && \
chmod +x /opt/cmake-3.19.3-Linux-x86_64.sh && mkdir -p /opt/cmake && \
bash /opt/cmake-3.19.3-Linux-x86_64.sh --skip-license --prefix=/opt/cmake && \
rm -rf /opt/cmake-3.19.3-Linux-x86_64.sh
# Add CMAKE into PATH
ENV PATH "/opt/cmake/bin:${PATH}"

# OpenCV
ENV CMAKE_TOOLCHAIN_FILE "${ANDROID_NDK_ROOT}/build/cmake/android.toolchain.cmake"
ENV ANDROID_ABI "arm64-v8a"
ENV API_LEVEL "31"
ENV ANDROID_TOOLCHAIN_NAME "aarch64-linux-android-4.9"
ARG COMMON_CMAKE_OPTIONS="-DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=release \
-DBUILD_ZLIB=ON -DWITH_FFMPEG=ON -DBUILD_TESTS=OFF \
-DWITH_TBB=ON -DBUILD_PERF_TESTS=OFF -DWITH_IPP=OFF \
-DWITH_OPENEXR=ON -DWITH_JASPER=ON -WITH_PNG=ON -DBUILD_FAT_JAVA_LIB=OFF WITH_IMGCODEC=ON"
# Ref: https://docs.opencv.org/3.4.0/d7/d9f/tutorial_linux_install.html
RUN wget -q https://github.com/opencv/opencv/archive/3.4.7/opencv-3.4.7.tar.gz -O /tmp/3.4.7.tar.gz && \
tar -C /tmp -xvf /tmp/3.4.7.tar.gz && \
# First build for arm-android
cd /tmp/opencv-3.4.7 && mkdir -p /opt/opencv-3.4.7_android/ release_android && cd release_android && \
cmake -DCMAKE_TOOLCHAIN_FILE="${CMAKE_TOOLCHAIN_FILE}" \
-DANDROID_NDK="${ANDROID_NDK}" \
-DANDROID_HOME="${ANDROID_HOME}" \
-DANDROID_STL=c++_shared \
-DBUILD_ANDROID_PROJECTS=OFF \
-DANDROID_NATIVE_API_LEVEL="${API_LEVEL}" \
-DANDROID_ABI="${ANDROID_ABI}" \
-DWITH_CUDA=ON -DWITH_OPENCL=ON \
$COMMON_CMAKE_OPTIONS \
-D WITH_ITT=OFF \
-DCMAKE_INSTALL_PREFIX=/opt/opencv-3.4.7_android/ .. && \
make -j16 && \
sudo make -j16 install && cp -rf ./3rdparty/ /opt/opencv-3.4.7_android/

# Set the variables to be used for actual app development/build
ENV ANDROID_SYSROOT "${ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/sysroot"
ENV ANDROID_PLATFORM "${API_LEVEL}"
ENV ANDROID_PLATFORM_TOOLS "${ANDROID_HOME}/platform-tools"
ENV PATH "${ANDROID_PLATFORM_TOOLS}:${PATH}"
ENV LD_LIBRARY_PATH "/usr/local/lib/:${LD_LIBRARY_PATH}"
12 changes: 12 additions & 0 deletions flutter/assets/icons/ic_task_stable_diffusion.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions flutter/assets/icons/ic_task_stable_diffusion_white.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion flutter/cpp/binary/cmdline.mk
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@

include flutter/cpp/binary/cmdline-docker.mk

cmdline/android/bins/release: cmdline/android/bins/build cmdline/android/bins/copy
cmdline/android/bins/release: cmdline/android/libs/deps cmdline/android/bins/build cmdline/android/bins/copy

.PHONY: cmdline/android/libs/deps
cmdline/android/libs/deps:
${backend_qti_libs_deps}

.PHONY: cmdline/android/bins/build
cmdline/android/bins/build:
Expand Down
21 changes: 12 additions & 9 deletions flutter/cpp/datasets/coco_gen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,20 @@ std::vector<uint8_t> CocoGen::ProcessOutput(const int sample_idx,
backend_->ConvertOutputs(total_byte, OUTPUT_WIDTH, OUTPUT_HEIGHT,
output_pixels.data());

std::string raw_output_filename =
raw_output_dir_ + "/output_" + std::to_string(sample_idx) + ".rgb8";
dump_output_pixels(output_pixels, raw_output_filename);

if (!output_pixels.empty()) {
sample_ids_.insert(sample_idx);
CaptionRecord* record = samples_.at(sample_idx).get();
LOG(INFO) << "caption: " << record->get_caption();
caption_map[sample_idx] = record->get_caption();
LOG(INFO) << "caption_id: " << record->get_caption_id()
<< " caption_text: " << record->get_caption_text();
caption_id_map[sample_idx] = record->get_caption_id();
caption_text_map[sample_idx] = record->get_caption_text();
output_pixels_map[sample_idx] = output_pixels;
attention_mask_map[sample_idx] = record->get_attention_mask_vector();
input_ids_map[sample_idx] = record->get_input_ids_vector();
std::string raw_output_filename = raw_output_dir_ + "/caption_id_" +
std::to_string(record->get_caption_id()) +
".rgb8";
dump_output_pixels(output_pixels, raw_output_filename);
return output_pixels;
} else {
return std::vector<uint8_t>();
Expand All @@ -130,7 +132,8 @@ float CocoGen::ComputeAccuracy() {
float total_score = 0.0f;
float total_samples = static_cast<float>(sample_ids_.size());
for (int sample_idx : sample_ids_) {
std::string caption = caption_map[sample_idx];
int caption_id = caption_id_map[sample_idx];
std::string caption_text = caption_text_map[sample_idx];
std::vector<int32_t> input_ids = input_ids_map[sample_idx];
std::vector<int32_t> attention_mask = attention_mask_map[sample_idx];
std::vector<uint8_t> output_pixels = output_pixels_map[sample_idx];
Expand All @@ -140,8 +143,8 @@ float CocoGen::ComputeAccuracy() {
}
float score =
score_predictor_.predict(attention_mask, input_ids, pixel_values);
LOG(INFO) << "sample_idx: " << sample_idx << " caption: " << caption
<< " score: " << score;
LOG(INFO) << "sample_idx: " << sample_idx << " caption_id: " << caption_id
<< " caption_text: " << caption_text << " score: " << score;
total_score += score;
}
float avg_score = total_score / total_samples;
Expand Down
3 changes: 2 additions & 1 deletion flutter/cpp/datasets/coco_gen.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ class CocoGen : public Dataset {
std::set<int> sample_ids_;
bool isModelFound;
std::string raw_output_dir_;
std::unordered_map<int, std::string> caption_map;
std::unordered_map<int, int> caption_id_map;
std::unordered_map<int, std::string> caption_text_map;
std::unordered_map<int, std::vector<uint8_t>> output_pixels_map;
std::unordered_map<int, std::vector<int32_t>> attention_mask_map;
std::unordered_map<int, std::vector<int32_t>> input_ids_map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"source": [
"SAVED_MODEL_DIR = './clip_model'\n",
"TFLITE_MODEL_PATH = './clip_model.tflite'\n",
"MODEL_NAME = \"openai/clip-vit-base-patch32\""
"MODEL_NAME = \"openai/clip-vit-large-patch14\""
],
"metadata": {
"id": "eOxB3zL_33tq"
Expand Down
5 changes: 4 additions & 1 deletion flutter/cpp/datasets/coco_gen_utils/generate_tfrecords.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ def download_image(url, file_path):
print(f"Downloaded image to {file_path}")


def serialize_example(caption, input_ids, attention_mask, file_name, clip_score):
def serialize_example(caption_id, caption, input_ids, attention_mask, file_name, clip_score):
"""Creates a tf.train.Example message ready to be written to a file."""
feature = {
'caption_id': tf.train.Feature(int64_list=tf.train.Int64List(value=caption_id)),
'caption': tf.train.Feature(bytes_list=tf.train.BytesList(value=[caption.encode()])),
'input_ids': tf.train.Feature(int64_list=tf.train.Int64List(value=input_ids)),
'attention_mask': tf.train.Feature(int64_list=tf.train.Int64List(value=attention_mask)),
Expand Down Expand Up @@ -87,6 +88,7 @@ def main():
with tf.io.TFRecordWriter(args.output_tfrecord, options='ZLIB') as writer:
total = len(df)
for idx, row in df.iterrows():
caption_id = row['id']
caption = row['caption']
file_name = row['file_name']
coco_url = row['coco_url']
Expand All @@ -104,6 +106,7 @@ def main():
clip_score = outputs.logits_per_image.numpy().flatten().tolist()

example = serialize_example(
caption_id=[int(caption_id)],
caption=caption,
input_ids=input_ids,
attention_mask=attention_mask,
Expand Down
Loading
Loading