mindspore 2.5.0__cp39-cp39-win_amd64.whl → 2.6.0rc1__cp39-cp39-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of mindspore might be problematic. Click here for more details.

Files changed (491) hide show
  1. mindspore/.commit_id +1 -1
  2. mindspore/Microsoft.VisualStudio.Telemetry.dll +0 -0
  3. mindspore/Newtonsoft.Json.dll +0 -0
  4. mindspore/__init__.py +6 -4
  5. mindspore/_c_dataengine.cp39-win_amd64.pyd +0 -0
  6. mindspore/_c_expression.cp39-win_amd64.pyd +0 -0
  7. mindspore/_c_mindrecord.cp39-win_amd64.pyd +0 -0
  8. mindspore/_check_jit_forbidden_api.py +3 -0
  9. mindspore/_checkparam.py +3 -33
  10. mindspore/_deprecated/__init__.py +17 -0
  11. mindspore/_deprecated/jit.py +198 -0
  12. mindspore/_extends/builtin_operations.py +1 -1
  13. mindspore/_extends/parse/__init__.py +6 -7
  14. mindspore/_extends/parse/compile_config.py +19 -0
  15. mindspore/_extends/parse/deprecated/deprecated_tensor_method.py +22 -3
  16. mindspore/_extends/parse/jit_fallback_modules/__init__.py +0 -0
  17. mindspore/_extends/parse/jit_fallback_modules/check_utils.py +123 -0
  18. mindspore/_extends/parse/jit_fallback_modules/third_party_modules.py +50 -0
  19. mindspore/_extends/parse/parser.py +24 -193
  20. mindspore/_extends/parse/resources.py +1 -5
  21. mindspore/_extends/parse/standard_method.py +97 -74
  22. mindspore/_extends/pijit/__init__.py +2 -2
  23. mindspore/_extends/pijit/pijit_func_white_list.py +16 -11
  24. mindspore/_extends/pijit/tensor_func_list.py +27 -0
  25. mindspore/_extends/utils.py +1 -1
  26. mindspore/amp.py +4 -4
  27. mindspore/atlprov.dll +0 -0
  28. mindspore/avcodec-59.dll +0 -0
  29. mindspore/avdevice-59.dll +0 -0
  30. mindspore/avfilter-8.dll +0 -0
  31. mindspore/avformat-59.dll +0 -0
  32. mindspore/avutil-57.dll +0 -0
  33. mindspore/boost/__init__.py +2 -2
  34. mindspore/boost/base.py +3 -7
  35. mindspore/boost/boost_cell_wrapper.py +2 -2
  36. mindspore/c1.dll +0 -0
  37. mindspore/c1xx.dll +0 -0
  38. mindspore/c2.dll +0 -0
  39. mindspore/common/__init__.py +4 -3
  40. mindspore/common/_grad_function.py +56 -0
  41. mindspore/common/_pijit_context.py +14 -5
  42. mindspore/common/_register_for_tensor.py +1 -1
  43. mindspore/common/_stub_tensor.py +5 -10
  44. mindspore/common/_tensor_cpp_method.py +1 -1
  45. mindspore/common/_tensor_docs.py +1915 -3287
  46. mindspore/common/api.py +341 -354
  47. mindspore/common/auto_dynamic_shape.py +41 -44
  48. mindspore/common/dtype.py +5 -2
  49. mindspore/common/dump.py +7 -5
  50. mindspore/common/file_system.py +3 -0
  51. mindspore/common/hook_handle.py +5 -3
  52. mindspore/common/initializer.py +10 -6
  53. mindspore/common/jit_begin_end.py +94 -0
  54. mindspore/common/jit_config.py +6 -1
  55. mindspore/common/jit_context.py +76 -0
  56. mindspore/common/jit_trace.py +378 -0
  57. mindspore/common/lazy_inline.py +2 -2
  58. mindspore/common/mutable.py +5 -4
  59. mindspore/common/parameter.py +106 -39
  60. mindspore/common/seed.py +2 -2
  61. mindspore/common/sparse_tensor.py +23 -17
  62. mindspore/common/tensor.py +297 -714
  63. mindspore/communication/__init__.py +7 -5
  64. mindspore/communication/_comm_helper.py +47 -2
  65. mindspore/communication/comm_func.py +70 -53
  66. mindspore/communication/management.py +83 -17
  67. mindspore/context.py +214 -560
  68. mindspore/dataset/__init__.py +44 -20
  69. mindspore/dataset/audio/__init__.py +2 -8
  70. mindspore/dataset/audio/transforms.py +3 -17
  71. mindspore/dataset/core/config.py +3 -3
  72. mindspore/dataset/engine/cache_client.py +1 -1
  73. mindspore/dataset/engine/datasets.py +102 -120
  74. mindspore/dataset/engine/datasets_audio.py +22 -22
  75. mindspore/dataset/engine/datasets_standard_format.py +43 -24
  76. mindspore/dataset/engine/datasets_text.py +78 -85
  77. mindspore/dataset/engine/datasets_user_defined.py +108 -76
  78. mindspore/dataset/engine/datasets_vision.py +111 -108
  79. mindspore/dataset/engine/iterators.py +5 -3
  80. mindspore/dataset/engine/obs/obs_mindrecord_dataset.py +1 -1
  81. mindspore/dataset/engine/samplers.py +279 -57
  82. mindspore/dataset/engine/serializer_deserializer.py +2 -1
  83. mindspore/dataset/engine/validators.py +10 -0
  84. mindspore/dataset/text/__init__.py +7 -6
  85. mindspore/dataset/text/transforms.py +6 -5
  86. mindspore/dataset/text/utils.py +3 -3
  87. mindspore/dataset/transforms/__init__.py +0 -9
  88. mindspore/dataset/transforms/transforms.py +3 -3
  89. mindspore/dataset/utils/browse_dataset.py +1 -1
  90. mindspore/dataset/vision/__init__.py +2 -9
  91. mindspore/dataset/vision/transforms.py +202 -158
  92. mindspore/dataset/vision/utils.py +7 -5
  93. mindspore/device_context/ascend/op_debug.py +60 -1
  94. mindspore/device_context/ascend/op_tuning.py +0 -4
  95. mindspore/device_manager.py +39 -3
  96. mindspore/dnnl.dll +0 -0
  97. mindspore/dpcmi.dll +0 -0
  98. mindspore/experimental/es/embedding_service.py +35 -27
  99. mindspore/experimental/map_parameter.py +4 -4
  100. mindspore/experimental/optim/adadelta.py +22 -26
  101. mindspore/experimental/optim/adagrad.py +4 -4
  102. mindspore/experimental/optim/adam.py +4 -0
  103. mindspore/experimental/optim/adamax.py +4 -4
  104. mindspore/experimental/optim/adamw.py +4 -0
  105. mindspore/experimental/optim/asgd.py +1 -1
  106. mindspore/experimental/optim/lr_scheduler.py +40 -22
  107. mindspore/experimental/optim/radam.py +5 -5
  108. mindspore/experimental/optim/rprop.py +1 -1
  109. mindspore/experimental/optim/sgd.py +1 -1
  110. mindspore/hal/contiguous_tensors_handle.py +6 -10
  111. mindspore/hal/device.py +55 -81
  112. mindspore/hal/event.py +38 -55
  113. mindspore/hal/memory.py +93 -144
  114. mindspore/hal/stream.py +81 -125
  115. mindspore/include/dataset/constants.h +7 -4
  116. mindspore/include/dataset/execute.h +2 -2
  117. mindspore/jpeg62.dll +0 -0
  118. mindspore/log.py +40 -2
  119. mindspore/mindrecord/__init__.py +20 -7
  120. mindspore/mindspore_backend_common.dll +0 -0
  121. mindspore/mindspore_backend_manager.dll +0 -0
  122. mindspore/mindspore_common.dll +0 -0
  123. mindspore/mindspore_core.dll +0 -0
  124. mindspore/mindspore_dump.dll +0 -0
  125. mindspore/mindspore_frontend.dll +0 -0
  126. mindspore/mindspore_glog.dll +0 -0
  127. mindspore/mindspore_memory_pool.dll +0 -0
  128. mindspore/mindspore_ms_backend.dll +0 -0
  129. mindspore/mindspore_ops.dll +0 -0
  130. mindspore/{mindspore_backend.dll → mindspore_ops_host.dll} +0 -0
  131. mindspore/mindspore_ops_kernel_common.dll +0 -0
  132. mindspore/mindspore_profiler.dll +0 -0
  133. mindspore/mindspore_pyboost.dll +0 -0
  134. mindspore/mindspore_pynative.dll +0 -0
  135. mindspore/mindspore_res_manager.dll +0 -0
  136. mindspore/mindspore_runtime_pipeline.dll +0 -0
  137. mindspore/mint/__init__.py +131 -700
  138. mindspore/mint/distributed/__init__.py +5 -1
  139. mindspore/mint/distributed/distributed.py +194 -109
  140. mindspore/mint/linalg/__init__.py +2 -0
  141. mindspore/mint/nn/__init__.py +280 -18
  142. mindspore/mint/nn/functional.py +282 -64
  143. mindspore/mint/nn/layer/__init__.py +4 -0
  144. mindspore/mint/nn/layer/_functions.py +7 -3
  145. mindspore/mint/nn/layer/activation.py +120 -13
  146. mindspore/mint/nn/layer/conv.py +218 -24
  147. mindspore/mint/nn/layer/normalization.py +15 -16
  148. mindspore/mint/nn/layer/padding.py +1 -1
  149. mindspore/mint/nn/layer/pooling.py +66 -1
  150. mindspore/mint/optim/__init__.py +2 -1
  151. mindspore/mint/optim/sgd.py +171 -0
  152. mindspore/msobj140.dll +0 -0
  153. mindspore/mspdb140.dll +0 -0
  154. mindspore/mspdbcore.dll +0 -0
  155. mindspore/mspdbst.dll +0 -0
  156. mindspore/mspft140.dll +0 -0
  157. mindspore/msvcdis140.dll +0 -0
  158. mindspore/msvcp140_1.dll +0 -0
  159. mindspore/msvcp140_2.dll +0 -0
  160. mindspore/msvcp140_atomic_wait.dll +0 -0
  161. mindspore/msvcp140_codecvt_ids.dll +0 -0
  162. mindspore/nn/__init__.py +4 -1
  163. mindspore/nn/cell.py +1250 -176
  164. mindspore/nn/layer/activation.py +23 -21
  165. mindspore/nn/layer/basic.py +22 -16
  166. mindspore/nn/layer/container.py +1 -1
  167. mindspore/nn/layer/conv.py +22 -17
  168. mindspore/nn/layer/embedding.py +9 -8
  169. mindspore/nn/layer/normalization.py +48 -42
  170. mindspore/nn/layer/pooling.py +75 -31
  171. mindspore/nn/layer/transformer.py +11 -10
  172. mindspore/nn/learning_rate_schedule.py +4 -2
  173. mindspore/nn/loss/loss.py +27 -19
  174. mindspore/nn/optim/ada_grad.py +6 -5
  175. mindspore/nn/optim/adadelta.py +9 -7
  176. mindspore/nn/optim/adafactor.py +1 -1
  177. mindspore/nn/optim/adam.py +16 -12
  178. mindspore/nn/optim/adamax.py +8 -7
  179. mindspore/nn/optim/adasum.py +5 -5
  180. mindspore/nn/optim/asgd.py +1 -1
  181. mindspore/nn/optim/ftrl.py +11 -9
  182. mindspore/nn/optim/lamb.py +1 -1
  183. mindspore/nn/optim/lazyadam.py +12 -10
  184. mindspore/nn/optim/momentum.py +7 -6
  185. mindspore/nn/optim/optimizer.py +2 -2
  186. mindspore/nn/optim/proximal_ada_grad.py +12 -10
  187. mindspore/nn/optim/rmsprop.py +13 -12
  188. mindspore/nn/optim/rprop.py +9 -7
  189. mindspore/nn/optim/sgd.py +9 -6
  190. mindspore/nn/optim/tft_wrapper.py +5 -2
  191. mindspore/nn/probability/bijector/bijector.py +17 -11
  192. mindspore/nn/probability/bijector/gumbel_cdf.py +5 -5
  193. mindspore/nn/probability/bijector/invert.py +2 -2
  194. mindspore/nn/probability/bijector/scalar_affine.py +3 -3
  195. mindspore/nn/probability/bijector/softplus.py +3 -2
  196. mindspore/nn/probability/distribution/beta.py +3 -3
  197. mindspore/nn/probability/distribution/categorical.py +1 -1
  198. mindspore/nn/probability/distribution/cauchy.py +4 -2
  199. mindspore/nn/probability/distribution/exponential.py +6 -7
  200. mindspore/nn/probability/distribution/gamma.py +2 -2
  201. mindspore/nn/probability/distribution/gumbel.py +2 -2
  202. mindspore/nn/probability/distribution/half_normal.py +5 -3
  203. mindspore/nn/probability/distribution/logistic.py +5 -3
  204. mindspore/nn/probability/distribution/poisson.py +1 -1
  205. mindspore/nn/probability/distribution/uniform.py +5 -3
  206. mindspore/nn/reinforcement/_tensors_queue.py +1 -1
  207. mindspore/nn/reinforcement/tensor_array.py +1 -1
  208. mindspore/nn/wrap/__init__.py +6 -6
  209. mindspore/nn/wrap/cell_wrapper.py +178 -117
  210. mindspore/nn/wrap/grad_reducer.py +45 -36
  211. mindspore/nn/wrap/loss_scale.py +3 -3
  212. mindspore/numpy/array_creations.py +3 -3
  213. mindspore/numpy/array_ops.py +1 -1
  214. mindspore/numpy/math_ops.py +4 -4
  215. mindspore/numpy/utils.py +1 -2
  216. mindspore/numpy/utils_const.py +1 -2
  217. mindspore/opencv_core452.dll +0 -0
  218. mindspore/opencv_imgcodecs452.dll +0 -0
  219. mindspore/opencv_imgproc452.dll +0 -0
  220. mindspore/ops/__init__.py +3 -2
  221. mindspore/ops/_grad_experimental/grad_comm_ops.py +18 -3
  222. mindspore/ops/_grad_experimental/grad_debug_ops.py +8 -1
  223. mindspore/ops/_grad_experimental/taylor_rule.py +29 -0
  224. mindspore/ops/_register_for_op.py +0 -11
  225. mindspore/{ops_generate → ops/_utils}/arg_dtype_cast.py +123 -4
  226. mindspore/{ops_generate → ops/_utils}/arg_handler.py +3 -4
  227. mindspore/ops/_vmap/vmap_array_ops.py +7 -6
  228. mindspore/ops/_vmap/vmap_grad_nn_ops.py +2 -1
  229. mindspore/ops/_vmap/vmap_math_ops.py +4 -7
  230. mindspore/ops/_vmap/vmap_nn_ops.py +9 -8
  231. mindspore/ops/auto_generate/__init__.py +4 -3
  232. mindspore/ops/auto_generate/cpp_create_prim_instance_helper.py +102 -49
  233. mindspore/ops/auto_generate/gen_extend_func.py +281 -135
  234. mindspore/ops/auto_generate/gen_ops_def.py +2574 -2326
  235. mindspore/ops/auto_generate/gen_ops_prim.py +8566 -2755
  236. mindspore/ops/auto_generate/pyboost_inner_prim.py +106 -76
  237. mindspore/ops/composite/__init__.py +2 -1
  238. mindspore/ops/composite/base.py +19 -24
  239. mindspore/ops/composite/math_ops.py +6 -16
  240. mindspore/ops/composite/multitype_ops/__init__.py +5 -2
  241. mindspore/ops/composite/multitype_ops/_compile_utils.py +2 -3
  242. mindspore/ops/composite/multitype_ops/_constexpr_utils.py +1 -2
  243. mindspore/ops/composite/multitype_ops/add_impl.py +2 -1
  244. mindspore/ops/composite/multitype_ops/bitwise_and_impl.py +2 -1
  245. mindspore/ops/composite/multitype_ops/bitwise_or_impl.py +2 -1
  246. mindspore/ops/composite/multitype_ops/bitwise_xor_impl.py +2 -1
  247. mindspore/ops/composite/multitype_ops/div_impl.py +6 -4
  248. mindspore/ops/composite/multitype_ops/equal_impl.py +4 -3
  249. mindspore/ops/composite/multitype_ops/floordiv_impl.py +2 -1
  250. mindspore/ops/composite/multitype_ops/getitem_impl.py +3 -2
  251. mindspore/ops/composite/multitype_ops/greater_equal_impl.py +4 -3
  252. mindspore/ops/composite/multitype_ops/greater_impl.py +4 -3
  253. mindspore/ops/composite/multitype_ops/in_impl.py +2 -1
  254. mindspore/ops/composite/multitype_ops/invert_impl.py +50 -0
  255. mindspore/ops/composite/multitype_ops/left_shift_impl.py +2 -1
  256. mindspore/ops/composite/multitype_ops/less_equal_impl.py +4 -3
  257. mindspore/ops/composite/multitype_ops/less_impl.py +4 -3
  258. mindspore/ops/composite/multitype_ops/logic_not_impl.py +3 -2
  259. mindspore/ops/composite/multitype_ops/logical_and_impl.py +2 -1
  260. mindspore/ops/composite/multitype_ops/logical_or_impl.py +2 -1
  261. mindspore/ops/composite/multitype_ops/mod_impl.py +2 -1
  262. mindspore/ops/composite/multitype_ops/mul_impl.py +3 -2
  263. mindspore/ops/composite/multitype_ops/negative_impl.py +2 -1
  264. mindspore/ops/composite/multitype_ops/not_equal_impl.py +2 -1
  265. mindspore/ops/composite/multitype_ops/not_in_impl.py +2 -1
  266. mindspore/ops/composite/multitype_ops/ones_like_impl.py +18 -0
  267. mindspore/ops/composite/multitype_ops/pow_impl.py +2 -1
  268. mindspore/ops/composite/multitype_ops/right_shift_impl.py +2 -1
  269. mindspore/ops/composite/multitype_ops/setitem_impl.py +2 -1
  270. mindspore/ops/composite/multitype_ops/sub_impl.py +2 -1
  271. mindspore/ops/function/__init__.py +28 -2
  272. mindspore/ops/function/_add_attr_func.py +58 -0
  273. mindspore/ops/function/array_func.py +1629 -2345
  274. mindspore/ops/function/clip_func.py +38 -45
  275. mindspore/ops/function/debug_func.py +36 -44
  276. mindspore/ops/function/grad/__init__.py +1 -0
  277. mindspore/ops/function/grad/grad_func.py +104 -71
  278. mindspore/ops/function/image_func.py +1 -1
  279. mindspore/ops/function/linalg_func.py +46 -78
  280. mindspore/ops/function/math_func.py +3035 -3705
  281. mindspore/ops/function/nn_func.py +676 -241
  282. mindspore/ops/function/other_func.py +159 -1
  283. mindspore/ops/function/parameter_func.py +17 -30
  284. mindspore/ops/function/random_func.py +204 -361
  285. mindspore/ops/function/reshard_func.py +4 -70
  286. mindspore/ops/function/sparse_func.py +3 -3
  287. mindspore/ops/function/sparse_unary_func.py +5 -5
  288. mindspore/ops/function/spectral_func.py +25 -58
  289. mindspore/ops/function/vmap_func.py +24 -17
  290. mindspore/ops/functional.py +6 -4
  291. mindspore/ops/functional_overload.py +547 -4
  292. mindspore/ops/op_info_register.py +32 -244
  293. mindspore/ops/operations/__init__.py +10 -5
  294. mindspore/ops/operations/_custom_ops_utils.py +247 -0
  295. mindspore/ops/operations/_grad_ops.py +1 -10
  296. mindspore/ops/operations/_inner_ops.py +5 -76
  297. mindspore/ops/operations/_ms_kernel.py +4 -10
  298. mindspore/ops/operations/_rl_inner_ops.py +1 -1
  299. mindspore/ops/operations/_scalar_ops.py +3 -2
  300. mindspore/ops/operations/_sequence_ops.py +1 -1
  301. mindspore/ops/operations/_tensor_array.py +1 -1
  302. mindspore/ops/operations/array_ops.py +37 -22
  303. mindspore/ops/operations/comm_ops.py +150 -107
  304. mindspore/ops/operations/custom_ops.py +221 -23
  305. mindspore/ops/operations/debug_ops.py +115 -16
  306. mindspore/ops/operations/inner_ops.py +1 -1
  307. mindspore/ops/operations/linalg_ops.py +1 -58
  308. mindspore/ops/operations/manually_defined/_inner.py +1 -1
  309. mindspore/ops/operations/manually_defined/ops_def.py +746 -79
  310. mindspore/ops/operations/math_ops.py +21 -18
  311. mindspore/ops/operations/nn_ops.py +65 -191
  312. mindspore/ops/operations/other_ops.py +62 -9
  313. mindspore/ops/operations/random_ops.py +13 -7
  314. mindspore/ops/operations/reshard_ops.py +1 -1
  315. mindspore/ops/operations/sparse_ops.py +2 -2
  316. mindspore/ops/primitive.py +43 -32
  317. mindspore/ops/tensor_method.py +232 -13
  318. mindspore/ops_generate/__init__.py +0 -5
  319. mindspore/ops_generate/aclnn/__init__.py +0 -0
  320. mindspore/ops_generate/{aclnn_kernel_register_auto_cc_generator.py → aclnn/aclnn_kernel_register_auto_cc_generator.py} +43 -18
  321. mindspore/ops_generate/{gen_aclnn_implement.py → aclnn/gen_aclnn_implement.py} +49 -51
  322. mindspore/ops_generate/api/__init__.py +0 -0
  323. mindspore/ops_generate/{add_tensor_docs_generator.py → api/add_tensor_docs_generator.py} +9 -7
  324. mindspore/ops_generate/{cpp_create_prim_instance_helper_generator.py → api/cpp_create_prim_instance_helper_generator.py} +6 -9
  325. mindspore/ops_generate/{functional_map_cpp_generator.py → api/functional_map_cpp_generator.py} +25 -12
  326. mindspore/ops_generate/{functional_overload_py_generator.py → api/functional_overload_py_generator.py} +8 -6
  327. mindspore/ops_generate/{functions_cc_generator.py → api/functions_cc_generator.py} +14 -10
  328. mindspore/ops_generate/api/gen_api.py +103 -0
  329. mindspore/ops_generate/{op_api_proto.py → api/op_api_proto.py} +98 -69
  330. mindspore/ops_generate/{tensor_func_reg_cpp_generator.py → api/tensor_func_reg_cpp_generator.py} +82 -43
  331. mindspore/ops_generate/common/__init__.py +0 -0
  332. mindspore/ops_generate/common/gen_constants.py +91 -0
  333. mindspore/ops_generate/{gen_utils.py → common/gen_utils.py} +72 -19
  334. mindspore/ops_generate/{op_proto.py → common/op_proto.py} +64 -1
  335. mindspore/ops_generate/{template.py → common/template.py} +96 -84
  336. mindspore/ops_generate/gen_ops.py +23 -325
  337. mindspore/ops_generate/op_def/__init__.py +0 -0
  338. mindspore/ops_generate/op_def/gen_op_def.py +90 -0
  339. mindspore/ops_generate/{lite_ops_cpp_generator.py → op_def/lite_ops_cpp_generator.py} +47 -11
  340. mindspore/ops_generate/{ops_def_cc_generator.py → op_def/ops_def_cc_generator.py} +18 -7
  341. mindspore/ops_generate/{ops_def_h_generator.py → op_def/ops_def_h_generator.py} +5 -5
  342. mindspore/ops_generate/{ops_name_h_generator.py → op_def/ops_name_h_generator.py} +30 -15
  343. mindspore/ops_generate/op_def/ops_primitive_h_generator.py +125 -0
  344. mindspore/ops_generate/op_def_py/__init__.py +0 -0
  345. mindspore/ops_generate/op_def_py/gen_op_def_py.py +47 -0
  346. mindspore/ops_generate/{op_def_py_generator.py → op_def_py/op_def_py_generator.py} +6 -5
  347. mindspore/ops_generate/{op_prim_py_generator.py → op_def_py/op_prim_py_generator.py} +24 -15
  348. mindspore/ops_generate/pyboost/__init__.py +0 -0
  349. mindspore/ops_generate/{auto_grad_impl_cc_generator.py → pyboost/auto_grad_impl_cc_generator.py} +11 -7
  350. mindspore/ops_generate/{auto_grad_reg_cc_generator.py → pyboost/auto_grad_reg_cc_generator.py} +7 -7
  351. mindspore/ops_generate/{gen_pyboost_func.py → pyboost/gen_pyboost_func.py} +40 -16
  352. mindspore/ops_generate/{op_template_parser.py → pyboost/op_template_parser.py} +105 -24
  353. mindspore/ops_generate/{pyboost_functions_cpp_generator.py → pyboost/pyboost_functions_cpp_generator.py} +55 -18
  354. mindspore/ops_generate/{pyboost_functions_h_generator.py → pyboost/pyboost_functions_h_generator.py} +42 -10
  355. mindspore/ops_generate/{pyboost_functions_py_generator.py → pyboost/pyboost_functions_py_generator.py} +6 -6
  356. mindspore/ops_generate/{pyboost_grad_function_cpp_generator.py → pyboost/pyboost_grad_function_cpp_generator.py} +11 -10
  357. mindspore/ops_generate/{pyboost_inner_prim_generator.py → pyboost/pyboost_inner_prim_generator.py} +8 -7
  358. mindspore/ops_generate/{pyboost_native_grad_functions_generator.py → pyboost/pyboost_native_grad_functions_generator.py} +14 -10
  359. mindspore/ops_generate/{pyboost_op_cpp_code_generator.py → pyboost/pyboost_op_cpp_code_generator.py} +140 -53
  360. mindspore/ops_generate/{pyboost_overload_functions_cpp_generator.py → pyboost/pyboost_overload_functions_cpp_generator.py} +28 -15
  361. mindspore/ops_generate/{pyboost_utils.py → pyboost/pyboost_utils.py} +88 -4
  362. mindspore/ops_generate/resources/__init__.py +0 -0
  363. mindspore/ops_generate/resources/resource_list.py +30 -0
  364. mindspore/ops_generate/resources/resource_loader.py +36 -0
  365. mindspore/ops_generate/resources/resource_manager.py +64 -0
  366. mindspore/ops_generate/resources/yaml_loader.py +88 -0
  367. mindspore/ops_generate/tensor_py_cc_generator.py +122 -0
  368. mindspore/parallel/__init__.py +6 -2
  369. mindspore/parallel/_auto_parallel_context.py +133 -6
  370. mindspore/parallel/_cell_wrapper.py +130 -15
  371. mindspore/parallel/_parallel_serialization.py +95 -4
  372. mindspore/parallel/_ps_context.py +1 -1
  373. mindspore/parallel/_recovery_context.py +7 -2
  374. mindspore/parallel/_tensor.py +142 -18
  375. mindspore/parallel/_utils.py +198 -25
  376. mindspore/parallel/algo_parameter_config.py +3 -3
  377. mindspore/parallel/auto_parallel.py +732 -0
  378. mindspore/parallel/checkpoint_convert.py +159 -0
  379. mindspore/parallel/checkpoint_transform.py +656 -37
  380. mindspore/parallel/cluster/process_entity/_api.py +151 -19
  381. mindspore/parallel/cluster/run.py +1 -1
  382. mindspore/parallel/function/__init__.py +24 -0
  383. mindspore/parallel/function/reshard_func.py +259 -0
  384. mindspore/parallel/nn/__init__.py +25 -0
  385. mindspore/parallel/nn/parallel_cell_wrapper.py +263 -0
  386. mindspore/parallel/nn/parallel_grad_reducer.py +169 -0
  387. mindspore/parallel/parameter_broadcast.py +24 -13
  388. mindspore/parallel/shard.py +137 -61
  389. mindspore/parallel/transform_safetensors.py +287 -95
  390. mindspore/pgodb140.dll +0 -0
  391. mindspore/pgort140.dll +0 -0
  392. mindspore/profiler/__init__.py +9 -5
  393. mindspore/profiler/analysis/parser/ascend_cann_parser.py +6 -2
  394. mindspore/profiler/analysis/parser/ms_framework_parser.py +4 -4
  395. mindspore/profiler/analysis/parser/timeline_assembly_factory/ascend_timeline_assembler.py +7 -4
  396. mindspore/profiler/analysis/parser/timeline_assembly_factory/trace_view_container.py +22 -0
  397. mindspore/profiler/analysis/parser/timeline_creator/fwk_timeline_creator.py +3 -3
  398. mindspore/profiler/analysis/parser/timeline_event/fwk_event.py +241 -86
  399. mindspore/profiler/analysis/viewer/ascend_communication_viewer.py +41 -2
  400. mindspore/profiler/analysis/viewer/ascend_kernel_details_viewer.py +33 -35
  401. mindspore/profiler/analysis/viewer/ascend_memory_viewer.py +7 -0
  402. mindspore/profiler/analysis/viewer/ascend_op_memory_viewer.py +8 -3
  403. mindspore/profiler/analysis/viewer/ascend_step_trace_time_viewer.py +141 -30
  404. mindspore/profiler/analysis/viewer/ms_dataset_viewer.py +5 -6
  405. mindspore/profiler/common/ascend_msprof_exporter.py +5 -4
  406. mindspore/profiler/common/constant.py +12 -0
  407. mindspore/profiler/common/msprof_cmd_tool.py +42 -23
  408. mindspore/profiler/common/path_manager.py +24 -0
  409. mindspore/profiler/common/profiler_context.py +26 -2
  410. mindspore/profiler/common/profiler_meta_data.py +74 -0
  411. mindspore/profiler/common/profiler_parameters.py +59 -18
  412. mindspore/profiler/common/profiler_path_manager.py +66 -7
  413. mindspore/profiler/dynamic_profiler.py +112 -79
  414. mindspore/profiler/envprofiler.py +26 -1
  415. mindspore/profiler/experimental_config.py +197 -0
  416. mindspore/profiler/mstx.py +57 -14
  417. mindspore/profiler/platform/npu_profiler.py +33 -7
  418. mindspore/profiler/profiler.py +541 -45
  419. mindspore/profiler/profiler_action_controller.py +1 -1
  420. mindspore/profiler/profiler_interface.py +4 -0
  421. mindspore/profiler/schedule.py +57 -22
  422. mindspore/rewrite/api/node.py +15 -13
  423. mindspore/rewrite/api/symbol_tree.py +1 -1
  424. mindspore/run_check/_check_version.py +25 -14
  425. mindspore/run_check/run_check.py +1 -1
  426. mindspore/runtime/__init__.py +2 -2
  427. mindspore/runtime/executor.py +40 -11
  428. mindspore/runtime/memory.py +25 -8
  429. mindspore/safeguard/rewrite_obfuscation.py +12 -9
  430. mindspore/swresample-4.dll +0 -0
  431. mindspore/swscale-6.dll +0 -0
  432. mindspore/tbbmalloc.dll +0 -0
  433. mindspore/tinyxml2.dll +0 -0
  434. mindspore/train/__init__.py +8 -8
  435. mindspore/train/_utils.py +35 -7
  436. mindspore/train/amp.py +1 -1
  437. mindspore/train/callback/__init__.py +2 -2
  438. mindspore/train/callback/_callback.py +2 -16
  439. mindspore/train/callback/_checkpoint.py +24 -40
  440. mindspore/train/callback/_cluster_monitor.py +14 -18
  441. mindspore/train/callback/_flops_collector.py +2 -3
  442. mindspore/train/callback/_history.py +7 -4
  443. mindspore/train/callback/_lambda_callback.py +2 -2
  444. mindspore/train/callback/_landscape.py +0 -3
  445. mindspore/train/callback/_loss_monitor.py +2 -1
  446. mindspore/train/callback/_on_request_exit.py +6 -5
  447. mindspore/train/callback/_reduce_lr_on_plateau.py +11 -6
  448. mindspore/train/callback/_summary_collector.py +8 -13
  449. mindspore/train/callback/_time_monitor.py +2 -1
  450. mindspore/train/callback/{_tft_register.py → _train_fault_tolerance.py} +179 -103
  451. mindspore/train/data_sink.py +25 -2
  452. mindspore/train/dataset_helper.py +4 -5
  453. mindspore/train/loss_scale_manager.py +8 -7
  454. mindspore/train/metrics/accuracy.py +3 -3
  455. mindspore/train/metrics/confusion_matrix.py +9 -9
  456. mindspore/train/metrics/error.py +3 -3
  457. mindspore/train/metrics/hausdorff_distance.py +4 -4
  458. mindspore/train/metrics/mean_surface_distance.py +3 -3
  459. mindspore/train/metrics/metric.py +0 -12
  460. mindspore/train/metrics/occlusion_sensitivity.py +4 -2
  461. mindspore/train/metrics/precision.py +8 -6
  462. mindspore/train/metrics/recall.py +9 -9
  463. mindspore/train/metrics/root_mean_square_surface_distance.py +2 -2
  464. mindspore/train/mind_ir_pb2.py +19 -12
  465. mindspore/train/model.py +176 -103
  466. mindspore/train/serialization.py +246 -988
  467. mindspore/train/summary/_summary_adapter.py +2 -2
  468. mindspore/train/summary/summary_record.py +1 -1
  469. mindspore/turbojpeg.dll +0 -0
  470. mindspore/utils/__init__.py +3 -2
  471. mindspore/utils/dryrun.py +4 -2
  472. mindspore/utils/hooks.py +81 -0
  473. mindspore/utils/utils.py +138 -4
  474. mindspore/vcmeta.dll +0 -0
  475. mindspore/vcruntime140.dll +0 -0
  476. mindspore/vcruntime140_1.dll +0 -0
  477. mindspore/version.py +1 -1
  478. {mindspore-2.5.0.dist-info → mindspore-2.6.0rc1.dist-info}/METADATA +2 -1
  479. {mindspore-2.5.0.dist-info → mindspore-2.6.0rc1.dist-info}/RECORD +483 -438
  480. mindspore/_install_custom.py +0 -43
  481. mindspore/common/_register_for_adapter.py +0 -74
  482. mindspore/ops/auto_generate/gen_arg_dtype_cast.py +0 -252
  483. mindspore/ops/auto_generate/gen_arg_handler.py +0 -136
  484. mindspore/ops/operations/_opaque_predicate_registry.py +0 -41
  485. mindspore/ops_generate/gen_constants.py +0 -190
  486. mindspore/ops_generate/gen_ops_inner_prim.py +0 -131
  487. mindspore/ops_generate/ops_primitive_h_generator.py +0 -81
  488. /mindspore/ops_generate/{base_generator.py → common/base_generator.py} +0 -0
  489. {mindspore-2.5.0.dist-info → mindspore-2.6.0rc1.dist-info}/WHEEL +0 -0
  490. {mindspore-2.5.0.dist-info → mindspore-2.6.0rc1.dist-info}/entry_points.txt +0 -0
  491. {mindspore-2.5.0.dist-info → mindspore-2.6.0rc1.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,732 @@
1
+ # Copyright 2024-2025 Huawei Technologies Co., Ltd
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ # ============================================================================
15
+ """Cell of auto parallel"""
16
+ import os
17
+ from mindspore.nn.cell import Cell
18
+ from mindspore.parallel.shard import Layout
19
+ from mindspore.communication.management import get_rank, get_group_size
20
+
21
+
22
+ class AutoParallel(Cell):
23
+ """
24
+ Encapsulation of top-level Cells or functions to realize static graph parallelism for a single network.
25
+
26
+ Note:
27
+ - When using the `Model` API, the network passed to the `Model` must be wrapped with `AutoParallel`.
28
+ - When using `functional` API, the outermost layer must be wrapped with `AutoParallel`.
29
+ - When using `functional` API, data sinking mode are not currently supported.
30
+
31
+ Args:
32
+ network (Union[Cell, Function]): Top-level cell or function in the forward network. Defines the core
33
+ computational graph structure that will be parallelized.
34
+
35
+ parallel_mode (str, optional): Specifies the parallelization strategy engine. Available modes: ``"semi_auto"``,
36
+ ``"sharding_propagation"``, ``"recursive_programming"``. Default: ``"semi_auto"``.
37
+
38
+ - semi_auto: Achieves data and model parallelism by setting parallel strategies.
39
+
40
+ - sharding_propagation:
41
+ Automatic strategy propagation mode. Infers sharding strategies for non-annotated operators
42
+ based on configured operator strategies. Dynamic shapes are not supported currently.
43
+
44
+ - recursive_programming:
45
+ Full automatic parallelization mode. Dynamically generates parallel strategies through
46
+ recursive program analysis.
47
+
48
+ Supported Platforms:
49
+ ``Ascend``
50
+
51
+ Examples:
52
+ .. note::
53
+ You need to use the msrun command to run the following examples.
54
+
55
+ >>> import os
56
+ >>> import mindspore as ms
57
+ >>> import mindspore.dataset as ds
58
+ >>> from mindspore import nn, ops
59
+ >>> from mindspore.communication import init, get_rank
60
+ >>> from mindspore.common.initializer import initializer
61
+ >>> from mindspore.parallel.auto_parallel import AutoParallel
62
+ >>> from mindspore.train import Model
63
+ >>> from mindspore.train import LossMonitor
64
+ >>> ms.set_context(mode=ms.GRAPH_MODE)
65
+ >>> init()
66
+ >>> ms.set_seed(1)
67
+ >>>
68
+ >>> # Create the dataset taking MNIST as an example. Refer to
69
+ >>> # https://gitee.com/mindspore/docs/blob/master/docs/mindspore/code/mnist.py
70
+ >>>
71
+ >>> def create_dataset(batch_size):
72
+ ... dataset_path = os.getenv("DATA_PATH")
73
+ ... dataset = ds.MnistDataset(dataset_path)
74
+ ... image_transforms = [
75
+ ... ds.vision.Rescale(1.0 / 255.0, 0),
76
+ ... ds.vision.Normalize(mean=(0.1307,), std=(0.3081,)),
77
+ ... ds.vision.HWC2CHW()
78
+ ... ]
79
+ ... label_transform = ds.transforms.TypeCast(ms.int32)
80
+ ... dataset = dataset.map(image_transforms, 'image')
81
+ ... dataset = dataset.map(label_transform, 'label')
82
+ ... dataset = dataset.batch(batch_size)
83
+ ... return dataset
84
+ >>>
85
+ >>> dataset = create_dataset(32)
86
+ >>>
87
+ >>> from mindspore import nn, ops, Parameter
88
+ >>> from mindspore.common.initializer import initializer, HeUniform
89
+ >>> import math
90
+ >>>
91
+ >>> class MatMulCell(nn.Cell):
92
+ ... def __init__(self, param=None, shape=None):
93
+ ... super().__init__()
94
+ ... if shape is None:
95
+ ... shape = [28 * 28, 512]
96
+ ... weight_init = HeUniform(math.sqrt(5))
97
+ ... self.param = Parameter(initializer(weight_init, shape), name="param")
98
+ ... if param is not None:
99
+ ... self.param = param
100
+ ... self.print = ops.Print()
101
+ ... self.matmul = ops.MatMul()
102
+ ...
103
+ ... def construct(self, x):
104
+ ... out = self.matmul(x, self.param)
105
+ ... self.print("out is:", out)
106
+ ... return out
107
+ >>>
108
+ >>> class Network(nn.Cell):
109
+ ... def __init__(self):
110
+ ... super().__init__()
111
+ ... self.flatten = nn.Flatten()
112
+ ... self.layer1 = MatMulCell()
113
+ ... self.relu1 = nn.ReLU()
114
+ ... self.layer2 = nn.Dense(512, 512)
115
+ ... self.relu2 = nn.ReLU()
116
+ ... self.layer3 = nn.Dense(512, 10)
117
+ ...
118
+ ... def construct(self, x):
119
+ ... x = self.flatten(x)
120
+ ... x = self.layer1(x)
121
+ ... x = self.relu1(x)
122
+ ... x = self.layer2(x)
123
+ ... x = self.relu2(x)
124
+ ... logits = self.layer3(x)
125
+ ... return logits
126
+ >>>
127
+ >>> import mindspore as ms
128
+ >>> from mindspore import nn, ops
129
+ >>> from mindspore.parallel.nn import Pipeline, PipelineGradReducer
130
+ >>> from mindspore.nn.utils import no_init_parameters
131
+ >>>
132
+ >>> with no_init_parameters():
133
+ >>> net = Network()
134
+ >>> optimizer = nn.SGD(net.trainable_params(), 1e-2)
135
+ >>> pp_grad_reducer = PipelineGradReducer(optimizer.parameters, opt_shard=False)
136
+ >>>
137
+ >>> loss_fn = nn.CrossEntropyLoss()
138
+ >>> net_with_loss = Pipeline(nn.WithLossCell(net, loss_fn), 4, stage_config={"_backbone.flatten":0,
139
+ >>> "_backbone.layer1": 0, "_backbone.relu1": 0, "_backbone.layer2": 1,
140
+ >>> "_backbone.relu2": 1, "_backbone.layer3": 1})
141
+ >>> parallel_net = AutoParallel(net_with_loss, parallel_mode="semi_auto")
142
+ >>> parallel_net.hsdp()
143
+ >>> parallel_net.pipeline(stages=2)
144
+ >>> parallel_net.dataset_strategy("data_parallel")
145
+ >>> parallel_net.save_param_strategy_file(f"/tmp/param_{get_rank()}.ckpt")
146
+ >>> parallel_net.set_group_ckpt_save_file(f"/tmp/comm_group_{get_rank()}.ckpt")
147
+ >>> parallel_net.dump_local_norm(f"/tmp/local_norm_{get_rank()}")
148
+ >>> parallel_net.disable_strategy_file_only_for_trainable_params()
149
+ >>> parallel_net.enable_fp32_communication()
150
+ >>> parallel_net.enable_device_local_norm()
151
+ >>> parallel_net.enable_gradients_mean()
152
+ >>> parallel_net.disable_gradient_fp32_sync()
153
+ >>> parallel_net.disable_loss_repeated_mean()
154
+ >>>
155
+ >>> loss_monitor = LossMonitor(per_print_times=1)
156
+ >>> model = Model(network=parallel_net, optimizer=optimizer)
157
+ >>> model.train(epoch=2, train_dataset=dataset, callbacks=[loss_monitor])
158
+
159
+ """
160
+
161
+ def __init__(self, network, parallel_mode="semi_auto"):
162
+ super(AutoParallel, self).__init__(auto_prefix=False)
163
+ self.network = network
164
+
165
+ self._parallel_mode = parallel_mode
166
+
167
+ self._global_rank = get_rank()
168
+ self._device_num = get_group_size()
169
+
170
+ self._init_param_in_compile = True
171
+
172
+ self._load_strategy_file_path = ""
173
+ self._save_strategy_file_path = ""
174
+ self._only_trainable_params = True
175
+
176
+ self._load_operator_strategy_file = ""
177
+ self._save_operator_strategy_file = ""
178
+
179
+ self._dataset_strategy_config = "data_parallel"
180
+ self._full_batch = False
181
+
182
+ self._enable_parallel_optimizer = False
183
+ self._optimizer_weight_shard_size = -1
184
+ self._parallel_optimizer_threshold = 64
185
+ self._gradient_accumulation_shard = False
186
+
187
+ self._pipeline_stages = 1
188
+ self._pipeline_result_broadcast = False
189
+ self._pipeline_interleave = False
190
+ self._pipeline_scheduler = "1f1b"
191
+
192
+ self._comm_fusion_config = dict()
193
+
194
+ self._force_fp32_communication = False
195
+ self._enable_alltoall = True
196
+ self._parameter_broadcast = False
197
+ self._group_ckpt_save_file = ""
198
+
199
+ self._dump_local_norm = False
200
+ self._dump_local_norm_path = ""
201
+ self._dump_device_local_norm = False
202
+
203
+ self._gradients_mean = False
204
+ self._gradient_fp32_sync = True
205
+ self._loss_repeated_mean = True
206
+
207
+ self._memory_offload_config = dict()
208
+ self._transformer_opt_config = None
209
+
210
+ def no_init_parameters_in_compile(self):
211
+ """
212
+ When enabled, the model weight parameters will not be initialized during the compilation process.
213
+
214
+ .. warning::
215
+ This is an experimental interface, may be changed or canceled in the future.
216
+
217
+ Examples:
218
+ >>> from mindspore.parallel.auto_parallel import AutoParallel
219
+ >>> # Define the network structure of LeNet5. Refer to
220
+ >>> # https://gitee.com/mindspore/docs/blob/master/docs/mindspore/code/lenet.py
221
+ >>> net = LeNet5()
222
+ >>> parallel_net = AutoParallel(net, parallel_mode="semi_auto")
223
+ >>> parallel_net.no_init_parameters_in_compile()
224
+ """
225
+ self._init_param_in_compile = False
226
+
227
+ def load_param_strategy_file(self, file_path):
228
+ """
229
+ Set the path to load parallel sharding strategy file. By default, load strategy information for trainable
230
+ parameters only.
231
+
232
+ Args:
233
+ file_path (str): The path to load parameter strategy checkpoint.
234
+
235
+ Raises:
236
+ TypeError: If the type of 'file_path' is not str.
237
+
238
+ Examples:
239
+ >>> from mindspore.parallel.auto_parallel import AutoParallel
240
+ >>> parallel_net = AutoParallel(net)
241
+ >>> parallel_net.load_param_strategy_file(file_path="./train_strategy.ckpt")
242
+ """
243
+ if not isinstance(file_path, str):
244
+ raise TypeError("the argument 'file_path' must be str, but got the type : {} .".format(type(file_path)))
245
+ self._load_strategy_file_path = file_path
246
+
247
+ def save_param_strategy_file(self, file_path):
248
+ """
249
+ Set the path to save parallel sharding strategy file. By default, save strategy information for trainable
250
+ parameters only.
251
+
252
+ Args:
253
+ file_path (str): The path where the parallel sharding strategy is saved.
254
+
255
+ Raises:
256
+ TypeError: If the type of 'file_path' is not str.
257
+ """
258
+ if not isinstance(file_path, str):
259
+ raise TypeError("the argument 'file_path' must be str, but got the type : {} .".format(type(file_path)))
260
+ self._save_strategy_file_path = file_path
261
+
262
+ def disable_strategy_file_only_for_trainable_params(self):
263
+ """By default, MindSpore only loads and saves trainable parameters. This API enables the loading and saving of
264
+ non-trainable parameters as well."""
265
+ self._only_trainable_params = False
266
+
267
+ def save_operator_strategy_file(self, file_path):
268
+ """
269
+ Set the path to save strategy json when using sharding propagation.
270
+
271
+ .. warning::
272
+ This is an experimental interface, may be changed or canceled in the future;
273
+ This interface currently doesn't support saving strategies using layout.
274
+
275
+ Note:
276
+ - It only works when `parallel_mode=sharding_propagation`.
277
+ - When performing distributed training, users can first save the strategy using dryrun on a single device
278
+ and then load strategy to perform distributed training.
279
+
280
+ Args:
281
+ file_path (str): Path to save parallel strategy json, must be an absolute path.
282
+
283
+ Raises:
284
+ TypeError: If the type of 'file_path' is not str.
285
+ KeyError: When 'file_path' is not an absolute path.
286
+ KeyError: When 'file_path' does not end in ``".json"`` .
287
+
288
+ Examples:
289
+ >>> import math
290
+ >>> import mindspore as ms
291
+ >>> import numpy as np
292
+ >>> from mindspore import nn, ops
293
+ >>> from mindspore.communication.management import init
294
+ >>> from mindspore.parallel.auto_parallel import AutoParallel
295
+ >>> from mindspore.common.initializer import initializer, HeUniform
296
+ >>>
297
+ >>> class ParallelNetwork(nn.Cell):
298
+ ... def __init__(self, strategy=None):
299
+ ... super().__init__()
300
+ ... self.flatten = ops.Flatten()
301
+ ... self.fc1_weight = ms.Parameter(initializer(HeUniform(math.sqrt(5)), shape=[
302
+ ... 16, 10], dtype=ms.float32), name="fc1")
303
+ ... self.matmul1 = ops.MatMul().shard(strategy)
304
+ ... self.relu1 = ops.ReLU()
305
+ ...
306
+ ... def construct(self, x):
307
+ ... x = self.flatten(x)
308
+ ... x = self.matmul1(x, self.fc1_weight)
309
+ ... x = self.relu1(x)
310
+ ... return x
311
+ >>>
312
+ >>> init(backend_name='hccl')
313
+ >>> strategy = ((1, 1), (1, 2))
314
+ >>> net = ParallelNetwork(strategy)
315
+ >>> parallel_net = AutoParallel(net, parallel_mode='sharding_propagation')
316
+ >>> parallel_net.save_operator_strategy_file("/tmp/strategy.json")
317
+ """
318
+ if not isinstance(file_path, str):
319
+ raise TypeError("the argument 'file_path' must be str, but got the type : {} .".format(type(file_path)))
320
+ if not os.path.isabs(file_path):
321
+ raise KeyError("the argument 'file_path' must be an absolute path.")
322
+ _, file_type = os.path.splitext(file_path)
323
+ if file_type != ".json":
324
+ raise KeyError("File type must be .json")
325
+ self._save_operator_strategy_file = file_path
326
+
327
+ def load_operator_strategy_file(self, file_path):
328
+ """
329
+ Set the path to load strategy json when using sharding propagation.
330
+
331
+ .. warning::
332
+ This is an experimental interface, may be changed or canceled in the future;
333
+ This interface currently doesn't support loading strategies using layout.
334
+
335
+ Note:
336
+ - It only works when `parallel_mode=sharding_propagation`.
337
+ - When performing distributed training, users can first save the strategy using dryrun on a single device
338
+ and then load strategy to perform distributed training.
339
+
340
+ Args:
341
+ file_path (str): Path to load parallel strategy json, must be an absolute path.
342
+
343
+ Raises:
344
+ TypeError: If the type of 'file_path' is not str.
345
+ KeyError: When 'file_path' is not an absolute path.
346
+ KeyError: When 'file_path' does not end in ``".json"`` .
347
+
348
+ Examples:
349
+ >>> import math
350
+ >>> import mindspore as ms
351
+ >>> import numpy as np
352
+ >>> from mindspore import nn, ops
353
+ >>> from mindspore.communication.management import init
354
+ >>> from mindspore.parallel.auto_parallel import AutoParallel
355
+ >>> from mindspore.common.initializer import initializer, HeUniform
356
+ >>>
357
+ >>> class ParallelNetwork(nn.Cell):
358
+ ... def __init__(self, strategy=None):
359
+ ... super().__init__()
360
+ ... self.flatten = ops.Flatten()
361
+ ... self.fc1_weight = ms.Parameter(initializer(HeUniform(math.sqrt(5)), shape=[
362
+ ... 16, 10], dtype=ms.float32), name="fc1")
363
+ ... self.matmul1 = ops.MatMul().shard(strategy)
364
+ ... self.relu1 = ops.ReLU()
365
+ ...
366
+ ... def construct(self, x):
367
+ ... x = self.flatten(x)
368
+ ... x = self.matmul1(x, self.fc1_weight)
369
+ ... x = self.relu1(x)
370
+ ... return x
371
+ >>>
372
+ >>> init(backend_name='hccl')
373
+ >>> strategy = ((1, 1), (1, 2))
374
+ >>> net = ParallelNetwork(strategy)
375
+ >>> parallel_net = AutoParallel(net, parallel_mode='sharding_propagation')
376
+ >>> parallel_net.load_operator_strategy_file("/tmp/strategy.json")
377
+ """
378
+ if not isinstance(file_path, str):
379
+ raise TypeError("the argument 'file_path' must be str, but got the type : {} .".format(type(file_path)))
380
+ if not os.path.isabs(file_path):
381
+ raise KeyError("the argument 'file_path' must be an absolute path.")
382
+ _, file_type = os.path.splitext(file_path)
383
+ if file_type != ".json":
384
+ raise KeyError("File type must be .json")
385
+ self._load_operator_strategy_file = file_path
386
+
387
+ def dataset_strategy(self, config):
388
+ """
389
+ Set dataset sharding strategy.
390
+
391
+ Args:
392
+ config (Union[str, tuple(tuple), tuple(Layout)]): The dataset sharding strategy. Default: "data_parallel".
393
+ If you want to split dataset across devices, you can set the dataset strategy as "data_parallel".
394
+ If you load whole batch datasets, you need to set the dataset strategy as "full_batch".
395
+ For dataset load into net by dataset strategy like ds_stra((1, 8), (1, 8)),it requires using
396
+ AutoParallel.dataset_strategy(ds_stra).Besides, dataset strategy also supports tuple of Layout.
397
+
398
+ Raises:
399
+ TypeError: When 'config' is not str type nor tuple type.
400
+ TypeError: If 'config' is tuple type, but its element is not tuple type nor Layout type.
401
+ TypeError: If 'config' is tuple type and its element is tuple type, the element in subtuple isn't int type.
402
+ ValueError: If 'config' is None.
403
+ ValueError: If the type of 'config' is str, but it's value is not 'full_batch' or 'data_parallel'.
404
+ """
405
+ if config is None:
406
+ raise ValueError("dataset_strategy is none in config!")
407
+
408
+ if isinstance(config, str):
409
+ if config not in ("full_batch", "data_parallel"):
410
+ raise ValueError("For 'AutoParallel.dataset_strategy', the argument "
411
+ "'config' must be 'full_batch' or 'data_parallel', but got the value : {}."
412
+ .format(config))
413
+ self._full_batch = (config == "full_batch")
414
+ self._dataset_strategy_config = config
415
+ return
416
+ if not isinstance(config, tuple):
417
+ raise TypeError("For 'AutoParallel.dataset_strategy', the argument 'config' "
418
+ "must be str or tuple type, but got the type : {}.".format(type(config)))
419
+ for ele in config:
420
+ if isinstance(ele, tuple):
421
+ for dim in ele:
422
+ if not isinstance(dim, int):
423
+ raise TypeError("For 'AutoParallel.dataset_strategy', the element of argument "
424
+ "'config' must be int type, but got the type : {} .".format(type(dim)))
425
+ elif isinstance(ele, Layout):
426
+ pass
427
+ else:
428
+ raise TypeError("For 'AutoParallel.dataset_strategy', the element of argument "
429
+ "'config' must be tuple or Layout, but got the type : {} .".format(type(ele)))
430
+ self._dataset_strategy_config = config
431
+
432
+ def hsdp(self, shard_size=-1, threshold=64, optimizer_level="level1"):
433
+ r"""
434
+ Set optimizer parallel configs.
435
+
436
+ Args:
437
+ shard_size (int, optional): Set the optimizer weight shard group size if you want to specific the
438
+ maximum group size across devices when the parallel optimizer is
439
+ enabled. The numerical range can be (0, device_num]. Default value
440
+ is -1, which means the optimizer weight shard group size will
441
+ the data parallel group of each parameter. Default ``-1``.
442
+ threshold (int, optional): Set the threshold of parallel optimizer. When parallel optimizer is
443
+ enabled, parameters with size smaller than this threshold will not be
444
+ sharded across the devices. Parameter size = shape[0] \* ... \*
445
+ shape[n] \* size(dtype). Non-negative. Unit: KB. Default: 64.
446
+ optimizer_level (str, optional): optimizer_level configuration is used to specify
447
+ the splitting level for optimizer sharding. It is important to note that the implementation
448
+ of optimizer sharding in static graph is inconsistent with dynamic graph like megatron,
449
+ but the memory optimization effect is the same.
450
+ It must be one of [ ``level1``, ``level2``, ``level3`` ]. Default: ``level1``.
451
+
452
+ - level1:
453
+ Splitting is performed on weights and optimizer state.
454
+ - level2:
455
+ Splitting is performed on weights, optimizer state, and gradients.
456
+ - level3:
457
+ Splitting is performed on weights, optimizer state,
458
+ gradients, additionally, before the backward pass, the weights are further applied with
459
+ allgather communication to release the memory used by the forward pass allgather.
460
+
461
+
462
+ Raises:
463
+ ValueError: If the `shard_size` is not a positive integer or -1.
464
+ ValueError: If `threshold` is not a positive integer or 0.
465
+ ValueError: If `optimizer_level` is not one of the [ ``level1``, ``level2``, ``level3`` ].
466
+ """
467
+ self._enable_parallel_optimizer = True
468
+ if not isinstance(shard_size, int) or (shard_size <= 0 and shard_size != -1):
469
+ raise ValueError("shard_size must be a positive integer or -1, but got {}.".format(shard_size))
470
+ self._optimizer_weight_shard_size = shard_size
471
+ if not isinstance(threshold, int) or threshold < 0:
472
+ raise ValueError("threshold must be a positive integer or 0, but got {}.".format(threshold))
473
+ self._parallel_optimizer_threshold = threshold
474
+ if optimizer_level not in ["level1", "level2", "level3"]:
475
+ raise ValueError("Optimizer level should in ['level1', 'level2', 'level3'], but got {}"
476
+ .format(optimizer_level))
477
+ self._optimizer_level = optimizer_level
478
+
479
+ def pipeline(self, stages=1, output_broadcast=False, interleave=False,
480
+ scheduler="1f1b"):
481
+ """
482
+ Configure the number of pipelin_dages, whether to broadcast the results,
483
+ whether to enable interleaving scheduling, configure type of scheduler when using pipeline parallel.
484
+
485
+ Args:
486
+ stages (int, optional): Set the stage information for pipeline parallelism
487
+ This indicates how the devices are individually distributed on the pipeline.
488
+ All devices will be divided into stages of pipine_dags. Default value: 1.
489
+ output_broadcast (bool, optional): When performing pipeline parallel inference,
490
+ whether the result of the last stage is broadcasted to the other stages. Default value: False.
491
+ interleave (bool, optional): Whether to enable interleaving scheduling.
492
+ scheduler(str, optional): The type of scheduler
493
+ Raises:
494
+ TypeError: If the type of 'stages is not int.
495
+ ValueError: When stages <= 0.
496
+ TypeError: If the type of 'output_broadcast' is not bool.
497
+ TypeError: If the type of 'interleave' is not bool.
498
+ TypeError: If the type of 'scheduler' is not str.
499
+ ValueError: If the type of 'scheduler' is not supported.
500
+ """
501
+ if not isinstance(stages, int):
502
+ raise TypeError("For 'AutoParallel.pipeline', the argument 'stages' "
503
+ "must be int type, but got the type : {}.".format(type(stages)))
504
+ if stages <= 0:
505
+ raise ValueError("For 'AutoParallel.pipeline', the argument 'stages' "
506
+ "must be larger than zero, but got value: {}.".format(stages))
507
+ if not isinstance(output_broadcast, bool):
508
+ raise TypeError("For 'AutoParallel.pipeline', the argument 'stages' "
509
+ "must be bool type, but got the type : {}.".format(type(output_broadcast)))
510
+ if not isinstance(interleave, bool):
511
+ raise TypeError("For 'AutoParallel.pipeline', the argument 'stages' "
512
+ "must be bool type, but got the type : {}.".format(type(interleave)))
513
+ if not isinstance(scheduler, str):
514
+ raise TypeError("For 'AutoParallel.pipeline', the argument 'stages' "
515
+ "must be str type, but got the type : {}.".format(type(scheduler)))
516
+ if scheduler not in ("1f1b", "gpipe"):
517
+ raise ValueError("For 'AutoParallel.pipeline', the argument "
518
+ "'scheduler' must be '1f1b' , 'gpipe' , but got the value : {}."
519
+ .format(scheduler))
520
+ self._pipeline_stages = stages
521
+ self._pipeline_result_broadcast = output_broadcast
522
+ self._pipeline_interleave = interleave
523
+ self._pipeline_scheduler = scheduler
524
+
525
+ def comm_fusion(self, config):
526
+ r"""
527
+ Set fusion configuration of parallel communication operators.
528
+
529
+ Args:
530
+ config (dict): A dict contains the types and configurations for setting the communication fusion. Each
531
+ communication fusion config has two keys: "mode" and "config".
532
+ It supports following communication fusion types and configurations:
533
+
534
+ - openstate: Whether turn on the communication fusion or not. If `openstate` is `True`, turn on
535
+ the communication fusion, otherwise, turn off the communication fusion. Default: `True`.
536
+
537
+ - allreduce: if communication fusion type is `allreduce`. The `mode` contains: `auto`, `size`
538
+ and `index`. In `auto` mode, allreduce fusion is configured by gradients size, and the default
539
+ fusion threshold is `64` MB. In 'size' mode, allreduce fusion is configured by gradients size
540
+ manually, and the fusion threshold must be larger than `0` MB. In `index` mode, it is same as
541
+ `all_reduce_fusion_config`.
542
+
543
+ - allgather: If communication fusion type is `allgather`. The `mode` contains: `auto`, `size`.
544
+ In `auto` mode, AllGather fusion is configured by gradients size, and the default fusion
545
+ threshold is `64` MB. In 'size' mode, AllGather fusion is configured by gradients size
546
+ manually, and the fusion threshold must be larger than `0` MB.
547
+
548
+ - reducescatter: If communication fusion type is `reducescatter`. The `mode` contains: `auto`
549
+ and `size`. Config is same as `allgather`.
550
+
551
+ Raises:
552
+ TypeError: If the type of config is not dict.
553
+
554
+ Examples:
555
+ >>> from mindspore.parallel.auto_parallel import AutoParallel
556
+ >>> # Define the network structure of LeNet5. Refer to
557
+ >>> # https://gitee.com/mindspore/docs/blob/master/docs/mindspore/code/lenet.py
558
+ >>> parallel_net = AutoParallel(net, parallel_mode="semi_auto")
559
+ >>> comm_config = {"openstate": True, "allreduce": {"mode": "auto", "config": None}}
560
+ >>> net.comm_fusion(config=comm_config)
561
+ """
562
+ if config is not None and not isinstance(config, dict):
563
+ raise TypeError(f"The parameter '{config}' must be {dict}, but got {type(config)}.")
564
+ self._comm_fusion_config = config
565
+
566
+ def enable_fp32_communication(self):
567
+ """
568
+ Enable reduce operators (AllReduce, ReduceScatter) are forced to use the fp32 data type for communication
569
+ during communication.
570
+ """
571
+ self._force_fp32_communication = True
572
+
573
+ def set_group_ckpt_save_file(self, file_path):
574
+ """
575
+ Set the save path of the communication group.
576
+
577
+ Args:
578
+ file_path (str): The path to save parallel group checkpoint.
579
+
580
+ Raises:
581
+ TypeError: If the type of 'file_path' is not str.
582
+ """
583
+ if not isinstance(file_path, str):
584
+ raise TypeError("the argument 'file_path' must be str, but got the type : {} .".format(type(file_path)))
585
+ self._group_ckpt_save_file = file_path
586
+
587
+ def print_local_norm(self):
588
+ """
589
+ Print local norm value for auto parallel.
590
+
591
+ Examples:
592
+ >>> from mindspore.parallel.auto_parallel import AutoParallel
593
+ >>> # Define the network structure of LeNet5. Refer to
594
+ >>> # https://gitee.com/mindspore/docs/blob/master/docs/mindspore/code/lenet.py
595
+ >>> net = LeNet5()
596
+ >>> parallel_net = AutoParallel(net, parallel_mode="semi_auto")
597
+ >>> parallel_net.print_local_norm()
598
+ """
599
+ self._dump_local_norm = True
600
+
601
+ def dump_local_norm(self, file_path):
602
+ """
603
+ Enable local norm printing with disk storage only (no console output).
604
+
605
+ Args:
606
+ file_path (str): The path to save local_norm.
607
+
608
+ Raises:
609
+ TypeError: If the type of 'file_path' is not str.
610
+ """
611
+ if not isinstance(file_path, str):
612
+ raise TypeError("the argument 'file_path' must be str, but got the type : {} .".format(type(file_path)))
613
+ self._dump_local_norm = True
614
+ self._dump_local_norm_path = file_path
615
+
616
+ def enable_device_local_norm(self):
617
+ """
618
+ Enable device local norm printing.
619
+ """
620
+ self._dump_device_local_norm = True
621
+
622
+ def enable_gradients_mean(self):
623
+ """
624
+ Perform mean operator after allreduce of gradients in parallel mode.
625
+ """
626
+ self._gradients_mean = True
627
+
628
+ def disable_gradient_fp32_sync(self):
629
+ """
630
+ Disable convert tensor type from fp16 to fp32 before parameter gradients allreduce.
631
+ """
632
+ self._gradient_fp32_sync = False
633
+
634
+ def disable_loss_repeated_mean(self):
635
+ """
636
+ The mean operator is not executed backwards when the calculation is repeated.
637
+ """
638
+ self._loss_repeated_mean = False
639
+
640
+ def get_pipeline_stages(self):
641
+ """
642
+ Get the stages of net.
643
+ """
644
+ return self._pipeline_stages
645
+
646
+ def transformer_opt(self, file_path):
647
+ r"""
648
+ Check and set speedup config for auto parallel, configuration can refer to `parallel_speed_up.json
649
+ <https://gitee.com/mindspore/mindspore/blob/master/config/parallel_speed_up.json>`_ .
650
+ If this parameter is set to None, it is disabled.
651
+
652
+ Args:
653
+ file_path(Union[str, None]): The path to the parallel speed up json file, configuration can refer to
654
+ `parallel_speed_up.json
655
+ <https://gitee.com/mindspore/mindspore/blob/master/config/parallel_speed_up.json>`_ .
656
+ If its value is None or '', it does not take effect. Default None.
657
+
658
+ - recomputation_communication_overlap (bool): Enable overlap between recompute ops and communication ops
659
+ if True.
660
+ Default: False.
661
+ - grad_matmul_communication_overlap (bool): Enable overlap between dw matmul and
662
+ tensor parallel communication ops if True. Default: False.
663
+ - grad_fa_allgather_overlap (bool): Enable overlap between duplicated allgather by recomputing
664
+ in sequence parallel and flashattentionscoregrad ops if True. Default: False.
665
+ - enable_communication_fusion (bool): Enable communication fusion to optimize the number of
666
+ communication operator tasks if True.
667
+ Default: False.
668
+ - grad_computation_allreduce_overlap (bool): Enable overlap between dx ops and data parallel
669
+ communication ops if True.
670
+ Currently, do not support
671
+ `O2 <https://www.mindspore.cn/docs/en/master/api_python/mindspore/mindspore.JitConfig.html>`_
672
+ Default: False.
673
+ - computation_allgather_overlap (bool): Enable overlap between forward ops
674
+ and optimizer parallel allgather communication if True. Currently, do not support
675
+ `O2 <https://www.mindspore.cn/docs/en/master/api_python/mindspore/mindspore.JitConfig.html>`_
676
+ Default: False.
677
+ - computation_communication_fusion_level (int): Enable the fusion between compute and communicate.
678
+ Default: ``0``. Note: This function must be used with Ascend Training Solution 24.0.RC2 or later.
679
+ This is an experimental configuration, may be changed or canceled in the future.
680
+
681
+ - 0: Disable fusion.
682
+
683
+ - 1: Apply fusion to forward nodes.
684
+
685
+ - 2: Apply fusion to backward nodes.
686
+
687
+ - 3: Apply fusion to all nodes.
688
+ - dataset_broadcast_opt_level (int): Optimize the scenario that the dataset repeated reading. Only
689
+ support O0/O1 jit level. It doesn't work in O2 mode. Default: ``0``.
690
+
691
+ - 0: Disable this optimize.
692
+
693
+ - 1: Optimize dataset reader between pipeline stage.
694
+
695
+ - 2: Optimize dataset reader within pipeline stage.
696
+
697
+ - 3: Optimize dataset reader with all scenes.
698
+ - allreduce_and_biasadd_swap (bool): Enable node execution order swap communication operators and add
699
+ operators if ``True``. Only 1-dimension bias node is supported. Default: ``False``.
700
+ - enable_allreduce_slice_to_reducescatter (bool): Enable allreduce optimization. In the scenario where
701
+ the batchmatmul model introduces allreduce in parallel, if the subsequent nodes are stridedslice
702
+ operator with model parallel, allreduce will be optimized as reducescatter according to the identified
703
+ patterns. Typical used in MoE module with groupwise alltoall. Default: ``False``.
704
+ - enable_interleave_split_concat_branch (bool): Enable communication computation parallel optimization
705
+ for branches formed by split and concat operators with ``enable_interleave`` attribute. It is typical
706
+ used in MoE parallel scenario. After splitting the input data, each slice of data is processed by the
707
+ MoE module, and then the branch results are concatenated. When the optimization is enable,
708
+ communication and computation will be executed in parallel between branches. Default: ``False``.
709
+ - enable_interleave_parallel_branch (bool): Enable communication computation parallel optimization
710
+ for parallel branches with ``parallel_branch`` attribute in branches merge node. It is typical
711
+ used in MoE parallel scenario with routed and shared expert. When the optimization is enable,
712
+ communication and computation will be executed in parallel between branches. Default: ``False``.
713
+
714
+ Examples:
715
+ >>> from mindspore.parallel.auto_parallel import AutoParallel
716
+ >>>
717
+ >>> # Define the network structure of LeNet5. Refer to
718
+ >>> # https://gitee.com/mindspore/docs/blob/master/docs/mindspore/code/lenet.py
719
+ >>> net = LeNet5()
720
+ >>> net = AutoParallel(net, parallel_mode="semi_auto")
721
+ >>> net.transformer_opt("./parallel_speed_up.json")
722
+ """
723
+ # disable pylint too broad Exception
724
+ # pylint: disable=W0212
725
+ from mindspore.context import _context
726
+ ctx = _context()
727
+ ctx._set_speedup_config_path(file_path)
728
+ self._transformer_opt_config = file_path
729
+ ctx.ascend_config['parallel_speed_up_json_path'] = file_path
730
+
731
+ def construct(self, *args, **kwargs):
732
+ return self.network(*args, **kwargs)