summaryrefslogtreecommitdiff
path: root/chromium/components/optimization_guide/proto/models.proto
blob: dabc1cdb04ec749defcdd193ec3231e4b377600c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
// 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.

syntax = "proto2";
option optimize_for = LITE_RUNTIME;
option java_package = "org.chromium.components.optimization_guide.proto";
option java_outer_classname = "ModelsProto";

package optimization_guide.proto;

import "common_types.proto";

// A generic handle for any type of model.
message Model {
  reserved 3, 4;

  oneof model {
    DecisionTree decision_tree = 1;
    Ensemble ensemble = 2;
    // The URL that the model can be downloaded from.
    string download_url = 5;
  }
  // The tag number is high to allow models to be added and an uncommon number
  // in case the proto this is generated from adds a similar functionality.
  optional DoubleValue threshold = 123;
}

// An ensemble prediction model consisting of an ordered sequence of models.
// This message can be used to express bagged or boosted models.
message Ensemble {
  reserved 2, 3, 4;

  message Member { optional Model submodel = 1; }
  // The tag number is set by the proto this is generated from and cannot be
  // changed.
  repeated Member members = 100;
}

// A decision tree model with its weight for use if included in an ensemble.
message DecisionTree {
  reserved 2;

  repeated TreeNode nodes = 1;
  optional float weight = 3;
}

// A node of a decision tree that is a binary deicison or a leaf.
message TreeNode {
  reserved 6, 7;

  // Following fields are provided for convenience and better readability.
  // Filling them in is not required.
  optional Int32Value node_id = 1;
  optional Int32Value depth = 2;
  optional Int32Value subtree_size = 3;

  oneof node_type {
    BinaryNode binary_node = 4;
    Leaf leaf = 5;
  }
}

// A tree node that contains an inequality test that during evaluation
// determines whether to continue the left or right child.
message BinaryNode {
  reserved 3, 5;

  optional Int32Value left_child_id = 1;
  optional Int32Value right_child_id = 2;
  enum Direction {
    LEFT = 0;
    RIGHT = 1;
  }
  // When a datapoint satisfies the test, it should be propagated to the left
  // child.
  optional InequalityTest inequality_left_child_test = 4;
}

// Vector of values for use within Models.
message Vector {
  repeated Value value = 1;
}

// A leaf node of a decision tree.
message Leaf {
  reserved 2, 3;

  optional Vector vector = 1;
}

// The ID for the features used during evaluation of a Model.
message FeatureId {
  reserved 2;

  optional StringValue id = 1;
}

// The set of inequality operations supported by binary nodes for
// decision tree models.
message InequalityTest {
  reserved 4;

  // When the feature is missing, the test's outcome is undefined.
  optional FeatureId feature_id = 1;
  enum Type {
    LESS_OR_EQUAL = 0;
    LESS_THAN = 1;
    GREATER_OR_EQUAL = 2;
    GREATER_THAN = 3;
  };
  optional Type type = 2;
  optional Value threshold = 3;
}

// Represents a single value of any type, e.g. 5 or "abc".
message Value {
  reserved 5;

  oneof value {
    float float_value = 1;
    double double_value = 2;
    int32 int32_value = 3;
    int64 int64_value = 4;
  }
}

// Wrapper message for `int32`.
//
// The JSON representation for `Int32Value` is JSON number.
message Int32Value {
  // The int32 value.
  optional int32 value = 1;
}

// Wrapper message for `string`.
//
// The JSON representation for `StringValue` is JSON string.
message StringValue {
  // The string value.
  optional string value = 1;
}

// Wrapper message for `double`.
//
// The JSON representation for `DoubleValue` is JSON number.
message DoubleValue {
  // The double value.
  optional double value = 1;
}

// Requests prediction models to be used for a set of optimization targets.
message GetModelsRequest {
  // Information about the requested models.
  repeated ModelInfo requested_models = 1;
  // The set of hosts to get additional metadata for, if applicable.
  repeated string hosts = 2;
  // Context in which this request is made.
  //
  // If the context matches one that requires more urgency (i.e.
  // CONTEXT_PAGE_NAVIGATION), then no model updates will be returned for the
  // requested models.
  optional RequestContext request_context = 3;
  // The field trials that are currently active when this request is made.
  repeated FieldTrial active_field_trials = 4;
}

// Response to the GetModels request.
message GetModelsResponse {
  // The models to be used during prediction for the requested optimization
  // targets.
  repeated PredictionModel models = 1;
  // A set of model features and their values for the hosts contained in the
  // request to be expected to be consulted with during prediction.
  //
  // It is not guaranteed that this set will contain an entry for every
  // requested host.
  repeated HostModelFeatures host_model_features = 2;
}

// Holds the prediction model for a particular optimization target.
message PredictionModel {
  // Information about the model.
  optional ModelInfo model_info = 1;
  // The model to evaluate for the attached model information.
  //
  // This will only be set if the model that the client claims it has is stale.
  // It is also guaranteed that the value populated as part of this field is one
  // that the client claims to support based on the request's client model
  // capabilities.
  optional Model model = 2;
}

//  Metadata for a prediction model for a specific optimization target.
message ModelInfo {
  // The optimization target for which the model predicts.
  optional OptimizationTarget optimization_target = 1;
  // The version of the model, which is specific to the optimization target.
  optional int64 version = 2;
  // The set of model features that are supported by the model.
  //
  // If in the request, this represents the set of features that the client
  // understands how to evaluate. If in the response, this represents the set
  // of features referenced by the model.
  repeated ClientModelFeature supported_model_features = 3;
  // The set of model types the requesting client can use to make predictions.
  repeated ModelType supported_model_types = 4;
  // The set of host model features that are referenced by the model.
  //
  // Note that this should only be populated if part of the response.
  repeated string supported_host_model_features = 5;
}

// The scenarios for which the optimization guide has models for.
enum OptimizationTarget {
  OPTIMIZATION_TARGET_UNKNOWN = 0;
  // Should only be applied when the page load is predicted to be painful.
  OPTIMIZATION_TARGET_PAINFUL_PAGE_LOAD = 1;
}

// The features that only the client can compute during prediction and also
// knows how to evaluate.
enum ClientModelFeature {
  CLIENT_MODEL_FEATURE_UNKNOWN = 0;
  // The effective connection type for the page load.
  CLIENT_MODEL_FEATURE_EFFECTIVE_CONNECTION_TYPE = 1;
  // How the current page load transitioned from the previous one.
  CLIENT_MODEL_FEATURE_PAGE_TRANSITION = 2;
  // The site engagement score of the main frame host for the page load.
  CLIENT_MODEL_FEATURE_SITE_ENGAGEMENT_SCORE = 3;
  // Whether the origin for the page load matches the origin of the previous
  // page load.
  CLIENT_MODEL_FEATURE_SAME_ORIGIN_NAVIGATION = 4;
  // The mean of the duration from navigation to first contentful paint for the
  // session.
  CLIENT_MODEL_FEATURE_FIRST_CONTENTFUL_PAINT_SESSION_MEAN = 5;
  // The standard deviation of the duration from navigation to first
  // contentful paint for the session.
  CLIENT_MODEL_FEATURE_FIRST_CONTENTFUL_PAINT_SESSION_STANDARD_DEVIATION = 6;
  // The duration from navigation to first contentful paint for the previous
  // page load, if applicable.
  CLIENT_MODEL_FEATURE_FIRST_CONTENTFUL_PAINT_PREVIOUS_PAGE_LOAD = 7;
}

// The types of models that can be evaluated.
enum ModelType {
  MODEL_TYPE_UNKNOWN = 0;
  // A decision tree.
  MODEL_TYPE_DECISION_TREE = 1;
}

// A set of model features and the host that it applies to.
message HostModelFeatures {
  // The host that the features should be applied for.
  optional string host = 1;
  // The set of features and their values that apply to the host.
  repeated ModelFeature model_features = 2;
}

// Information about a feature that is potentially referenced in a model.
message ModelFeature {
  // The name of the feature to match if encountered in a model.
  optional string feature_name = 1;
  // The value of the feature to be used during prediction.
  oneof feature_value {
    double double_value = 2;
    int64 int64_value = 3;
  }
}