xref: /aosp_15_r20/external/executorch/devtools/bundled_program/schema/bundled_program_schema.fbs (revision 523fa7a60841cd1ecfb9cc4201f1ca8b03ed023a)
1// Copyright (c) Meta Platforms, Inc. and affiliates.
2
3//
4// See README.md before modifying this file.
5//
6
7include "scalar_type.fbs";
8
9namespace bundled_program_flatbuffer;
10
11// Identifier of a valid bundled program schema.
12file_identifier "BP08";
13// Extension of written files.
14file_extension "bpte";
15
16// Reason for basic struct: union value type can only be table/struct/string
17table Int {
18  int_val:long;
19}
20
21table Bool {
22  bool_val:bool;
23}
24
25table Double {
26  double_val:double;
27}
28
29// All information we need to bundle for a tensor EValue input.
30table Tensor {
31  // The scalar type of Tensor
32  scalar_type: executorch_flatbuffer.ScalarType;
33  // The target sizes of the tensor.
34  sizes: [int];
35  // The contents of the corresponding input tensor.
36  data: [ubyte] (force_align: 16);
37  dim_order:[ubyte];
38}
39
40union ValueUnion {
41  Tensor,
42  Int,
43  Bool,
44  Double,
45}
46
47// Abstraction for BundledMethodTestCase values
48table Value {
49  val: ValueUnion;
50}
51
52// A single test for a method. The provided inputs should produce the
53// expected outputs.
54table BundledMethodTestCase {
55  // The inputs to provide to the method. The number and types of inputs must
56  // match the schema of the method under test.
57  inputs: [Value];
58
59  // The expected outputs generated while running the model in eager mode using
60  // the inputs provided. Its length should be equal to the length of program
61  // outputs.
62  expected_outputs: [Value];
63}
64
65// Collection of test cases for a program method.
66table BundledMethodTestSuite {
67  // The name of the method to test; e.g., "forward" for the forward() method
68  // of an nn.Module. This name match a method defined by the ExecuTorch
69  // program.
70  method_name: string;
71
72  // Individual test cases for the method.
73  test_cases: [BundledMethodTestCase];
74}
75
76
77// Executorch program bunlded with data for verification.
78table BundledProgram {
79  // Schema version.
80  version:uint;
81
82  // Test sets to run against the program.
83  // Each BundledMethodTestSuite should be used for the method of program sharing same name.
84  method_test_suites: [BundledMethodTestSuite];
85
86  // The binary data of a serialized Executorch program.
87  // The following `force_align` may sliently override any larger force_align
88  // used in the program. Therefore, to keep the data (including constant
89  // tensor, delegate data, etc, see schema.fbs for more info) in the
90  // executorch program keeps the same alignment as original no matter how
91  // the program schema changes, we need to make the force_align here the max
92  // one around all kinds of force_align in the current and future program
93  // schema, so we use the 32 as the force_align here.
94  program: [ubyte] (force_align: 32);
95}
96
97root_type BundledProgram;
98