You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

om.proto 9.1 kB

4 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. /**
  2. * Copyright 2019-2020 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. syntax = "proto3";
  17. package domi;
  18. enum TargetType
  19. {
  20. MINI = 0;
  21. TINY = 1;
  22. LITE = 2;
  23. }
  24. // offline model
  25. message ModelDef {
  26. string name = 1;
  27. uint32 version = 2;
  28. uint64 memory_size = 10;
  29. uint32 stream_num = 11;
  30. uint32 event_num = 12;
  31. uint64 weight_size = 13;
  32. uint32 label_num = 15;
  33. repeated OpDef op = 20;
  34. TargetType target_type = 23;
  35. map<string, AttrDef> attr = 30;
  36. };
  37. // operator define
  38. message OpDef {
  39. string name = 1;
  40. string type = 2;
  41. uint32 id = 3;
  42. uint32 stream_id = 4;
  43. repeated string input_name = 5;
  44. repeated string src_name = 8;
  45. repeated int32 src_index = 9;
  46. repeated int64 input = 10;
  47. repeated int64 output = 11;
  48. repeated TensorDescriptor input_desc = 12;
  49. repeated TensorDescriptor output_desc = 13;
  50. repeated WeightDef weights = 14;
  51. repeated string dst_name = 15;
  52. repeated int32 dst_index = 16;
  53. repeated int64 workspace = 20;
  54. repeated uint32 workspace_bytes = 21;
  55. repeated string weight_name = 22;
  56. repeated bool is_input_const = 23;
  57. map<string, AttrDef> attr = 30;
  58. QuantizeFactorParams quantize_factor = 31;
  59. oneof op_params {
  60. // start at 100 here
  61. SendOpParams sender_param = 100;
  62. RecvOpParams receiver_param = 200;
  63. ConvolutionOpParams convolution_param = 300;
  64. PoolingOpParams pooling_param = 400;
  65. EltwiseOpParams eltwise_param = 500;
  66. BatchNormOpParams batchnorm_param = 600;
  67. ScaleOpParams scale_param = 700;
  68. FullConnectionOpParams full_connection_param = 800;
  69. SoftmaxOpParams softmax_param = 900;
  70. ActivationOpParams activation_param = 1000;
  71. ReshapeOpParams reshape_param = 1100;
  72. }
  73. };
  74. message SendOpParams {
  75. uint32 event_id = 1;
  76. };
  77. message RecvOpParams {
  78. uint32 event_id = 1;
  79. };
  80. enum QuantizeScaleType
  81. {
  82. VECTOR_SCALE = 0;
  83. SCALAR_SCALE = 1;
  84. }
  85. enum QuantizeScaleMode
  86. {
  87. NORMAL_MODE = 0;
  88. SQRT_MODE = 1;
  89. }
  90. enum QuantizeAlgorithm
  91. {
  92. NON_OFFSET_ALGO = 0;
  93. HALF_OFFSET_ALGO = 1;
  94. ALL_OFFSET_ALGO = 2;
  95. }
  96. message QuantizeFactor
  97. {
  98. QuantizeScaleMode scale_mode = 1;
  99. bytes scale_value = 2;
  100. int64 scale_offset = 3;
  101. bytes offset_data_value = 4;
  102. int64 offset_data_offset = 5;
  103. bytes offset_weight_value = 6;
  104. int64 offset_weight_offset = 7;
  105. bytes offset_pad_value = 8;
  106. int64 offset_pad_offset = 9;
  107. };
  108. message QuantizeCalcFactor
  109. {
  110. bytes offsetw = 1;
  111. int64 offsetw_offset = 2;
  112. bytes offsetd = 3;
  113. int64 offsetd_offset = 4;
  114. bytes scalereq = 5;
  115. int64 scaledreq_offset = 6;
  116. bytes offsetdnext = 7;
  117. int64 offsetdnext_offset = 8;
  118. }
  119. message QuantizeFactorParams
  120. {
  121. QuantizeAlgorithm quantize_algo = 1;
  122. QuantizeScaleType scale_type = 2;
  123. QuantizeFactor quantize_param = 3;
  124. QuantizeFactor dequantize_param = 4;
  125. QuantizeFactor requantize_param = 5;
  126. QuantizeCalcFactor quantizecalc_param = 6;
  127. };
  128. message ConvolutionOpParams {
  129. int32 mode = 1;
  130. int32 algo = 2;
  131. int32 pad_mode = 3;
  132. uint32 group = 4;
  133. uint32 num_output = 5;
  134. repeated uint32 pad = 10;
  135. repeated uint32 stride = 11;
  136. repeated uint32 dilation = 12;
  137. repeated uint32 kernel = 13;
  138. float alpha = 20;
  139. float beta = 21;
  140. WeightDef filter = 40;
  141. WeightDef bias = 41;
  142. bool relu_flag = 62;
  143. repeated uint32 adj = 70;
  144. repeated uint32 target_shape = 71;
  145. repeated uint32 before_pad = 72;
  146. };
  147. message PoolingOpParams {
  148. int32 mode = 1;
  149. int32 nan_opt = 2;
  150. int32 pad_mode = 3;
  151. bool global_pooling = 4;
  152. repeated uint32 window = 10;
  153. repeated uint32 pad = 11;
  154. repeated uint32 stride = 12;
  155. bool ceil_mode = 13;
  156. int32 data_mode = 14;
  157. float alpha = 20;
  158. float beta = 21;
  159. repeated uint32 before_pad = 22;
  160. };
  161. message EltwiseOpParams {
  162. int32 mode = 1;
  163. repeated float coeff = 2;
  164. float alpha = 3;
  165. float beta = 4;
  166. repeated WeightDef weight = 5;
  167. bool relu_flag = 6;
  168. };
  169. message ActivationOpParams {
  170. int32 mode = 1;
  171. float coef = 2;
  172. float alpha = 3;
  173. float beta = 4;
  174. };
  175. message BatchNormOpParams {
  176. int32 mode = 1;
  177. float alpha = 2;
  178. float beta = 3;
  179. double epsilon = 4;//optinal,[default = 1e-5]
  180. bool use_global_stats = 5; //optinal,by default true,testing mode
  181. float moving_average_fraction = 6; //optinal,[default = .999];
  182. WeightDef estimated_mean = 7;
  183. WeightDef estimated_variance = 8;
  184. WeightDef scale = 9;
  185. WeightDef bias = 10;
  186. };
  187. message ScaleOpParams {
  188. WeightDef scale = 1;
  189. WeightDef bias = 2;
  190. };
  191. message ReshapeOpParams {
  192. float alpha = 1;
  193. float beta = 2;
  194. ShapeDef shape = 3;
  195. int32 axis = 4;
  196. int32 num_axes = 5;
  197. int32 format = 6;
  198. };
  199. message SoftmaxOpParams {
  200. int32 algo = 1;
  201. int32 mode = 2;
  202. float alpha = 3;
  203. float beta = 4;
  204. };
  205. message FullConnectionOpParams {
  206. WeightDef filter = 1;
  207. WeightDef bias = 2;
  208. uint32 num_output = 3;
  209. bool relu_flag = 12;
  210. };
  211. message FlattenOpParams {
  212. float alpha = 1;
  213. float beta = 2;
  214. int32 start_axis = 3;
  215. int32 end_axis = 4;
  216. }
  217. message AddLimitedOpParams {
  218. float alpha = 1;
  219. float beta = 2;
  220. int32 axis = 3;
  221. bool broadcast = 4;
  222. repeated WeightDef weight = 10;
  223. };
  224. message MulLimitedOpParams {
  225. float alpha = 1;
  226. float beta = 2;
  227. int32 axis = 3;
  228. bool broadcast = 4;
  229. repeated WeightDef weight = 10;
  230. };
  231. message AddOpParams {
  232. float alpha = 1;
  233. float beta = 2;
  234. repeated WeightDef weight = 10;
  235. };
  236. message MulOpParams {
  237. float alpha = 1;
  238. float beta = 2;
  239. repeated WeightDef weight = 10;
  240. };
  241. message SubOpParams {
  242. float alpha = 1;
  243. float beta = 2;
  244. repeated WeightDef weight = 10;
  245. };
  246. message BiasAddOpParams {
  247. float alpha = 1;
  248. float beta = 2;
  249. WeightDef bias = 10;
  250. };
  251. message MatMulOpParams {
  252. float alpha = 1;
  253. float beta = 2;
  254. bool transposeX = 3;
  255. bool transposeW = 4;
  256. WeightDef filter = 10;
  257. WeightDef bias = 12;
  258. };
  259. message RsqrtOpParams {
  260. float alpha = 1;
  261. float beta = 2;
  262. };
  263. message WeightDef {
  264. int32 format = 1;
  265. int32 data_type = 2;
  266. ShapeDef shape = 3;
  267. bytes data = 4;
  268. int64 data_offset = 5;
  269. uint32 cmps_size = 6;
  270. bytes cmps_tab = 7;
  271. int64 cmps_tab_offset = 10;
  272. CompressInfo cmps_info = 8;
  273. AllOffsetQuantizeInfo alloffset_quantize_info = 11;
  274. }
  275. message ShapeDef {
  276. repeated int64 dim = 1;
  277. }
  278. enum DeviceType {
  279. NPU = 0; // In default, we will use NPU.
  280. CPU = 1; // CPU
  281. }
  282. message AllOffsetQuantizeInfo {
  283. float scale = 1;
  284. int32 offset = 2;
  285. }
  286. message TensorDescriptor {
  287. int32 format = 1;
  288. int32 data_type = 2;
  289. repeated int64 dim = 3;
  290. uint32 size = 4;
  291. bool reuse_input = 5;
  292. bool output_tensor = 7;
  293. DeviceType device_type = 8;
  294. bool input_tensor = 9;
  295. uint32 real_dim_cnt = 10;
  296. uint32 reuse_input_index = 11;
  297. AllOffsetQuantizeInfo alloffset_quantize_info = 12;
  298. }
  299. message CompressInfo {
  300. int32 blockRow = 1; // block row
  301. int32 blockCol = 2; // block col
  302. int32 fractalK = 3; // fractal K
  303. int32 fractalN = 4; // fractal N
  304. int32 lastFractalK = 5; // K of last fractal
  305. int32 lastFractalN = 6; // N of last fractal
  306. int32 cubeSize = 7; // cube's length
  307. int32 loadDir = 8; // data load directtiono 0:col load 1:row load
  308. }
  309. message AttrDef {
  310. message ListValue {
  311. repeated string s = 2; // "list(string)"
  312. repeated int64 i = 3 [packed = true]; // "list(int)"
  313. repeated float f = 4 [packed = true]; // "list(float)"
  314. repeated bool b = 5 [packed = true]; // "list(bool)"
  315. repeated uint32 u = 6 [packed = true]; // "list(uint)"
  316. repeated bytes bt = 7;
  317. }
  318. oneof value {
  319. string s = 2; // "string"
  320. int64 i = 3; // "int"
  321. float f = 4; // "float"
  322. bool b = 5; // "bool"
  323. uint32 u = 6; // "uint32"
  324. bytes bt = 7;
  325. ListValue list = 1; // any "list(...)"
  326. NamedAttrs func = 10;
  327. }
  328. }
  329. // A list of attr names and their values. The whole list is attached
  330. // with a string name. E.g., MatMul[T=float].
  331. message NamedAttrs {
  332. string name = 1;
  333. map<string, AttrDef> attr = 2;
  334. }

图引擎模块(GE)是MindSpore的一个子模块,其代码由C++实现,位于前端模块ME和底层硬件之间,起到承接作用。图引擎模块以ME下发的图作为输入,然后进行一系列的深度图优化操作,最后输出一张可以在底层硬件上高效运行的图。GE针对昇腾AI处理器的硬件结构特点,做了特定的优化工作,以此来充分发挥出昇腾AI处理器的强大算力。在进行模型训练/推理时,GE会被自动调用而用户并不感知。GE主要由GE API和GE Core两部分组成,详细的架构图如下所示