Commit 4aeed825 authored by Amanda Deacon's avatar Amanda Deacon Committed by Chromium LUCI CQ

Remove Top Cat inference code and references to tflite model.

Tests: unit tests

Bug: 1098112
Change-Id: Ia17ebf3407b4f9429b6b2ab006210b38a0d7fab1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2570878Reviewed-by: default avatarTony Yeoman <tby@chromium.org>
Reviewed-by: default avatarAndrew Moylan <amoylan@chromium.org>
Reviewed-by: default avatarSam McNally <sammc@chromium.org>
Reviewed-by: default avatarcalamity <calamity@chromium.org>
Commit-Queue: Amanda Deacon <amandadeacon@chromium.org>
Cr-Commit-Position: refs/heads/master@{#833595}
parent 790d98e7
......@@ -505,7 +505,6 @@
<if expr="chromeos">
<include name="IDR_SMART_DIM_20181115_EXAMPLE_PREPROCESSOR_CONFIG_PB" file="chromeos\power\ml\smart_dim\20181115_example_preprocessor_config.pb" type="BINDATA" />
<include name="IDR_SMART_DIM_20190521_EXAMPLE_PREPROCESSOR_CONFIG_PB" file="chromeos\power\ml\smart_dim\20190521_example_preprocessor_config.pb" type="BINDATA" />
<include name="IDR_TOP_CAT_20190722_EXAMPLE_PREPROCESSOR_CONFIG_PB" file="ui\app_list\search\search_result_ranker\20190722_example_preprocessor_config.pb" type="BINDATA" />
<include name="IDR_SEARCH_RANKER_20190923_EXAMPLE_PREPROCESSOR_CONFIG_PB" file="ui\app_list\search\search_result_ranker\search_ranker_assets\20190923_example_preprocessor_config.pb" type="BINDATA" />
</if>
<if expr="chromeos">
......
......@@ -1811,8 +1811,6 @@ static_library("ui") {
"app_list/search/search_result_ranker/frecency_store.h",
"app_list/search/search_result_ranker/histogram_util.cc",
"app_list/search/search_result_ranker/histogram_util.h",
"app_list/search/search_result_ranker/ml_app_rank_provider.cc",
"app_list/search/search_result_ranker/ml_app_rank_provider.h",
"app_list/search/search_result_ranker/ranking_item_util.cc",
"app_list/search/search_result_ranker/ranking_item_util.h",
"app_list/search/search_result_ranker/recurrence_predictor.cc",
......
......@@ -134,26 +134,6 @@ void AppLaunchEventLogger::OnGridClicked(const std::string& id) {
weak_factory_.GetWeakPtr(), event));
}
void AppLaunchEventLogger::CreateRankings() {
const base::TimeDelta duration = base::Time::Now() - start_time_;
if (!ml_app_rank_provider_) {
ml_app_rank_provider_ = std::make_unique<MlAppRankProvider>();
}
ml_app_rank_provider_->CreateRankings(
app_features_map_,
ExponentialBucket(duration.InHours(), kTotalHoursBucketSizeMultiplier),
Bucketize(all_clicks_last_hour_->GetTotal(duration), kClickBuckets),
Bucketize(all_clicks_last_24_hours_->GetTotal(duration), kClickBuckets));
}
std::map<std::string, float> AppLaunchEventLogger::RetrieveRankings() {
if (!ml_app_rank_provider_) {
return {};
}
return ml_app_rank_provider_->RetrieveRankings();
}
std::string AppLaunchEventLogger::RemoveScheme(const std::string& id) {
std::string app_id(id);
if (!app_id.compare(0, strlen(kExtensionSchemeWithDelimiter),
......
......@@ -15,7 +15,6 @@
#include "base/sequenced_task_runner.h"
#include "base/values.h"
#include "chrome/browser/ui/app_list/search/search_result_ranker/app_launch_event_logger.pb.h"
#include "chrome/browser/ui/app_list/search/search_result_ranker/ml_app_rank_provider.h"
#include "extensions/browser/extension_registry.h"
#include "services/metrics/public/cpp/ukm_source_id.h"
......@@ -154,9 +153,6 @@ class AppLaunchEventLogger {
const std::unique_ptr<chromeos::power::ml::RecentEventsCounter>
all_clicks_last_24_hours_;
// Empty until/unless CreateRankings is called.
std::unique_ptr<MlAppRankProvider> ml_app_rank_provider_;
scoped_refptr<base::SequencedTaskRunner> task_runner_;
base::WeakPtrFactory<AppLaunchEventLogger> weak_factory_;
......
// Copyright (c) 2019 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.
#ifndef CHROME_BROWSER_UI_APP_LIST_SEARCH_SEARCH_RESULT_RANKER_ML_APP_RANK_PROVIDER_H_
#define CHROME_BROWSER_UI_APP_LIST_SEARCH_SEARCH_RESULT_RANKER_ML_APP_RANK_PROVIDER_H_
#include <map>
#include <string>
#include <vector>
#include "base/containers/flat_map.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/optional.h"
#include "base/sequence_checker.h"
#include "base/sequenced_task_runner.h"
#include "chrome/browser/ui/app_list/search/search_result_ranker/app_launch_event_logger.pb.h"
#include "chromeos/services/machine_learning/public/mojom/graph_executor.mojom.h"
#include "chromeos/services/machine_learning/public/mojom/model.mojom.h"
#include "chromeos/services/machine_learning/public/mojom/tensor.mojom.h"
#include "components/assist_ranker/proto/example_preprocessor.pb.h"
#include "components/assist_ranker/proto/ranker_example.pb.h"
#include "mojo/public/cpp/bindings/remote.h"
namespace app_list {
// Creates a RankerExample with the given |features| and provided parameters.
// Calculates other features (ClicksEachHour, ClickPerHour, FourHourClicks,
// SixHourClicks). Converts the app id into the URL format used in the ML model.
assist_ranker::RankerExample CreateRankerExample(
const AppLaunchFeatures& features,
int time_since_last_click,
int total_hours,
int day_of_week,
int hour_of_day,
int all_clicks_last_hour,
int all_clicks_last_24_hours);
// Provide the app ranking using an ML model.
// Rankings are created asynchronously using the ML Service and retrieved
// synchronously at any time.
// Sequencing: Must be created and used on the same sequence (typically the UI
// thread).
class MlAppRankProvider {
public:
MlAppRankProvider();
~MlAppRankProvider();
// Asynchronously generates ranking scores for the apps in |app_features_map|.
void CreateRankings(
const base::flat_map<std::string, AppLaunchFeatures>& app_features_map,
int total_hours,
int all_clicks_last_hour,
int all_clicks_last_24_hours);
// Returns a map of the ranking scores keyed by app id.
// This will return an empty map until some time after the first call to
// CreateRankings().
std::map<std::string, float> RetrieveRankings();
private:
// Execute the |executor_| on the creation thread.
void RunExecutor(
base::flat_map<std::string,
::chromeos::machine_learning::mojom::TensorPtr> inputs,
std::vector<std::string> outputs,
std::string app_id);
// Stores the ranking score for an |app_id| in the |ranking_map_|.
// Executed by the ML Service when an Execute call is complete.
void ExecuteCallback(
std::string app_id,
::chromeos::machine_learning::mojom::ExecuteResult result,
base::Optional<
std::vector<::chromeos::machine_learning::mojom::TensorPtr>> outputs);
// Initializes the graph executor for the ML service if it's not already
// available.
void BindGraphExecutorIfNeeded();
void OnConnectionError();
// Remotes used to execute functions in the ML service server end.
mojo::Remote<::chromeos::machine_learning::mojom::Model> model_;
mojo::Remote<::chromeos::machine_learning::mojom::GraphExecutor> executor_;
// Map from app id to ranking score.
std::map<std::string, float> ranking_map_;
// Runner for tasks that should run on the creation sequence.
scoped_refptr<base::SequencedTaskRunner> creation_task_runner_;
// Runner for low priority background tasks.
scoped_refptr<base::SequencedTaskRunner> background_task_runner_;
// Sequence checker for methods that must run on the creation sequence.
SEQUENCE_CHECKER(creation_sequence_checker_);
base::WeakPtrFactory<MlAppRankProvider> weak_factory_{this};
DISALLOW_COPY_AND_ASSIGN(MlAppRankProvider);
};
} // namespace app_list
#endif // CHROME_BROWSER_UI_APP_LIST_SEARCH_SEARCH_RESULT_RANKER_ML_APP_RANK_PROVIDER_H_
// Copyright 2019 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 "chrome/browser/ui/app_list/search/search_result_ranker/ml_app_rank_provider.h"
#include <string>
#include "base/test/task_environment.h"
#include "chrome/browser/ui/app_list/search/search_result_ranker/app_launch_event_logger.pb.h"
#include "chromeos/services/machine_learning/public/cpp/fake_service_connection.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace app_list {
const char kAppId[] = "app_id";
TEST(MlAppRankProviderTest, MlInferenceTest) {
base::test::TaskEnvironment task_environment_;
chromeos::machine_learning::FakeServiceConnectionImpl fake_service_connection;
const double expected_value = 1.234;
fake_service_connection.SetOutputValue(std::vector<int64_t>{1L},
std::vector<double>{expected_value});
chromeos::machine_learning::ServiceConnection::
UseFakeServiceConnectionForTesting(&fake_service_connection);
MlAppRankProvider ml_app_rank_provider;
base::flat_map<std::string, AppLaunchFeatures> app_features_map;
AppLaunchFeatures features;
features.set_app_id(kAppId);
features.set_app_type(AppLaunchEvent_AppType_CHROME);
features.set_click_rank(1);
for (int hour = 0; hour < 24; ++hour) {
features.add_clicks_each_hour(1);
}
app_features_map[kAppId] = features;
ml_app_rank_provider.CreateRankings(app_features_map, 3, 1, 7);
EXPECT_EQ(0UL, ml_app_rank_provider.RetrieveRankings().size());
task_environment_.RunUntilIdle();
const std::map<std::string, float> ranking_map =
ml_app_rank_provider.RetrieveRankings();
task_environment_.RunUntilIdle();
ASSERT_EQ(1UL, ranking_map.size());
const auto it = ranking_map.find(kAppId);
ASSERT_NE(ranking_map.end(), it);
EXPECT_NEAR(expected_value, it->second, 0.001);
}
TEST(MlAppRankProviderTest, ExecutionAfterDestructorTest) {
base::test::TaskEnvironment task_environment_;
chromeos::machine_learning::FakeServiceConnectionImpl fake_service_connection;
const double expected_value = 1.234;
fake_service_connection.SetOutputValue(std::vector<int64_t>{1L},
std::vector<double>{expected_value});
chromeos::machine_learning::ServiceConnection::
UseFakeServiceConnectionForTesting(&fake_service_connection);
{
MlAppRankProvider ml_app_rank_provider;
base::flat_map<std::string, AppLaunchFeatures> app_features_map;
AppLaunchFeatures features;
features.set_app_id(kAppId);
features.set_app_type(AppLaunchEvent_AppType_CHROME);
app_features_map[kAppId] = features;
ml_app_rank_provider.CreateRankings(app_features_map, 3, 1, 7);
}
// Run the background tasks after ml_app_rank_provider has been destroyed.
// If this does not crash it is a success.
task_environment_.RunUntilIdle();
}
TEST(MlAppRankProviderTest, CreateRankerExampleTest) {
base::test::TaskEnvironment task_environment_;
MlAppRankProvider ml_app_rank_provider;
base::flat_map<std::string, AppLaunchFeatures> app_features_map;
AppLaunchFeatures features;
features.set_app_id(kAppId);
features.set_app_type(AppLaunchEvent_AppType_CHROME);
features.set_click_rank(1);
features.set_clicks_last_hour(3);
features.set_clicks_last_24_hours(4);
features.set_last_launched_from(AppLaunchEvent_LaunchedFrom_GRID);
features.set_most_recently_used_index(2);
features.set_total_clicks(100);
for (int hour = 0; hour < 24; ++hour) {
features.add_clicks_each_hour(hour + 10);
}
app_features_map[kAppId] = features;
assist_ranker::RankerExample actual =
CreateRankerExample(features, 120, 4, 3, 19, 7, 17);
auto* actual_feature_map(actual.mutable_features());
EXPECT_EQ(3, (*actual_feature_map)["DayOfWeek"].int32_value());
EXPECT_EQ(19, (*actual_feature_map)["HourOfDay"].int32_value());
EXPECT_EQ(7, (*actual_feature_map)["AllClicksLastHour"].int32_value());
EXPECT_EQ(17, (*actual_feature_map)["AllClicksLast24Hours"].int32_value());
EXPECT_EQ(1, (*actual_feature_map)["AppType"].int32_value());
EXPECT_EQ(1, (*actual_feature_map)["ClickRank"].int32_value());
EXPECT_EQ(3, (*actual_feature_map)["ClicksLastHour"].int32_value());
EXPECT_EQ(4, (*actual_feature_map)["ClicksLast24Hours"].int32_value());
EXPECT_EQ(1, (*actual_feature_map)["LastLaunchedFrom"].int32_value());
EXPECT_EQ(true, (*actual_feature_map)["HasClick"].bool_value());
EXPECT_EQ(2, (*actual_feature_map)["MostRecentlyUsedIndex"].int32_value());
EXPECT_EQ(120, (*actual_feature_map)["TimeSinceLastClick"].int32_value());
EXPECT_EQ(100, (*actual_feature_map)["TotalClicks"].int32_value());
EXPECT_NEAR(20.0, (*actual_feature_map)["TotalClicksPerHour"].float_value(),
0.1);
EXPECT_EQ(4, (*actual_feature_map)["TotalHours"].int32_value());
EXPECT_EQ(std::string("chrome-extension://") + kAppId,
(*actual_feature_map)["URL"].string_value());
EXPECT_EQ(10, (*actual_feature_map)["ClicksEachHour00"].int32_value());
EXPECT_EQ(11, (*actual_feature_map)["ClicksEachHour01"].int32_value());
EXPECT_EQ(19, (*actual_feature_map)["ClicksEachHour09"].int32_value());
EXPECT_EQ(20, (*actual_feature_map)["ClicksEachHour10"].int32_value());
// Bucketizing rounds 21-29 down to 20, 31-39 down to 30.
EXPECT_EQ(20, (*actual_feature_map)["ClicksEachHour11"].int32_value());
EXPECT_EQ(20, (*actual_feature_map)["ClicksEachHour19"].int32_value());
EXPECT_EQ(30, (*actual_feature_map)["ClicksEachHour20"].int32_value());
EXPECT_EQ(30, (*actual_feature_map)["ClicksEachHour23"].int32_value());
EXPECT_NEAR(2.0, (*actual_feature_map)["ClicksPerHour00"].float_value(), 0.1);
EXPECT_NEAR(2.2, (*actual_feature_map)["ClicksPerHour01"].float_value(), 0.1);
EXPECT_NEAR(6.0, (*actual_feature_map)["ClicksPerHour23"].float_value(), 0.1);
EXPECT_EQ(10 + 11 + 12 + 13,
(*actual_feature_map)["FourHourClicks0"].int32_value());
EXPECT_EQ(30 + 30 + 30 + 30,
(*actual_feature_map)["FourHourClicks5"].int32_value());
EXPECT_EQ(10 + 11 + 12 + 13 + 14 + 15,
(*actual_feature_map)["SixHourClicks0"].int32_value());
EXPECT_EQ(20 + 20 + 30 + 30 + 30 + 30,
(*actual_feature_map)["SixHourClicks3"].int32_value());
}
} // namespace app_list
......@@ -4996,7 +4996,6 @@ test("unit_tests") {
"../browser/ui/app_list/search/search_result_ranker/app_search_result_ranker_unittest.cc",
"../browser/ui/app_list/search/search_result_ranker/chip_ranker_unittest.cc",
"../browser/ui/app_list/search/search_result_ranker/frecency_store_unittest.cc",
"../browser/ui/app_list/search/search_result_ranker/ml_app_rank_provider_unittest.cc",
"../browser/ui/app_list/search/search_result_ranker/ranking_item_util_unittest.cc",
"../browser/ui/app_list/search/search_result_ranker/recurrence_predictor_unittest.cc",
"../browser/ui/app_list/search/search_result_ranker/recurrence_ranker_unittest.cc",
......
......@@ -34,7 +34,7 @@ enum BuiltinModelId {
// The Smart Dim (20190221) ML model.
SMART_DIM_20190221 = 3,
// The Top Cat (20190722) ML model.
TOP_CAT_20190722 = 4,
UNSUPPORTED_TOP_CAT_20190722 = 4,
// The Smart Dim (20190521) ML model.
SMART_DIM_20190521 = 5,
// The Search Ranker (20190923) ML model.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment