forked from tensorflow/tfjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.ts
More file actions
332 lines (270 loc) · 9.15 KB
/
types.ts
File metadata and controls
332 lines (270 loc) · 9.15 KB
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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
/**
* @license
* Copyright 2019 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
/**
* =======================================================
* Old types used by the tjfs-core benchmarks.
* =======================================================
*/
export interface BenchmarkTest {
run(size: number, opType?: string, params?: {}): Promise<number>;
}
export interface BenchmarkModelTest extends BenchmarkTest {
loadModel(): void;
}
export interface BenchmarkLog {
averageTimeMs: number;
params: string;
}
/**
* =======================================================
* New types to be used by tfjs-layers and tfjs-node
* benchmarks.
*
* We plan to migrate the tfjs-core benchmarks to the new
* type system as well.
* =======================================================
*/
/**
* Interfaces that correspond to collections in Firestore Collections.
*/
export type VersionSetCollection = {
[versionSetId: string]: VersionSet
};
export type EnvironmentCollection = {
[environmentId: string]: EnvironmentInfo
};
/**
* Used by the dashboard front end to quickly retrieve a list
* of available benchmark tasks.
*
* New documents (rows) will be added to this collection (table) only when a
* new benchmark task (e.g., a new model, or a new function of an existing
* model) has been added. This is how a client frontend knows what models and
* function (and non-model tasks) are available in the database.
* Therefore, multiple runs of the same task will reuse the same document (row)
* in this collection (table).
*
* Note: this collection has redundant information with `BenchmarkRun` and
* `BenchmarkRunCollection`. It is essentially an index that speeds up queries
* for all available tasks. In principle, this collection can be recreated
* from `BenchmarkRunCollection` if necessary.
*/
export type TaskCollection = {
[taskId: string]: Task
};
/**
* A collection containing information about benchmarked models.
*
* Their versions and description.
*
* This applies to only model-based benchmarks and does not apply to
* non-model benchmarks.
*/
export type ModelCollection = {
[modelId: string]: Model
};
/** The collection that stores the actual benchmark results data. */
export type BenchmarkRunCollection = {
[benchmarkRunId: string]: BenchmarkRun
};
/** Version sets. */
export type CodeRepository =
'tfjs'|'tfjs-converter'|'tfjs-core'|'tfjs-data'|'tfjs-layers'|'tfjs-node';
export interface VersionSet {
commitHashes?: {[repo in CodeRepository]?: string};
versions?: {[repo in CodeRepository]?: string};
}
/** Environments. */
export type BrowserEnvironmentType =
'chrome-linux'|'chrome-mac'|'firefox-linux'|'firefox-mac'|'safari-mac'|
'chrome-windows'|'firefox-windows'|'chrome-ios-11'|'safari-ios-11';
export type NodeEnvironmentType =
'node-libtensorflow-cpu'|'node-libtensorflow-cuda'|'node-gles';
export type PythonEnvironmentType =
'python-tensorflow-cpu'|'python-tensorflow-cuda';
export type ServerSideEnvironmentType =
NodeEnvironmentType|PythonEnvironmentType;
export type BenchmarkEnvironmentType =
BrowserEnvironmentType|ServerSideEnvironmentType;
export interface EnvironmentInfo {
type: BenchmarkEnvironmentType;
/** `uname -a` output. */
systemInfo?: string;
/** `inxi` output. */
cpuInfo?: string;
/** Processed `free` output. */
memInfo?: string;
}
export interface BrowserEnvironmentInfo extends EnvironmentInfo {
type: BrowserEnvironmentType;
/** Browser `navigator.userAgent`. */
userAgent: string;
webGLVersion?: string;
}
export interface ServerSideEnvironmentInfo extends EnvironmentInfo {
type: ServerSideEnvironmentType;
/** Processed output from `nvidia-smi`. */
cudaGPUInfo?: string;
/** Output from `nvcc --version`. */
cudaVersion?: string;
}
export interface NodeEnvironmentInfo extends ServerSideEnvironmentInfo {
type: NodeEnvironmentType;
/** `node --version` output. */
nodeVersion: string;
tfjsNodeVersion?: string;
tfjsNodeUsesCUDA?: boolean;
}
export interface PythonEnvironmentInfo extends ServerSideEnvironmentInfo {
type: PythonEnvironmentType;
/** Output of `python --version`. */
pythonVersion?: string;
tensorflowVersion?: string;
kerasVersion?: string;
tensorflowUsesCUDA?: boolean;
}
/**
* Task types, names and function names under each task.
*
* If a task is performed in multiple environments (e.g., in tfjs-node and
* Python), they should correspond the same `Task` object.
*/
export interface Task {
taskType: TaskType;
/**
* Name of the task.
*
* For model-based tasks, this is the name of the model.
*/
taskName: string;
/**
* For model-based tasks, this is the function name, e.g.,
* predict(), fit(), fitDataset().
*/
functionName?: string;
}
export interface ModelTask extends Task {
/** A reference to Model in ModelCollection. */
modelId: string;
functionName: ModelFunctionName;
}
/** Information about a benchmarked model. */
export type ModelType =
'keras-model'|'tensorflow-model'|'tfjs-layers-model'|'tfjs-graph-model';
export interface Model {
type: ModelType;
name: string;
version: string;
description: string;
}
/** Benchmark tasks logs. */
// TODO(cais): Add new types in the future, such as low-level tensor
// operations, etc.
export type TaskType = 'model';
export type ModelFormat = 'LayersModel'|'GraphModel';
export type ModelFunctionName = 'predict'|'fit'|'fitDataset';
export type FunctionName = ModelFunctionName;
/**
* The results and related data from a benchmark run.
*
* A benchmark run is a full set of iterations that assess the performance
* of a specific task (see `Task` interface) in a given environment,
* under a given version / commit set. It includes a number of warm-up
* (a.k.a., burn-in) iterations, followed by a number of benchmarked
* iterations.
*
* See the doc strings below for what an iteration means in the context
* of Model.predict(), fit(), fitDataset() and non-model-based tasks.
*/
export interface BenchmarkRun {
versionSetId: string;
environmentId: string;
taskId: string;
taskType: TaskType;
functionName: string;
/**
* Number of burn-in (i.e., warm-up) iterations that take place prior to the
* benchmarked iterations.
*
* Follows the same convention as `numBenchmarkedIterations` for counting
* iterations.
*/
numWarmUpIterations: number;
/**
* Number of individual iterations that are timed.
*
* - For predict() and non-model-based tasks, this is the number of function
* calls.
* - For fit() and fitDatset(), this is the number of epochs of a single call.
*/
numBenchmarkedIterations: number;
/** The ending timestamp of the task, in milliseconds since epoch. */
endingTimestampMs: number;
/**
* Raw benchmarked run times in milliseconds.
*
* This field is optional because for certain types of benchmarks (e.g.,
* tf.LayersModel.fit() calls), the individual-iteration times are not
* available (e.g., cannot obtain epoch-by-epoch times without using
* a callback; but a callback affects the timing itself.)
* However, in cases where the individual-iteration times are available
* (e.g., tf.LayersModel.predict calls), it should be populated.
*
* - For predict() and non-model-based tasks, each item of the array is
* the wall time of a single predict() call or some other type of function
* call.
* - For fit() and fitDatset(), this field is not populated, due to the
* fact that obtaining per-epoch time requires a callback and that may
* affect the performance of the fit() / fitDataset() call.
*/
timesMs?: number[];
/**
* Arithmetic mean of `benchmarkedRunTimesMs`.
*
* - For predict() and non-model-based tasks, this is the arithmetic mean
* of `timeMs`.
* - For a fit() or fitDataset() task, this is the total time of the function
* call divided by the number of training epochs (i.e.,
* `numBenchmarkedIterations`).
*/
averageTimeMs: number;
}
export interface ModelBenchmarkRun extends BenchmarkRun {
taskType: 'model';
modelFormat: ModelFormat;
modelName: string;
functionName: ModelFunctionName;
batchSize: number;
}
export interface ModelTrainingBenchmarkRun extends ModelBenchmarkRun {
loss: string;
optimizer: string;
}
export interface TensorDef {
value: number[];
shape: number[];
dtype: 'string'|'float32'|'int32'|'bool'|'complex64';
}
export interface ValidationRun {
taskType: 'model';
modelFormat: ModelFormat;
modelName: string;
functionName: ModelFunctionName;
inputs: {[key: string]: TensorDef};
outputs: {[key: string]: TensorDef};
async: boolean;
}