ml: Treat a model as supported if it has metadata
Previously ML Service checks for the validity of a ModelId by checking
if the enum value is out-of-range. We expect to remove support from
models over time (including the current Smart Dim model soon). Therefore
the range check is not correct. This CL changes the definition of
"supported" model to be "has a ModelMetadata" entry.
We also document that models that become unsupported should have their
names prefixed with UNSUPPORTED_. The UNKNOWN model previously used as a
default value and for range checking purposes becomes UNSUPPORTED_ in
this way.
TEST=ebuild clean test
BUG=chromium:937063
Change-Id: I529119d4b56767326d8bb0594a9719ec53db9df7
Reviewed-on: https://chromium-review.googlesource.com/1614831
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Andrew Moylan <amoylan@chromium.org>
Reviewed-by: Michael Martis <martis@chromium.org>
Reviewed-by: Sam McNally <sammc@chromium.org>
diff --git a/ml/machine_learning_service_impl.cc b/ml/machine_learning_service_impl.cc
index 8247db1..4f57f58 100644
--- a/ml/machine_learning_service_impl.cc
+++ b/ml/machine_learning_service_impl.cc
@@ -56,19 +56,14 @@
const LoadModelCallback& callback) {
RequestMetrics<LoadModelResult> request_metrics(kMetricsNameBase);
request_metrics.StartRecordingPerformanceMetrics();
- if (spec->id <= ModelId::UNKNOWN || spec->id > ModelId::kMax) {
- callback.Run(LoadModelResult::MODEL_SPEC_ERROR);
- request_metrics.RecordRequestEvent(LoadModelResult::MODEL_SPEC_ERROR);
- return;
- }
- // Shouldn't happen (as we maintain a metadata entry for every valid model),
- // but can't hurt to be defensive.
+ // Unsupported models do not have metadata entries.
const auto metadata_lookup = model_metadata_.find(spec->id);
if (metadata_lookup == model_metadata_.end()) {
- LOG(ERROR) << "No metadata present for model ID " << spec->id << ".";
- callback.Run(LoadModelResult::LOAD_MODEL_ERROR);
- request_metrics.RecordRequestEvent(LoadModelResult::LOAD_MODEL_ERROR);
+ LOG(WARNING) << "LoadModel requested for unsupported model ID " << spec->id
+ << ".";
+ callback.Run(LoadModelResult::MODEL_SPEC_ERROR);
+ request_metrics.RecordRequestEvent(LoadModelResult::MODEL_SPEC_ERROR);
return;
}
const ModelMetadata& metadata = metadata_lookup->second;