schema_v2.fbs 5.3 KB
Newer Older
1 2 3 4 5 6 7
include "dtype.fbs";
include "opr_param_defs.fbs";
include "mgb_opr_param_defs.fbs";
include "mgb_cpp_opr.fbs";

namespace mgb.serialization.fbs.v2;

M
Megvii Engine Team 已提交
8
file_identifier "mgv2";
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

table CompNode {
    logical_locator:string;
}

table DefaultTensorFormat{}

table Image2DPackedTensorFormat{
    align_axis: ubyte;
}

table LowbitsAlignedTensorFormat{
    size_nbits: ubyte;
    align_size_in_bits: ubyte;
}

/// The Tensor Format
union TensorFormat {
    DefaultTensorFormat = 1,
    Image2DPackedTensorFormat = 2,
    LowbitsAlignedTensorFormat = 3,
}

/// Opaque byte buffer defined by operator implementation
table Blob {
    data:[ubyte];
}

table Tensor {
    name:string;
    shape:[uint];
    comp_node:CompNode;
    dtype:DType;
    format:TensorFormat;
    /// The tensor raw data
    data:[ubyte];
}

table Reserved0 {}
table DeprecatedParam {}

union OperatorParam {
    param.Empty = 1,
    param.Axis = 2,
    param.Convolution = 3,
    param.MaskPropagate = 4,
    param.ConvPooling = 5,
    param.ConvBias = 6,
    param.SeparableConv = 7,
    param.Images2Neibs = 8,
    param.Pooling = 9,
    param.LRN = 10,
    param.BN = 11,
    param.ROIPooling = 12,
    param.WarpPerspective = 13,
    param.SpatialTfGridGenerator = 14,
    param.SpatialTfSampler = 15,
    param.MGBAddUpdate = 16,
    param.Elemwise = 17,
    param.ElemwiseMultiType = 18,
    param.PowC = 19,
    param.MatrixMul = 20,
    //Reserved for param.Winograd = 21,
    DeprecatedParam = 21,
    param.SVD = 22,
    param.Reduce = 23,
    param.Cumsum = 24,
    param.CondTake = 25,
    param.Argsort = 26,
    param.IndexingRemap = 27,
    param.MGBSleep = 28,
    param.Linspace = 29,
    param.LinspaceFull = 30,
    param.Eye = 31,
    param.UniformRNG = 32,
    param.GaussianRNG = 33,
    param.Flip = 34,
    param.Rotate = 35,
    param.ROICopy = 36,
    param.CvtColor = 37,
    param.WarpAffine = 38,
    param.GaussianBlur = 39,
    param.Resize = 40,
    param.Convolution3D = 41,
    param.Conv3DBias = 42,
    param.SeparableConv3D = 43,
    param.TopK = 44,
    param.RelayoutFormat = 45,
    param.SeparableFilter = 46,
    param.LocalShare = 47,
    param.ROIAlign = 48,
    param.DeformablePSROIPooling = 49,
    param.BatchConvBias = 50,
    param.DType = 51,
    param.PersistentOutputStorage = 52,
    param.OptionalAxis = 53,
    param.OptionalAxisV1 = 54,
    param.ExecutionPolicy = 55,
    param.AssertEqual = 56,
M
Megvii Engine Team 已提交
108
    Reserved0 = 57,
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
    param.CollectiveComm = 58,
    param.CondExecPred = 59,
    param.CondExecPredLogical = 60,
    param.CondExecMark = 61,
    param.CondExecMerge = 62,
    param.Host2DeviceCopy = 63,
    param.Dimshuffle = 64,
    param.AxisAddRemove = 65,
    param.IndexDescMaskDump = 66,
    DType = 67,
    param.Remap = 68,
    param.NMSKeep = 69,
    param.AdaptivePooling = 70,
    param.NvOf = 71,
    param.DctChannelSelect = 72,
    param.FakeQuant = 73,
    param.TQT = 74,
    param.Correlation = 75,
    param.LSQ = 76,
    param.GammaRNG = 77,
    param.PoissonRNG = 78,
    param.PermutationRNG = 79,
    param.BetaRNG = 80,
    param.SlidingWindowTranspose = 81,
    param.Padding = 82,
    param.ShuffleRNG = 83,
    param.CheckNonFinite = 84,
    param.LayerNorm = 85,
    param.Dropout = 86,
    param.RNNCell = 87,
    param.RNN = 88,
    param.LSTM = 89,
    param.Softmax = 90,
    param.Diag = 91,
143
    param.GroupNorm = 92,
M
Megvii Engine Team 已提交
144
    param.Fill = 93,
145
    param.GeneralNorm=94,
146
    param.MultiHeadAttn=95,
147
    param.Resize3D = 96,
148
    param.Cross = 97,
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
}

table Operator {
    /// the Operator type id
    type:string;
    /// sometime type maybe not exist, so add type_id
    type_id:ulong;
    name:string;

    /// Operator parameter
    param:OperatorParam;
    /// Operator may want to save more than one OperatorParam
    additional_params:[OperatorParam];

    /// ID of the input tensor in the middle_tensors of a model
    inputs:[uint];

    /// ID of the output tensor in the middle_tensors of a model
    outputs:[uint];

    comp_node:[CompNode];
    output_dtype:DType;

    /// the const value in tensor format of the Operator
    tensors:[Tensor];

    /// opr version, with develop of MegEngine, some opr may have multi version
    opr_version:uint;

    /// the order of the Operator in the graph
    priority:int = 0;

    /// custom may want to save big, opaque byte buffers.
    custom_data:[Blob];
}

table Metadata {
    is_valid:bool;
    graph_modified:bool;
    optimize_options:ulong;
    user_info:string;
}

table MiddleTensor {
    name:string;
    shape:[uint];
    comp_node:CompNode;
    dtype:DType;
    format:TensorFormat;
}

table OutputVar {
    /// the id of the middle tensor in graph, the same as the inputs in Operator
    compact_id:uint;
    original_id:uint;
}

M
Megvii Engine Team 已提交
206 207 208 209 210
table OutputAlias {
    id:uint;
    name:string;
}

211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
table Model {
    /// the megengine version when serialize the model
    mge_version:uint;

    /// model version, now model support:
    /// version v1: the original fbs serialization version
    /// version v2: support backward and poor forward compatibility
    model_version:uint;

    oprs:[Operator];

    /// the tensors produce and consume by the Operators, not the input or
    /// output tensor
    middle_tensors:[MiddleTensor];

    output_vars_idx:[OutputVar];
M
Megvii Engine Team 已提交
227
    output_alias:[OutputAlias];
228 229 230 231 232 233 234

    nr_shared_tensor:uint;
    /// the Metadata to storage the custom data or some flags
    metadata:Metadata;
}

root_type Model;