forked from robertknight/rten
-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema.fbs
618 lines (519 loc) · 10.1 KB
/
schema.fbs
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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
// Flatbuffers schema for serialized RTen models.
//
// See https://google.github.io/flatbuffers/flatbuffers_guide_writing_schema.html.
//
// Operator names and attributes align with the corresponding ONNX operators.
// See https://onnx.ai/onnx/operators/index.html.
file_identifier "RTEN";
file_extension "rten";
// Type for an operator node
enum OperatorType: ubyte {
Add,
ArgMin,
ArgMax,
AveragePool,
BatchNormalization,
Cast,
Clip,
Concat,
ConstantOfShape,
Conv,
ConvTranspose,
Cos,
CumSum,
Div,
Equal,
Erf,
Expand,
Flatten,
Gather,
Gemm,
GlobalAveragePool,
Greater,
GRU,
Identity,
LeakyRelu,
Less,
LessOrEqual,
Log,
LogSoftmax,
LSTM,
MatMul,
MaxPool,
Mod,
Mul,
Pad,
Pow,
Range,
ReduceMean,
ReduceL2,
Relu,
Reshape,
Resize,
Shape,
Sigmoid,
Sin,
Slice,
Split,
Sqrt,
Squeeze,
Softmax,
Sub,
Tanh,
Transpose,
Unsqueeze,
Where,
// New operators. These are appended here to preserve binary compatibility
// of existing model files.
ReduceProd,
ReduceSum,
ReduceMin,
ReduceMax,
NonZero,
ScatterElements,
Tile,
Not,
Abs,
Max,
Mean,
Min,
Sum,
OneHot,
Round,
Floor,
Ceil,
Reciprocal,
TopK,
Neg,
Exp,
GreaterOrEqual,
Size,
Tan,
Acos,
Asin,
Atan,
InstanceNormalization,
HardSigmoid,
HardSwish,
And,
Or,
Xor,
Trilu,
ScatterND,
NonMaxSuppression,
Sign,
GatherElements,
LayerNormalization,
ReduceSumSquare,
RandomUniform,
Elu,
RandomUniformLike,
RandomNormal,
RandomNormalLike,
Softplus,
GatherND,
Gelu,
Einsum,
If,
DequantizeLinear,
QuantizeLinear,
DynamicQuantizeLinear,
MatMulInteger,
}
enum RNNDirection: ubyte {
Forward,
Reverse,
Bidirectional
}
// Values for `auto_pad` field. In ONNX the default for `auto_pad` is "NOTSET".
// In this schema the default is `Same` for some operators for backwards
// compatibility. The converter will however set it to `Fixed` if the `auto_pad`
// attribute is missing in the ONNX model, preserving ONNX semantics.
enum AutoPad: ubyte {
// nb. ONNX defines `SAME_UPPER` and `SAME_LOWER`. This corresponds to
// `SAME_UPPER` and TensorFlow / Keras's "same".
Same,
NotSet
}
enum DataType: ubyte {
Int32,
Float,
Int8,
UInt8,
}
// Coordinate transform modes for Resize operator.
enum CoordTransformMode: ubyte {
HalfPixel,
Asymmetric,
AlignCorners
}
// Rounding modes supported by Resize operator when `ResizeMode` is `Nearest`.
enum NearestMode: ubyte {
Floor,
Ceil,
RoundPreferFloor,
RoundPreferCeil,
}
enum ResizeMode: ubyte {
Nearest,
Linear
}
// Operator-specific configuration
union OperatorAttrs {
ArgMaxAttrs, // Also used for ArgMin
AveragePoolAttrs,
BatchNormalizationAttrs, // Also used for InstanceNormalization
CastAttrs,
ConcatAttrs,
ConstantOfShapeAttrs,
ConvAttrs,
ConvTransposeAttrs,
FlattenAttrs,
GatherAttrs, // Also used for GatherElements
GemmAttrs,
GRUAttrs,
LeakyReluAttrs,
LSTMAttrs,
MaxPoolAttrs,
ReduceMeanAttrs, // Also used for Reduce* ops
ReshapeAttrs,
ResizeAttrs,
SplitAttrs,
SoftmaxAttrs, // Also used for LogSoftmax
TransposeAttrs,
// New operator attrs. These are appended here to preserve binary compatibility
// of existing model files.
ModAttrs,
ScatterElementsAttrs,
OneHotAttrs,
TopKAttrs,
HardSigmoidAttrs,
TriluAttrs,
ScatterNDAttrs,
NonMaxSuppressionAttrs,
LayerNormalizationAttrs,
RandomUniformAttrs,
EluAttrs,
RandomUniformLikeAttrs,
RandomNormalAttrs,
RandomNormalLikeAttrs,
GatherNDAttrs,
GeluAttrs,
EinsumAttrs,
IfAttrs,
PadAttrs,
DequantizeLinearAttrs,
QuantizeLinearAttrs,
}
table ArgMaxAttrs {
axis:int;
keep_dims:bool;
}
table AveragePoolAttrs {
kernel_size:[uint] (required);
auto_pad:AutoPad;
// Padding for spatial axes as [top, left, bottom, right]
pads:[uint];
strides:[uint];
count_include_pad:bool;
}
table BatchNormalizationAttrs {
epsilon:float;
}
table CastAttrs {
to:DataType;
}
table ConcatAttrs {
axis:int;
}
union Scalar {
IntScalar,
FloatScalar
}
table IntScalar {
value:int32;
}
table FloatScalar {
value:float32;
}
table ConstantOfShapeAttrs {
value:Scalar (required);
}
table ConvAttrs {
auto_pad:AutoPad;
// Padding for spatial axes as [left, right] or [top, left, bottom, right]
pads:[uint];
groups:uint;
strides:[uint];
dilations:[uint];
}
table ConvTransposeAttrs {
strides:[uint];
// Defaults to `NotSet` for backwards compatibility.
auto_pad:AutoPad = NotSet;
// Padding for spatial axes as [left, right] or [top, left, bottom, right]
pads:[uint];
}
table DequantizeLinearAttrs {
axis:int;
}
table EinsumAttrs {
equation:string;
}
table EluAttrs {
alpha:float;
}
table FlattenAttrs {
axis:int;
}
table LayerNormalizationAttrs {
axis:int;
epsilon:float;
}
table GatherAttrs {
axis:int;
}
table GatherNDAttrs {
batch_dims:int;
}
// Reserved for supporting `approximate` attr in future.
table GeluAttrs {}
table GemmAttrs {
alpha:float;
beta:float;
transpose_a:bool;
transpose_b:bool;
}
table GRUAttrs {
direction:RNNDirection;
hidden_size:uint;
linear_before_reset:bool;
}
table HardSigmoidAttrs {
alpha:float;
beta:float;
}
table IfAttrs {
then_branch:Graph;
else_branch:Graph;
}
table LeakyReluAttrs {
alpha:float;
}
table LSTMAttrs {
direction:RNNDirection;
hidden_size:uint;
}
table MaxPoolAttrs {
kernel_size:[uint] (required);
auto_pad:AutoPad;
// Padding for spatial axes as [top, left, bottom, right]
pads:[uint];
strides:[uint];
}
table ModAttrs {
fmod:bool;
}
enum NMSBoxOrder: ubyte {
TopLeftBottomRight,
CenterWidthHeight,
}
table NonMaxSuppressionAttrs {
box_order:NMSBoxOrder;
}
table OneHotAttrs {
axis:int;
}
enum PadMode: ubyte {
Constant,
Reflect,
}
table PadAttrs {
mode:PadMode;
}
table QuantizeLinearAttrs {
axis:int;
output_dtype:DataType = null;
}
table RandomNormalAttrs {
mean:float;
scale:float;
seed:float = null;
shape:[uint];
}
table RandomNormalLikeAttrs {
mean:float;
scale:float;
seed:float = null;
}
table RandomUniformAttrs {
shape:[uint];
high:float;
low:float;
seed:float = null;
}
table RandomUniformLikeAttrs {
high:float;
low:float;
seed:float = null;
}
table ReduceMeanAttrs {
axes:[int];
keep_dims:bool;
}
table ReshapeAttrs {
allow_zero:bool;
}
table ResizeAttrs {
mode:ResizeMode;
coord_mode:CoordTransformMode;
nearest_mode:NearestMode;
}
enum ScatterReduction: ubyte {
None,
Add,
Mul,
Min,
Max,
}
table ScatterElementsAttrs {
axis:int;
reduction:ScatterReduction;
}
table ScatterNDAttrs {
reduction:ScatterReduction;
}
table SoftmaxAttrs {
axis:int;
}
table SplitAttrs {
axis:int;
}
table TopKAttrs {
axis:int;
largest:bool;
sorted:bool;
}
table TransposeAttrs {
perm:[uint];
}
table TriluAttrs {
upper:bool;
}
// Node in the dataflow graph
union NodeKind {
OperatorNode,
ConstantNode,
ValueNode
}
// Graph node that computes an output tensor given one or more inputs and
// operator configuration.
table OperatorNode {
type:OperatorType;
attrs:OperatorAttrs;
// Indexes of input nodes. Negative values indicate missing optional inputs.
inputs:[int];
// Indexes of output nodes. Negative values indicate unused outputs.
outputs:[int];
}
// Data for constants stored inline in a model.
union ConstantData {
FloatData,
Int32Data,
Int8Data,
UInt8Data,
}
table FloatData {
data: [float32] (required);
}
table Int8Data {
data: [byte] (required);
}
table Int32Data {
data: [int32] (required);
}
table UInt8Data {
data: [ubyte] (required);
}
enum ConstantDataType: ushort {
Int32, // Signed 32-bit int
Float32, // IEEE-754 32-bit float
Int8,
UInt8,
}
// Graph node for a constant tensor value, whose data is part of the model.
table ConstantNode {
shape:[uint] (required);
// Tensor data embedded within the model file.
data:ConstantData;
// Data type. This is null in older models.
dtype:ConstantDataType = null;
// Offset of tensor data from the start of the tensor data segment in the
// model file. Null if the tensor data is stored inline.
data_offset:uint64 = null;
}
// Dimension of a ValueNode's shape. This can be either a fixed value or a
// symbolic name.
//
// This is logically a union, but uses a table due to
// https://github.com/google/flatbuffers/issues/5024.
table Dim {
value:uint;
name:string;
}
// Graph node for a dynamic tensor value, such as a model input or operator
// output.
table ValueNode {
// Expected shape of the tensor at runtime.
shape:[Dim];
}
table Node {
// Identifier for external referencing and debugging
name:string;
data:NodeKind;
}
// Graph describing a sequence of operations in a model.
//
// This is analagous to the body of a function or closure in a programming
// language.
table Graph {
// Nodes are sorted in topological order. This means that if a node references
// other nodes (eg. an operator node referencing inputs), the referents must
// come earlier in the list.
nodes:[Node];
// IDs of input nodes
inputs:[uint];
// IDs of output nodes
outputs:[uint];
// IDs of nodes which capture their values from the enclosing scope when
// this graph is run as a subgraph.
captures:[uint];
}
table Metadata {
// SHA-256 hash of the ONNX model that was used as the source for this RTen
// model.
onnx_hash:string;
// A short description of what this model does.
description:string;
// Identifier for the license used in this model.
//
// This should be an SPDX (https://spdx.org/licenses/) identifier for openly
// licensed models.
license:string;
// Commit ID for the code that produced this model.
commit:string;
// URL of repository where the model's code is hosted (eg. GitHub).
code_repository:string;
// URL of repository where the model is hosted (eg. Hugging Face).
model_repository:string;
// Identifier for the training run that produced this model.
run_id:string;
// URL of logs etc. for the training run that produced this model.
run_url:string;
}
table Model {
schema_version:int;
graph:Graph (required);
metadata:Metadata;
}
root_type Model;