android_webview
apps
ash
base
build
build_overrides
buildtools
cc
chrome
chromecast
chromeos
cloud_print
components
about_ui
account_id
android_system_error_page
apdu
arc
assist_ranker
autofill
autofill_assistant
autofill_payments_strings_grdp
autofill_strings_grdp
background_task_scheduler
base32
blocked_content
blocklist
bookmark_bar_strings_grdp
bookmarks
browser_sync
browser_ui
browser_watcher
browsing_data
browsing_data_strings_grdp
captive_portal
cast
cast_certificate
cast_channel
cbor
cdm
certificate_matching
certificate_transparency
chrome_cleaner
chromeos_camera
client_hints
client_update_protocol
cloud_devices
component_updater
components_strings_grd
consent_auditor
constrained_window
content_capture
content_settings
contextual_search
cookie_config
country_codes
crash
crash_strings_grdp
cronet
crx_file
data_reduction_proxy
data_use_measurement
database_utils
dbus
device_event_log
discardable_memory
dom_distiller
dom_distiller_strings_grdp
domain_reliability
download
drive
embedder_support
encrypted_messages
enterprise
error_page
error_page_strings_grdp
exo
external_intents
favicon
favicon_base
feature_engagement
federated_learning
feed
feedback
filename_generation
find_in_page
flags_ui
games
gcm_driver
google
grpc_support
guest_os
guest_view
gwp_asan
handoff
heap_profiling
history
image_fetcher
infobars
invalidation
javascript_dialogs
javascript_dialogs_strings_grdp
js_injection
keep_alive_registry
keyed_service
language
language_usage_metrics
leveldb_proto
link_header_util
location
login
lookalikes
management
management_ios_strings_grdp
management_strings_grdp
media_control
media_message_center
media_router
messages
metal_util
metrics
metrics_services_manager
minidump_uploader
mirroring
module_installer
nacl
navigation_interception
navigation_metrics
net_log
neterror
network_hints
network_session_configurator
network_time
new_or_sad_tab_strings_grdp
ntp_snippets
ntp_snippets_strings_grdp
ntp_tiles
offline_items_collection
offline_pages
omnibox
omnibox_strings_grdp
on_load_script_injector
onc
open_from_clipboard
openscreen_platform
optimization_guide
proto
BUILD.gn
DEPS
OWNERS
README.md
bloom_filter.cc
bloom_filter.h
bloom_filter_unittest.cc
command_line_top_host_provider.cc
command_line_top_host_provider.h
command_line_top_host_provider_unittest.cc
decision_tree_prediction_model.cc
decision_tree_prediction_model.h
decision_tree_prediction_model_unittest.cc
hint_cache.cc
hint_cache.h
hint_cache_unittest.cc
hints_component_info.h
hints_component_util.cc
hints_component_util.h
hints_component_util_unittest.cc
hints_fetcher.cc
hints_fetcher.h
hints_fetcher_factory.cc
hints_fetcher_factory.h
hints_fetcher_unittest.cc
hints_processing_util.cc
hints_processing_util.h
hints_processing_util_unittest.cc
memory_hint.cc
memory_hint.h
optimization_filter.cc
optimization_filter.h
optimization_filter_unittest.cc
optimization_guide_constants.cc
optimization_guide_constants.h
optimization_guide_decider.h
optimization_guide_enums.h
optimization_guide_features.cc
optimization_guide_features.h
optimization_guide_features_unittest.cc
optimization_guide_prefs.cc
optimization_guide_prefs.h
optimization_guide_service.cc
optimization_guide_service.h
optimization_guide_service_observer.h
optimization_guide_service_unittest.cc
optimization_guide_store.cc
optimization_guide_store.h
optimization_guide_store_unittest.cc
optimization_guide_switches.cc
optimization_guide_switches.h
optimization_guide_switches_unittest.cc
optimization_guide_test_util.cc
optimization_guide_test_util.h
optimization_guide_util.cc
optimization_guide_util.h
optimization_metadata.cc
optimization_metadata.h
optimization_metadata_unittest.cc
prediction_model.cc
prediction_model.h
prediction_model_unittest.cc
proto_database_provider_test_base.cc
proto_database_provider_test_base.h
store_update_data.cc
store_update_data.h
store_update_data_unittest.cc
test_hints_component_creator.cc
test_hints_component_creator.h
test_optimization_guide_decider.cc
test_optimization_guide_decider.h
top_host_provider.h
url_pattern_with_wildcards.cc
url_pattern_with_wildcards.h
url_pattern_with_wildcards_unittest.cc
os_crypt
ownership
page_image_annotation
page_info
page_info_strings_grdp
page_load_metrics
paint_preview
password_manager
password_manager_strings_grdp
payments
payments_strings_grdp
pdf
pdf_strings_grdp
performance_manager
permissions
permissions_strings_grdp
plugins
policy
policy_strings_grdp
pref_registry
prefs
prerender
previews
printing
printing_component_strings_grdp
profile_metrics
proxy_config
pwg_encoder
query_parser
query_tiles
quirks
rappor
reading_list
remote_cocoa
renderer_context_menu
reset_password_strings_grdp
resources
rlz
safe_browsing
safe_search_api
safety_check
scheduling_metrics
schema_org
search
search_engines
search_provider_logos
security_interstitials
security_interstitials_strings_grdp
security_state
security_state_strings_grdp
send_tab_to_self
send_tab_to_self_strings_grdp
services
session_manager
sessions
signin
site_isolation
sms_strings_grdp
soda
speech
spellcheck
sqlite_proto
ssl_errors
ssl_errors_strings_grdp
startup_metric_utils
storage_monitor
strictmode
strings
subresource_filter
suggestions
sync
sync_bookmarks
sync_device_info
sync_preferences
sync_sessions
sync_ui_strings_grdp
sync_user_events
system_media_controls
tab_count_metrics
tab_groups
tab_groups_strings_grdp
test
thin_webview
timers
tracing
translate
translate_strings_grdp
ui_devtools
ui_metrics
ukm
undo
undo_strings_grdp
unified_consent
update_client
upload_list
url_formatter
url_matcher
url_pattern_index
user_actions_ui
user_manager
user_prefs
variations
vector_icons
version_info
version_ui
version_ui_strings_grdp
visitedlink
viz
web_cache
web_modal
web_package
web_resource
webapk
webcrypto
webdata
webdata_services
webrtc
webrtc_logging
wifi
zoom
zucchini
.eslintrc.js
BUILD.gn
DEPS
OWNERS
PRESUBMIT.py
README.md
android_system_error_page_strings.grdp
autofill_assistant_strings.grdp
autofill_payments_strings.grdp
autofill_strings.grdp
blocked_content_strings.grdp
bookmark_bar_strings.grdp
bookmark_component_strings.grdp
browsing_data_strings.grdp
components_chromium_strings.grd
components_google_chrome_strings.grd
components_locale_settings.grd
components_settings_strings.grdp
components_strings.grd
crash_strings.grdp
dialog_strings.grdp
dom_distiller_strings.grdp
error_page_strings.grdp
find_in_page_strings.grdp
flags_strings.grdp
history_strings.grdp
javascript_dialogs_strings.grdp
login_dialog_strings.grdp
management_ios_strings.grdp
management_strings.grdp
media_message_center_strings.grdp
new_or_sad_tab_strings.grdp
ntp_snippets_strings.grdp
omnibox_strings.grdp
page_info_strings.grdp
paint_preview_strings.grdp
password_manager_strings.grdp
payments_strings.grdp
pdf_strings.grdp
permissions_strings.grdp
policy_strings.grdp
print_media_strings.grdp
printing_component_strings.grdp
reset_password_strings.grdp
safe_browsing_strings.grdp
security_interstitials_strings.grdp
security_state_strings.grdp
send_tab_to_self_strings.grdp
sms_strings.grdp
ssl_errors_strings.grdp
sync_ui_strings.grdp
tab_groups_strings.grdp
translate_strings.grdp
typemaps.gni
undo_strings.grdp
version_ui_strings.grdp
content
courgette
crypto
dbus
device
docs
extensions
fuchsia
gin
google_apis
google_update
gpu
headless
infra
ios
ipc
jingle
media
mojo
native_client_sdk
net
pdf
ppapi
printing
remoting
rlz
sandbox
services
skia
sql
storage
styleguide
testing
third_party
tools
ui
url
weblayer
.clang-format
.clang-tidy
.eslintrc.js
.git-blame-ignore-revs
.gitattributes
.gitignore
.gn
.vpython
.vpython3
.yapfignore
AUTHORS
BUILD.gn
CODE_OF_CONDUCT.md
DEPS
DIR_METADATA
ENG_REVIEW_OWNERS
LICENSE
LICENSE.chromium_os
OWNERS
PRESUBMIT.py
PRESUBMIT_test.py
PRESUBMIT_test_mocks.py
README.md
WATCHLISTS
codereview.settings

This will share the evaluation code of the decision tree model to support out-of-process evaluations in the Chrome ML Service. Bug: 1102420 Change-Id: Idbefa68ce125f8f9d6b63469154dbe20c1bce67a Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2282948 Commit-Queue: Jia Li <jiakl@google.com> Auto-Submit: Jia Li <jiakl@google.com> Reviewed-by: Sophie Chang <sophiechang@chromium.org> Reviewed-by: Michael Crouse <mcrouse@chromium.org> Cr-Commit-Position: refs/heads/master@{#785521}
175 lines
6.5 KiB
C++
175 lines
6.5 KiB
C++
// Copyright 2020 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "components/optimization_guide/prediction_model.h"
|
|
|
|
#include <utility>
|
|
|
|
#include "components/optimization_guide/proto/models.pb.h"
|
|
#include "testing/gtest/include/gtest/gtest.h"
|
|
|
|
namespace optimization_guide {
|
|
|
|
TEST(PredictionModelTest, ValidPredictionModel) {
|
|
std::unique_ptr<proto::PredictionModel> prediction_model =
|
|
std::make_unique<proto::PredictionModel>();
|
|
prediction_model->mutable_model()->mutable_threshold()->set_value(5.0);
|
|
|
|
proto::DecisionTree decision_tree_model = proto::DecisionTree();
|
|
decision_tree_model.set_weight(2.0);
|
|
|
|
proto::TreeNode* tree_node = decision_tree_model.add_nodes();
|
|
tree_node->mutable_node_id()->set_value(0);
|
|
tree_node->mutable_binary_node()->mutable_left_child_id()->set_value(1);
|
|
tree_node->mutable_binary_node()->mutable_right_child_id()->set_value(2);
|
|
tree_node->mutable_binary_node()
|
|
->mutable_inequality_left_child_test()
|
|
->mutable_feature_id()
|
|
->mutable_id()
|
|
->set_value("agg1");
|
|
tree_node->mutable_binary_node()
|
|
->mutable_inequality_left_child_test()
|
|
->set_type(proto::InequalityTest::LESS_OR_EQUAL);
|
|
tree_node->mutable_binary_node()
|
|
->mutable_inequality_left_child_test()
|
|
->mutable_threshold()
|
|
->set_float_value(1.0);
|
|
|
|
tree_node = decision_tree_model.add_nodes();
|
|
tree_node->mutable_node_id()->set_value(1);
|
|
tree_node->mutable_leaf()->mutable_vector()->add_value()->set_double_value(
|
|
2.);
|
|
|
|
tree_node = decision_tree_model.add_nodes();
|
|
tree_node->mutable_node_id()->set_value(2);
|
|
tree_node->mutable_leaf()->mutable_vector()->add_value()->set_double_value(
|
|
4.);
|
|
|
|
*prediction_model->mutable_model()->mutable_decision_tree() =
|
|
decision_tree_model;
|
|
|
|
optimization_guide::proto::ModelInfo* model_info =
|
|
prediction_model->mutable_model_info();
|
|
model_info->set_version(1);
|
|
model_info->add_supported_model_types(
|
|
optimization_guide::proto::ModelType::MODEL_TYPE_DECISION_TREE);
|
|
model_info->add_supported_model_features(
|
|
optimization_guide::proto::ClientModelFeature::
|
|
CLIENT_MODEL_FEATURE_EFFECTIVE_CONNECTION_TYPE);
|
|
model_info->add_supported_host_model_features("agg1");
|
|
|
|
std::unique_ptr<PredictionModel> model =
|
|
PredictionModel::Create(std::move(prediction_model));
|
|
|
|
EXPECT_EQ(1, model->GetVersion());
|
|
EXPECT_EQ(2u, model->GetModelFeatures().size());
|
|
EXPECT_TRUE(model->GetModelFeatures().count("agg1"));
|
|
EXPECT_TRUE(model->GetModelFeatures().count(
|
|
"CLIENT_MODEL_FEATURE_EFFECTIVE_CONNECTION_TYPE"));
|
|
}
|
|
|
|
TEST(PredictionModelTest, NoModel) {
|
|
std::unique_ptr<optimization_guide::proto::PredictionModel> prediction_model =
|
|
std::make_unique<optimization_guide::proto::PredictionModel>();
|
|
|
|
std::unique_ptr<PredictionModel> model =
|
|
PredictionModel::Create(std::move(prediction_model));
|
|
EXPECT_FALSE(model);
|
|
}
|
|
|
|
TEST(PredictionModelTest, NoModelVersion) {
|
|
std::unique_ptr<optimization_guide::proto::PredictionModel> prediction_model =
|
|
std::make_unique<optimization_guide::proto::PredictionModel>();
|
|
|
|
optimization_guide::proto::DecisionTree* decision_tree_model =
|
|
prediction_model->mutable_model()->mutable_decision_tree();
|
|
decision_tree_model->set_weight(2.0);
|
|
|
|
std::unique_ptr<PredictionModel> model =
|
|
PredictionModel::Create(std::move(prediction_model));
|
|
EXPECT_FALSE(model);
|
|
}
|
|
|
|
TEST(PredictionModelTest, NoModelType) {
|
|
std::unique_ptr<optimization_guide::proto::PredictionModel> prediction_model =
|
|
std::make_unique<optimization_guide::proto::PredictionModel>();
|
|
|
|
optimization_guide::proto::DecisionTree* decision_tree_model =
|
|
prediction_model->mutable_model()->mutable_decision_tree();
|
|
decision_tree_model->set_weight(2.0);
|
|
|
|
optimization_guide::proto::ModelInfo* model_info =
|
|
prediction_model->mutable_model_info();
|
|
model_info->set_version(1);
|
|
|
|
std::unique_ptr<PredictionModel> model =
|
|
PredictionModel::Create(std::move(prediction_model));
|
|
EXPECT_FALSE(model);
|
|
}
|
|
|
|
TEST(PredictionModelTest, UnknownModelType) {
|
|
std::unique_ptr<optimization_guide::proto::PredictionModel> prediction_model =
|
|
std::make_unique<optimization_guide::proto::PredictionModel>();
|
|
|
|
optimization_guide::proto::DecisionTree* decision_tree_model =
|
|
prediction_model->mutable_model()->mutable_decision_tree();
|
|
decision_tree_model->set_weight(2.0);
|
|
|
|
optimization_guide::proto::ModelInfo* model_info =
|
|
prediction_model->mutable_model_info();
|
|
model_info->set_version(1);
|
|
model_info->add_supported_model_types(
|
|
optimization_guide::proto::ModelType::MODEL_TYPE_UNKNOWN);
|
|
|
|
std::unique_ptr<PredictionModel> model =
|
|
PredictionModel::Create(std::move(prediction_model));
|
|
EXPECT_FALSE(model);
|
|
}
|
|
|
|
TEST(PredictionModelTest, MultipleModelTypes) {
|
|
std::unique_ptr<optimization_guide::proto::PredictionModel> prediction_model =
|
|
std::make_unique<optimization_guide::proto::PredictionModel>();
|
|
|
|
optimization_guide::proto::DecisionTree* decision_tree_model =
|
|
prediction_model->mutable_model()->mutable_decision_tree();
|
|
decision_tree_model->set_weight(2.0);
|
|
|
|
optimization_guide::proto::ModelInfo* model_info =
|
|
prediction_model->mutable_model_info();
|
|
model_info->set_version(1);
|
|
model_info->add_supported_model_types(
|
|
optimization_guide::proto::ModelType::MODEL_TYPE_DECISION_TREE);
|
|
model_info->add_supported_model_types(
|
|
optimization_guide::proto::ModelType::MODEL_TYPE_UNKNOWN);
|
|
|
|
std::unique_ptr<PredictionModel> model =
|
|
PredictionModel::Create(std::move(prediction_model));
|
|
EXPECT_FALSE(model);
|
|
}
|
|
|
|
TEST(PredictionModelTest, UnknownModelClientFeature) {
|
|
std::unique_ptr<optimization_guide::proto::PredictionModel> prediction_model =
|
|
std::make_unique<optimization_guide::proto::PredictionModel>();
|
|
|
|
optimization_guide::proto::DecisionTree* decision_tree_model =
|
|
prediction_model->mutable_model()->mutable_decision_tree();
|
|
decision_tree_model->set_weight(2.0);
|
|
|
|
optimization_guide::proto::ModelInfo* model_info =
|
|
prediction_model->mutable_model_info();
|
|
model_info->set_version(1);
|
|
model_info->add_supported_model_types(
|
|
optimization_guide::proto::ModelType::MODEL_TYPE_DECISION_TREE);
|
|
|
|
model_info->add_supported_model_features(
|
|
optimization_guide::proto::ClientModelFeature::
|
|
CLIENT_MODEL_FEATURE_UNKNOWN);
|
|
|
|
std::unique_ptr<PredictionModel> model =
|
|
PredictionModel::Create(std::move(prediction_model));
|
|
EXPECT_FALSE(model);
|
|
}
|
|
|
|
} // namespace optimization_guide
|