Commit 12c3b65c authored by Jia's avatar Jia Committed by Commit Bot

[Power ML] Change UserActivityPrediction flag to enabled

Bug: 862461
Change-Id: I624d39293e50754629b3b30990828af73f57f0b3
Reviewed-on: https://chromium-review.googlesource.com/c/1482281Reviewed-by: default avatarDan Erat <derat@chromium.org>
Reviewed-by: default avatarSteven Holte <holte@chromium.org>
Commit-Queue: Jia Meng <jiameng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#634856}
parent c6cbbf4d
......@@ -222,25 +222,18 @@ void LogPowerMLSmartDimParameterResult(SmartDimParameterResult result) {
UMA_HISTOGRAM_ENUMERATION("PowerML.SmartDimParameter.Result", result);
}
// Returns "dim_threshold" from experiment parameter. Also logs status to UMA
// (i.e. whether the parameter is undefined or cannot be parsed, or can be
// parsed successfully.
base::Optional<float> GetDimThreshold() {
const std::string dim_threshold_str = base::GetFieldTrialParamValueByFeature(
features::kUserActivityPrediction, "dim_threshold");
if (dim_threshold_str.empty()) {
LogPowerMLSmartDimParameterResult(SmartDimParameterResult::kUndefinedError);
return base::nullopt;
}
double dim_threshold_double;
if (!base::StringToDouble(dim_threshold_str, &dim_threshold_double)) {
LogPowerMLSmartDimParameterResult(SmartDimParameterResult::kParsingError);
return base::nullopt;
// Returns "dim_threshold" from experiment parameter. Also logs status to UMA.
float GetDimThreshold() {
const double default_threshold = -0.18;
const double dim_threshold = base::GetFieldTrialParamByFeatureAsDouble(
features::kUserActivityPrediction, "dim_threshold", default_threshold);
if (std::abs(dim_threshold - default_threshold) < 1e-10) {
LogPowerMLSmartDimParameterResult(
SmartDimParameterResult::kUseDefaultValue);
} else {
LogPowerMLSmartDimParameterResult(SmartDimParameterResult::kSuccess);
}
LogPowerMLSmartDimParameterResult(SmartDimParameterResult::kSuccess);
return base::Optional<float>(dim_threshold_double);
return dim_threshold;
}
} // namespace
......@@ -322,12 +315,12 @@ SmartDimModelResult SmartDimModelImpl::CalculateInactivityScoreTfNative(
UserActivityEvent::ModelPrediction
SmartDimModelImpl::CreatePredictionFromInactivityScore(float inactivity_score) {
UserActivityEvent::ModelPrediction prediction;
const base::Optional<float> dim_threshold = GetDimThreshold();
const float dim_threshold = GetDimThreshold();
prediction.set_decision_threshold(ScoreToProbability(dim_threshold.value()));
prediction.set_decision_threshold(ScoreToProbability(dim_threshold));
prediction.set_inactivity_score(ScoreToProbability(inactivity_score));
if (inactivity_score >= dim_threshold.value()) {
if (inactivity_score >= dim_threshold) {
prediction.set_response(UserActivityEvent::ModelPrediction::DIM);
} else {
prediction.set_response(UserActivityEvent::ModelPrediction::NO_DIM);
......@@ -342,11 +335,6 @@ UserActivityEvent::ModelPrediction SmartDimModelImpl::ShouldDimTfNative(
UserActivityEvent::ModelPrediction prediction;
prediction.set_response(UserActivityEvent::ModelPrediction::MODEL_ERROR);
const base::Optional<float> dim_threshold = GetDimThreshold();
if (!dim_threshold) {
return prediction;
}
float inactivity_score = 0;
const SmartDimModelResult result =
CalculateInactivityScoreTfNative(input_features, &inactivity_score);
......@@ -368,12 +356,6 @@ void SmartDimModelImpl::ShouldDimMlService(
UserActivityEvent::ModelPrediction prediction;
prediction.set_response(UserActivityEvent::ModelPrediction::MODEL_ERROR);
const base::Optional<float> dim_threshold = GetDimThreshold();
if (!dim_threshold) {
std::move(callback).Run(prediction);
return;
}
std::vector<float> vectorized_features;
auto preprocess_result =
PreprocessInput(input_features, &vectorized_features);
......
......@@ -44,7 +44,8 @@ enum class SmartDimParameterResult {
kSuccess = 0,
kUndefinedError = 1,
kParsingError = 2,
kMaxValue = kParsingError
kUseDefaultValue = 3,
kMaxValue = kUseDefaultValue
};
// Real implementation of SmartDimModel that predicts whether an upcoming screen
......
......@@ -146,25 +146,6 @@ TEST_F(SmartDimModelImplTest, ShouldDim) {
EXPECT_TRUE(callback_done);
}
TEST_F(SmartDimModelImplTest, ModelError) {
// Model parameter is undefined, which would trigger a model error.
bool callback_done = false;
smart_dim_model_.RequestDimDecision(
features_, base::BindOnce(
[](bool* callback_done,
UserActivityEvent::ModelPrediction prediction) {
EXPECT_EQ(
UserActivityEvent::ModelPrediction::MODEL_ERROR,
prediction.response());
EXPECT_FALSE(prediction.has_decision_threshold());
EXPECT_FALSE(prediction.has_inactivity_score());
*callback_done = true;
},
&callback_done));
scoped_task_environment_.RunUntilIdle();
EXPECT_TRUE(callback_done);
}
// Check that CancelableCallback ensures a callback doesn't execute twice, in
// case two RequestDimDecision() calls were made before any callback ran.
TEST_F(SmartDimModelImplTest, CheckCancelableCallback) {
......
......@@ -80,7 +80,7 @@ const base::Feature kUseMessagesStagingUrl{"UseMessagesStagingUrl",
// Defined here rather than in //chrome alongside other related features so that
// PowerPolicyController can check it.
const base::Feature kUserActivityPrediction{"UserActivityPrediction",
base::FEATURE_DISABLED_BY_DEFAULT};
base::FEATURE_ENABLED_BY_DEFAULT};
// Enables or disables ML service inferencing (instead of TFNative inferencing)
// for the Smart Dim feature on Chrome OS.
......
......@@ -43316,6 +43316,10 @@ Called by update_net_trust_anchors.py.-->
<int value="2" label="Parsing error">
Threshold parameter was not parsed correctly from string to double.
</int>
<int value="3" label="Use default value">
Threshold parameter was not supplied or same as the default value. In either
case, the default value was used.
</int>
</enum>
<enum name="PowerSupplyType">
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