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

use time step embedding from file #928

Merged
merged 29 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
c78b889
feat: pass task-specific config to backend (#922)
anhappdev Oct 15, 2024
fad36c1
feat: add ConvertOutputs() API (#927)
anhappdev Oct 23, 2024
48cb33c
feat: timestamp-embedding-parser (WIP)
RSMNYS Oct 28, 2024
6d9bc91
disabled bitcode to be able compile with new XCode
RSMNYS Oct 28, 2024
fadee08
chore: formatting
RSMNYS Oct 28, 2024
1bddf37
refactor: use custom setting in Core ML backend to detect NCHW input.…
anhappdev Nov 12, 2024
463d974
fix: resolve crash due to permission denied on Android Play Store ver…
anhappdev Nov 12, 2024
e0f6813
chore: increase Android minSdkVersion from 21 to 30 (#859)
anhappdev Nov 19, 2024
1008c49
feat: finalized SD pipeline to use embedding from the binary file.
RSMNYS Dec 2, 2024
aba5d7d
Merge branch 'master' into features/timestamp-embedding-parser
RSMNYS Dec 2, 2024
8527f36
refactor: updated embedding_utils to parse pkl file
RSMNYS Dec 3, 2024
1cec8b3
chore: linting
RSMNYS Dec 3, 2024
47c54fa
fix: fixed lint issue in neuron
RSMNYS Dec 3, 2024
1c97942
chore: BUILD cleanup
RSMNYS Dec 3, 2024
4b67590
chore: cleanup
RSMNYS Dec 3, 2024
8eb4f4a
chore: ignore .fvm
RSMNYS Dec 6, 2024
0835157
chore: updated model paths and checksums for stable diffusion benchma…
RSMNYS Dec 6, 2024
b035768
chore: reverse timesteps and embeddings to support descending order o…
RSMNYS Dec 29, 2024
f2f132a
chore: fixed formatting
RSMNYS Dec 31, 2024
b7ad4ee
Merge branch 'submission-v4.1' into features/timestamp-embedding-parser
RSMNYS Jan 3, 2025
336bd76
chore: added links to the sd models and timestep embeddings file
RSMNYS Jan 3, 2025
f222a14
chore: add the proper name for the embedding_timesteps file
RSMNYS Jan 6, 2025
b14424e
chore: added missed declaration for backend_convert_outputs
RSMNYS Jan 6, 2025
3e5a5e2
chore: clang formatting
RSMNYS Jan 6, 2025
809b11d
chore: added missed files
RSMNYS Jan 7, 2025
ddedee4
chore: fixed build file for the pixel backend
RSMNYS Jan 7, 2025
3d58e5a
chore: bazel formatting
RSMNYS Jan 7, 2025
6170627
fix: added missed interface implementation for pixel
RSMNYS Jan 7, 2025
f29dccd
chore: clang formatting
RSMNYS Jan 7, 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
.ijwb
.idea
.vscode
.fvm
/bazel-*
/output
/output_logs
Expand Down
4 changes: 2 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
2 changes: 1 addition & 1 deletion flutter/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ android {

defaultConfig {
applicationId "org.mlcommons.android.mlperfbench"
minSdkVersion 21
minSdkVersion 30
targetSdkVersion 34
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
Expand Down
3 changes: 2 additions & 1 deletion flutter/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
android:maxSdkVersion="29"/>

<application android:label="MLPerf Mobile"
android:icon="@mipmap/ic_launcher">
android:icon="@mipmap/ic_launcher"
android:extractNativeLibs="true">

<!-- TFLite -->
<uses-library android:name="libOpenCL.so"
Expand Down
1 change: 1 addition & 0 deletions flutter/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
android.bundle.enableUncompressedNativeLibs=false
8 changes: 8 additions & 0 deletions flutter/assets/tasks.pbtxt
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,12 @@ task {
id: "stable_diffusion"
name: "StableDiffusion"
}
custom_config {
id: "stable_diffusion_seed"
value: "633994880"
}
custom_config {
id: "stable_diffusion_num_steps"
value: "20"
}
}
4 changes: 4 additions & 0 deletions flutter/cpp/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ class Backend {
virtual void ConvertInputs(int bytes, int image_width, int image_height,
uint8_t* data) = 0;

// Allow backend to do output layout change
virtual void ConvertOutputs(int bytes, int image_width, int image_height,
uint8_t* data) = 0;

private:
BackendSetting settings_;
};
Expand Down
4 changes: 3 additions & 1 deletion flutter/cpp/backends/external.cc
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ BackendFunctions::BackendFunctions(const std::string& lib_path) {
// Backends may need to change the format of the inputs (e.g. channel order)
convert_inputs = reinterpret_cast<decltype(convert_inputs)>(
CheckSymbol("mlperf_backend_convert_inputs"));

// Backends may need to change the format of the outputs (e.g. channel order)
convert_outputs = reinterpret_cast<decltype(convert_outputs)>(
CheckSymbol("mlperf_backend_convert_outputs"));
// If both functions are defined, then update
if (get_buffer && release_buffer) {
LOG(INFO) << "Using backend allocator";
Expand Down
12 changes: 12 additions & 0 deletions flutter/cpp/backends/external.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ struct BackendFunctions {
mlperf_backend_ptr_t, uint32_t, int32_t, void**)>::type;
using ConvertInputsPtr = std::add_pointer<void(mlperf_backend_ptr_t, int, int,
int, uint8_t*)>::type;
using ConvertOutputsPtr = std::add_pointer<void(mlperf_backend_ptr_t, int,
int, int, uint8_t*)>::type;

// Required functions.
BackendMatchesPtr match{nullptr};
Expand All @@ -91,6 +93,7 @@ struct BackendFunctions {
AllocatorMgr::GetBufferFn get_buffer{nullptr};
AllocatorMgr::ReleaseBufferFn release_buffer{nullptr};
ConvertInputsPtr convert_inputs{nullptr};
ConvertOutputsPtr convert_outputs{nullptr};

bool isLoaded() { return isloaded; }

Expand Down Expand Up @@ -210,6 +213,15 @@ class ExternalBackend : public Backend {
}
}

// Optional function to do output data re-formatting
void ConvertOutputs(int bytes, int width, int height,
uint8_t* data) override {
if (backend_functions_.convert_outputs) {
backend_functions_.convert_outputs(backend_ptr_, bytes, width, height,
data);
}
}

private:
std::string backend_name_;
std::string vendor_;
Expand Down
10 changes: 5 additions & 5 deletions flutter/cpp/binary/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ int Main(int argc, char *argv[]) {
command_line += " " + backend_name + " " + benchmark_id;

// Command Line Flags for mlperf.
std::string mode, scenario = "SingleStream", output_dir;
std::string mode, scenario = "SingleStream", output_dir, custom_config;
int min_query_count = 100, min_duration_ms = 100,
max_duration_ms = 10 * 60 * 1000,
single_stream_expected_latency_ns = 1000000;
Expand All @@ -157,8 +157,9 @@ int Main(int argc, char *argv[]) {
"A hint used by the loadgen to pre-generate "
"enough samples to meet the minimum test duration."),
Flag::CreateFlag("output_dir", &output_dir,
"The output directory of mlperf.", Flag::kRequired)});

"The output directory of mlperf.", Flag::kRequired),
Flag::CreateFlag("custom_config", &custom_config,
"Custom config in form key1:val1,key2:val2.")});
// Command Line Flags for backend.
std::unique_ptr<Backend> backend;
std::unique_ptr<Dataset> dataset;
Expand Down Expand Up @@ -207,9 +208,8 @@ int Main(int argc, char *argv[]) {
}
}
}

SettingList setting_list =
createSettingList(backend_setting, benchmark_id);
CreateSettingList(backend_setting, custom_config, benchmark_id);

ExternalBackend *external_backend = new ExternalBackend(
model_file_path, lib_path, setting_list, native_lib_path);
Expand Down
2 changes: 2 additions & 0 deletions flutter/cpp/c/backend_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ mlperf_status_t mlperf_backend_get_output(mlperf_backend_ptr_t backend_ptr,
// Optional functions
void mlperf_backend_convert_inputs(mlperf_backend_ptr_t backend_ptr, int bytes,
int width, int height, uint8_t* data);
void mlperf_backend_convert_outputs(mlperf_backend_ptr_t backend_ptr, int bytes,
int width, int height, uint8_t* data);

#ifdef __cplusplus
}
Expand Down
1 change: 1 addition & 0 deletions flutter/cpp/flutter/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ apple_xcframework(
},
minimum_os_versions = {
"ios": "13.1",
"macos": "13.1",
},
deps = [
"//flutter/cpp/flutter:bridge",
Expand Down
14 changes: 13 additions & 1 deletion flutter/cpp/proto/mlperf_task.proto
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ message MLPerfConfig {
// Config of the mlperf tasks.
// A task is basically a combination of models and a dataset.
//
// Next ID: 11
// Next ID: 12
message TaskConfig {
// Must be unique in one task file. Ex: image_classification
// used to match backend settings
Expand All @@ -52,6 +52,7 @@ message TaskConfig {
required string scenario = 7;
required DatasetConfig datasets = 8;
required ModelConfig model = 9;
repeated CustomConfig custom_config = 11;
}

// Datasets for a task
Expand Down Expand Up @@ -107,3 +108,14 @@ message ModelConfig {
// Number of detection classes if applicable
optional int32 num_classes = 6;
}

// CustomConfig are task specific configuration.
// The TaskConfig.CustomConfig will be converted to
// BenchmarkSetting.CustomSetting and passed to the backend.
// To avoid name collision, the id should be prefixed with TaskConfig.id.
message CustomConfig {
// Id of this config.
required string id = 1;
// Value of this config.
required string value = 2;
}
4 changes: 3 additions & 1 deletion flutter/cpp/proto/test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,11 @@ int test_proto() {
std::list<std::string> benchmarks;
benchmarks.push_back("image_classification");
benchmarks.push_back("image_classification_offline");
std::string custom_config = "key1:val1,key2:val2";
for (auto benchmark_id : benchmarks) {
// Convert to SettingList
SettingList setting_list = createSettingList(backend_setting, benchmark_id);
SettingList setting_list =
CreateSettingList(backend_setting, custom_config, benchmark_id);

std::cout << "SettingList for " << benchmark_id << ":\n";
dumpSettingList(setting_list);
Expand Down
91 changes: 85 additions & 6 deletions flutter/cpp/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,27 +125,106 @@ mlperf_backend_configuration_t CppToCSettings(const SettingList &settings) {
return c_settings;
}

SettingList createSettingList(const BackendSetting &backend_setting,
std::string benchmark_id) {
// Split the string by a given delimiter
std::vector<std::string> _splitString(const std::string &str, char delimiter) {
std::vector<std::string> tokens;
std::stringstream ss(str);
std::string token;
while (std::getline(ss, token, delimiter)) {
tokens.push_back(token);
}
return tokens;
}

// Parse the key:value string list
std::unordered_map<std::string, std::string> _parseKeyValueList(
const std::string &input) {
std::unordered_map<std::string, std::string> keyValueMap;
std::vector<std::string> pairs = _splitString(input, ','); // Split by comma

for (const std::string &pair : pairs) {
std::vector<std::string> keyValue =
_splitString(pair, ':'); // Split by colon
if (keyValue.size() == 2) {
keyValueMap[keyValue[0]] = keyValue[1];
} else {
LOG(ERROR) << "Invalid key:value pair: " << pair;
}
}
return keyValueMap;
}

// Create the setting list for backend
SettingList CreateSettingList(const BackendSetting &backend_setting,
const std::string &custom_config,
const std::string &benchmark_id) {
SettingList setting_list;
int setting_index = 0;

for (auto setting : backend_setting.common_setting()) {
for (const auto &setting : backend_setting.common_setting()) {
setting_list.add_setting();
(*setting_list.mutable_setting(setting_index)) = setting;
setting_index++;
}

// Copy the benchmark specific settings
setting_index = 0;
for (auto bm_setting : backend_setting.benchmark_setting()) {
for (const auto &bm_setting : backend_setting.benchmark_setting()) {
if (bm_setting.benchmark_id() == benchmark_id) {
setting_list.mutable_benchmark_setting()->CopyFrom(bm_setting);

auto parsed = _parseKeyValueList(custom_config);
for (const auto &kv : parsed) {
CustomSetting custom_setting = CustomSetting();
custom_setting.set_id(kv.first);
custom_setting.set_value(kv.second);
setting_list.mutable_benchmark_setting()->mutable_custom_setting()->Add(
std::move(custom_setting));
}
break;
}
}
LOG(INFO) << "setting_list:" << std::endl << setting_list.DebugString();
return setting_list;
}

template <typename T>
T GetConfigValue(mlperf_backend_configuration_t *configs, const char *key,
T defaultValue);

template <>
int GetConfigValue<int>(mlperf_backend_configuration_t *configs,
const char *key, int defaultValue) {
for (int i = 0; i < configs->count; ++i) {
if (strcmp(configs->keys[i], key) == 0) {
const char *valueStr = configs->values[i];
char *endptr = nullptr;
errno = 0;
long value =
strtol(valueStr, &endptr, 10); // Base 10 for decimal conversion
if (errno == ERANGE || value < INT_MIN || value > INT_MAX) {
LOG(ERROR) << "Value out of range for int: " << valueStr;
return defaultValue;
}
if (endptr == valueStr || *endptr != '\0') {
LOG(ERROR) << "Invalid value for int: " << valueStr;
return defaultValue;
}
return static_cast<int>(value);
}
}
return defaultValue;
}

template <>
std::string GetConfigValue<std::string>(mlperf_backend_configuration_t *configs,
const char *key,
std::string defaultValue) {
for (int i = 0; i < configs->count; ++i) {
if (strcmp(configs->keys[i], key) == 0) {
return std::string(configs->values[i]);
}
}
return defaultValue;
}

} // namespace mobile
} // namespace mlperf
9 changes: 7 additions & 2 deletions flutter/cpp/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,13 @@ void DeleteBackendConfiguration(mlperf_backend_configuration_t *configs);

mlperf_backend_configuration_t CppToCSettings(const SettingList &settings);

SettingList createSettingList(const BackendSetting &backend_setting,
std::string benchmark_id);
SettingList CreateSettingList(const BackendSetting &backend_setting,
const std::string &custom_config,
const std::string &benchmark_id);

template <typename T>
T GetConfigValue(mlperf_backend_configuration_t *configs, const char *key,
T defaultValue);

} // namespace mobile
} // namespace mlperf
Expand Down
5 changes: 5 additions & 0 deletions flutter/lib/benchmark/benchmark.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ class Benchmark {
setting: commonSettings,
benchmarkSetting: benchmarkSettings,
);
// Convert TaskConfig.CustomConfig to BenchmarkSetting.CustomSetting
final customConfigs = taskConfig.customConfig
.map((e) => pb.CustomSetting(id: e.id, value: e.value))
.toList();
benchmarkSettings.customSetting.addAll(customConfigs);
final uris = selectedDelegate.modelFile.map((e) => e.modelPath).toList();
final modelDirName = selectedDelegate.delegateName.replaceAll(' ', '_');
final backendModelPath =
Expand Down
1 change: 1 addition & 0 deletions mobile_back_apple/cpp/backend_coreml/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ apple_xcframework(
},
minimum_os_versions = {
"ios": "13.1",
"macos": "13.1",
},
deps = [
"//mobile_back_apple/cpp/backend_coreml:coreml_c",
Expand Down
Loading
Loading