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

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