MegEngine v1.7.0 Release Notes

MegEngine

HighLight

  • dump_with_testcase_mge.py 脚本删除,功能都挪入 megengine.jit.trace.dump 中,使用请参考 导出序列化模型文件
  • MgeConvert 可将 mge/TracedModule 模型转换为第三方模型文件,支持 Caffe、TFLite 和 ONNX 框架。使用参考 ReadMe

Bug Fixes

通用组件

  • 修复python3.8下的语法问题。
  • 修复学习率不能为0的问题。
  • 增加指数操作特判逻辑以保证结果的一致性,如x2和x*x,x3和xxx等的一致性。
  • 修复了业务线 det int4 模型在全局图优化 dump 时的问题。修复后全局图优化会检查 opr 的 format,若 format 不匹配 nchw 就不做全局图优化。
  • 解决 tensor.mean() 在以 fp32 计算,fp16 输出时溢出的问题。
  • 修复求导规则失败后异常过多的问题,通过条件判断仅输出必要异常,便于 gdb 调试。
  • 修复无法将 tensor 转换为量化 int4 类型的问题。
  • 修复禁止 DTR 功能时未释放相关资源的问题。
  • 解决 DTR 平方根采样不随机的问题,解决后 resnet1202 训练速度可提升5%。
  • 删除 DTR 中所有 swap 接口。
  • 显存分配默认开启去碎片功能,去除 enable_defrag 接口。
  • 修复scripts/cmake-build/*.sh脚本-n参数。
  • 使用官方构建脚本构建nccl。
  • 修复让 fbs 序列化使用正确的版本号。
  • imperative中支持设置fast-run的workspace限制,以解决开 fastrun 训练 OOM 问题。
  • 修复 megengine.functional.nn.layer_norm 在 AMP 上的运行错误。

CUDA

  • 当 CUBLAS_VERSION < 11200( CUBLAS 版本低于 11.2 )且 batch 为 1 时,如果 shape 过大,则关闭 cublas batched matmul 算法,避免运行崩溃。
  • 修复使 kernel size 较大时(例如 160x160 ),可找到正确的算法。
  • 修复 CUDA 下卷积 illegal memory access 的问题。
  • 修复 cuda11 下,部分模型 cudnnConvBiasActivation 崩溃的问题。
  • 修复带 BatchConvBias 的模型开启 nchw32 图优化时模型运行报错的问题。

python API

  • 添加 layer_norm API 文档。
  • megengine.utils.module_stats 支持字典输入。
  • megengine.functional.full :修改返回值的 dtype 为传入的数字的 dtype ,而不是默认 float32 。
  • 修复使用 PReLU 的模型无法被 trace 的问题。

基础组件

  • 优化 low bit 类型的信息描述。
  • 修复使 module 的 tensors 和 named_tensors 接口只返回 Tensor 类型的数据。
  • 修复 gcc 和 clang 编译选项没对齐带来的精度问题。

周边工具

  • 使用load and run 工具推理增加支持 u16 和 s16 输入数据。
  • 修复 load_and_run 获取模型内存 「--get-static-mem-info」 选项不生效的问题。

x86

  • 修复 conv_bias Operator 计算错误问题。

发版流程

  • 修复在 TracedModule 中插入自定义 QATModule 后 trace 状态有误的问题。
  • 修复 TracedModule 拍平之后的图中部分 Node 未重命名。
  • 修复 TracedModule 无法插入 _name 属性相同的 Module 。
  • 修复让不在megengine.functional.nn 里定义的函数可被 TracedModule 正确地 trace 。
  • TracedModule 中修复 module dict 遍历操作无法被 trace 的问题。
  • 修复使用相同 tensor node 的 functional 调用时 flatten 时 node.users 不正确的问题。

OpenCL

  • 修改OpenCL算法搜索的cache更新策略,当cache key一样时用最新的而不是之前的,以解决更换cache触发了从source编译kernel,导致运行速度变慢的问题。

Compatibility violation

ARM

  • 优化Arm中Sigmoid的计算性能。

New Features

Python API

  • 增加 pixel_shuffle opr 。
  • megengine.random.permutation 增加支持 Tensor 输入。
  • 增加megengine.random.shuffle opr 。
  • 添加 layer_norm 的支持。
  • 增加 megengine.functional.nn.hinge_loss
  • 增加 megengine.functional.nn.pad
  • megengine.functional.nn.local_response_norm 在 Functional 和 Module 中添加 LRN(局部相应归一化)支持。
  • megengine.functional.nn.conv_transpose2d megengine.functional.nn.conv_transpose3d 增加 group 参数支持。

通用组件

  • 添加 megengine.coalesce_free_memory 接口,用于回收空闲内存。
  • 修复 module.PixelShuffle 报错问题。
  • 支持构造 uint16 tensor 。
  • BatchNorm 添加支持 NHWC format 。
  • 支持 bazel 编译 flatbuffer ,使用编译参数 --copt “-DMGB_ENABLE_FBS_SERIALIZATION=1” 编译的 load and run 可以运行开源版本 MegEngine dump 的模型。
  • 支持在 windows 上直接使用 MegEngine 的动态库以减少 windows 中 whl 包的大小。
  • 修复同一个进程中同时使用 MegEngine 和 Pytorch 崩溃问题。
  • 训练时自动打开 defrag 功能,显存不够且显存碎片严重时可合并显存碎片。
  • 支持 record 模式中输出 tensor 的内存地址可自定义修改。
  • megengine.functional.nn.cvt_color OPR 增加 bgr2gray mode 。

周边工具

  • 删除 dump_with_testcase_mge.py,将其功能放在jit.dump接口中。
  • 为 SmallVector 等 MegEngine 自定义容器增加调试脚本,在 gdb 调试时可以查看容器内容,如下图所示。注意:gdb 只有在 MegBrain 根目录运行的时候才自动有效。

基础组件

  • Reduce 算子支持 nchw44 format 。
  • Elemwise 算子支持 nchw88 的 format 。
  • 针对nhwc int8 conv,添加融合 conv 和 typecvt 图优化。
  • megengine.optimizer.SGD 增加 nesterov momentum 支持。
  • 支持 C++ 模型内存/显存可视化。

ARM

  • 优化非连续情况下的transpose性能,在aarch64 下加速比 1.3。
  • Arm 平台支持 NHWC Int16 输入,fp32 输出的 elemwise。
  • 增加支持了 nchw、nchw44+fp32、nchw88+fp16 的 linear 的 upsample2 ,大幅优化了 ARM 上 linear resize 性能。
  • 优化 channel wise conv 实现,在 feature map 较小时有 1.5x 加速。
  • conv 加入 nchw88 format 的 fp16 支持。
  • 优化 arm 中非连续的 relayout kernel,在开启 record 的情况下推理平均用时在 sdm660 上可以减少约 50% ; subtensor opr 的用时占比减少约70% 。
  • 优化 Arm Elemwise 中 N1HW 的 broadcast 情况,单个计算性能有 1 倍以上提升。

X86

  • X86下添加 reproduceable 属性的 6x16 的 matmul 支持。

CUDA

  • BatchNorm 算子支持 nhwc format 。

发版流程

  • TracedModule node 命名规则变更, 对 expr 的 GetAttr 根据目的进行融合。
    node 修改为 name 、qualname 两个名字,命名规则参见如下规则。node._name 用法不变,node._orig_name 需要修改为 node.qualname 使用 。
    qualname
    • 通过 qualname 可以找到该 Node 是哪个 Module 或 Module 中第几个操作产生了该 Tensor 或 Module。
    • 当 Node 所对应的 Tensor 或 Module 是模型的 attribute 时,qualname 与 attribute 的路径一致。
    • 当 Node 所对应的 Tensor 是通过调用一个 Module 而生成时,qualname = 该 Module 的在模型中的路径 + “.[out]”。
    • 当 Node 所对应的 Tensor 是通过调用一个 function 而生成时,qualname = 该 Node 所在 Graph 的 qualname + “.[func_函数名_函数在当前 Module 中的调用次数]”。
    • 当 Node 所对应的 Tensor 是通过调用某个 Tensor 的 method 而生成时,qualname = 该 Node 所在 Graph 的 qualname + “.[method_方法名_该方法在当前 Module 中的调用次数]”。
    • 当 Node 所对应的 Tensor 是通过调用一个 opdef 而生成时,qualname = 该 Node 所在 Graph 的 qualname + “.[def_opdef名_该 opdef 在当前 Module 中的调用次数]”。
    • 其它:qualname = 该 Node 所在 Graph 的 qualname +"[.Node的名字]"。 name:
    • 如果该 Node 所对应的 Tensor 或 Module 是模型的 attribute,name 为 Node 的 qualname 与 Graph 的 qualname 的 “差值” 去重后得到, 则 name = Node 的qualname - Node 所在 Graph 的qualname。例如:ResNet18.layer1.block0.conv- ResNet18.layer1 = block0.conv → block0_conv → block0_conv + 去重后缀。
    • 当 Node 所对应的 Tensor 是通过调用一个 Module 而生成时,name qualname = 该 Module 所对应 ModuleNode 的 name + “_out” + 去重后缀。
    • 当 Node 所对应的 Tensor 是通过调用一个 function 而生成时,qualname = 函数名 + “_out” + 去重后缀。
    • 当 Node 所对应的 Tensor 是通过调用某个 Tensor 的 method 而生成时,qualname = 方法名 + “_out” + 去重后缀。
    • 当 Node 所对应的 Tensor 是通过调用一个 opdef 而生成时,qualname = opdef名 + “_out” + 去重后缀。
    • 其它:name = 形参的参数名 或 用户定义的名字。

MegEngine Lite

Bug Fixes

  • 修复调用 enable_profile_performance 接口,在 OpenCL 平台的运行性能分析数据为0的问题。
  • 修复 tensor 等在线程结束后无法被其他线程使用的问题,修改为全局变量并加锁。
  • 修复 lite 中 rknn 设置 tensor 属性类型错误。
  • 修复 MegEngineLite 编译 midout 失败的问题。
  • 修复lite中纯C接口编译错误问题。
  • 修复 MegEngine Lite 模型load之后推导输出 tensor shape 错误的问题。
  • 修复 lite Python 接口中异步执行回调函数错误问题。

New Features

  • 添加 LITE_get_static_memory_alloc_info 接口,用于静态内存分析以及可视化。
  • 支持在执行之前获得模型输出的 Tensor Shape。
  • Lite 支持用户指定输入输出内存地址。
  • Load and run 重构到 Lite 下,并删除原目录「sdk/load-and-run」。文档正在撰写中,待正式版本中可以提供。
  • Lite 中 C 接口的回调函数支持传递 void* 参数。

MegEngine

HighLight

  • The dump_with_testcase_mge.py script is deleted, and the functions are moved into megengine.jit.trace.dump , please refer to Export Serialized Model File .
  • MgeConver can convert mge/TracedModule models into third-party model files, and supports Caffe, TFLite and ONNX frameworks. Use reference ReadMe .

Bug Fixes

Common components

  • Fix the syntax problem under python3.8.
  • Fix the problem that the learning rate cannot be 0.
  • Increase the special judgment logic of exponential operation to ensure the consistency of the results, such as the consistency of x2 and x*x, x3 and xxx, etc.
  • Fixed the problem when the business line det int4 model optimized dump in the global graph. After the repair, the global graph optimization will check the format of opr. If the format does not match nchw, the global graph optimization will not be performed.
  • Solve the problem of overflow when tensor.mean() is calculated with fp32 and fp16 is output.
  • Fix the problem of too many exceptions after the derivation rule fails, and only necessary exceptions are output through conditional judgment, which is convenient for gdb debugging.
  • Fix the problem that tensor cannot be converted to quantized int4 type.
  • Fixed the issue that related resources were not released when the DTR function was disabled.
  • Solve the problem that DTR square root sampling is not random. After solving the problem, resnet1202 training speed can be increased by 5%.
  • Delete all swap interfaces in DTR.
  • The video memory allocation defaults to enable the de-fragmentation function and remove the enable_defrag interface.
  • Fix scripts/cmake-build/*.sh script -n parameter.
  • Use the official build script to build nccl.
  • Fix to use the correct version number for fbs serialization.
  • Imperative supports setting fast-run workspace restrictions to solve the problem of opening fastrun training OOM.
  • Fix the running error of megengine.functional.nn.layer_norm on AMP.

CUDA

  • When CUBLAS_VERSION <11200 (CUBLAS version is lower than 11.2) and batch is 1, if the shape is too large, turn off the cublas batched matmul algorithm to avoid running crashes.
  • Fix that when the kernel size is larger (for example, 160x160), the correct algorithm can be found.
  • Fix the problem of illegal memory access of convolution under CUDA.
  • Fixed the problem that some models cudnnConvBiasActivation crash under cuda11.
  • Fix the problem that the model with BatchConvBias will report an error when the nchw32 graph is optimized.

python API

  • Added layer_norm API documentation.
  • megengine.utils.module_stats supports dictionary input.
  • megengine.functional.full : Modify the dtype of the return value to the dtype of the number passed in, instead of the default float32.
  • Fix the problem that the model using PReLU cannot be traced.

Basic components

  • Optimize the information description of the low bit type.
  • Fix the module’s tensors and named_tensors interfaces to only return data of type Tensor.
  • Fix the accuracy problem caused by the misalignment of gcc and clang compilation options.

Peripheral tools

  • Use load and run tool inference to increase support for u16 and s16 input data.
  • Fix the problem that the option of load_and_run to obtain model memory “--get-static-mem-info” does not take effect.

x86

  • Fix the calculation error of conv_bias Operator .

Release process

  • Fix the problem that the trace status is incorrect after inserting a custom QATModule in the traced module.
  • Fix that some nodes in the figure after TracedModule are flattened are not renamed.
  • Fix TracedModule cannot insert Module with the same _name attribute.
  • Fix to make it not in megengine.functional.nn The defined function can be traced correctly by TracedModule.
  • Fixed the problem that module dict traversal operation cannot be traced in TracedModule.
  • Fix the problem that node.users is incorrect when flattening the functional call of the same tensor node.

OpenCL

  • Modify the cache update strategy of the OpenCL algorithm search. When the cache key is the same, use the latest instead of the previous one to solve the problem that the replacement of the cache triggers the compilation of the kernel from the source, which causes the running speed to slow down.

Compatibility violation

ARM

  • Optimize the calculation performance of Sigmoid in Arm.

New Features

Python API

  • Add pixel_shuffle opr.
  • megengine.random.permutation adds support for Tensor input.
  • Add megengine.random.shuffle opr.
  • Add support for layer_norm.
  • Add megengine.functional.nn.hinge_loss .
  • megengine.functional.nn.local_response_norm adds LRN (local response normalization) support in Functional and Module.
  • megengine.functional.nn.conv_transpose2d megengine.functional.nn.conv_transpose3d adds group parameter support.

Common components

  • Add megengine.coalesce_free_memory interface to reclaim free memory.
  • Fix the error report of module.PixelShuffle.
  • Support the construction of uint16 tensor.
  • BatchNorm adds support for NHWC format.
  • Support bazel to compile flatbuffer, use compiling parameter --copt “-DMGB_ENABLE_FBS_SERIALIZATION=1” to compile load and run to run the open source version of MegEngine dump model.
  • Support the direct use of MegEngine’s dynamic library on windows to reduce the size of the whl package in windows.
  • Fixed a crash when using MegEngine and Pytorch in the same process at the same time.
  • The defrag function is automatically turned on during training, and the video memory fragments can be merged when the video memory is insufficient and the video memory fragments are severe.
  • Support the memory address of output tensor in record mode can be customized and modified.
  • Added bgr2gray mode for megengine.functional.nn.cvt_color OPR.

Peripheral tools

  • Delete dump_with_testcase_mge.py and put its function in the jit.dump interface.
  • Add debugging scripts to MegEngine custom containers such as SmallVector, and you can view the contents of the container during gdb debugging, as shown in the figure below. Note: gdb is only effective when the root directory of MegBrain is running.

Basic components

  • Reduce operator supports nchw44 format.
  • The Elemwise operator supports the format of nchw88.
  • For nhwc int8 conv, add fusion conv and typecvt graph optimization.
  • megengine.optimizer.SGD adds nesterov momentum support.
  • Support C++ model memory/video memory visualization, please refer to [Static Graph Memory Visualization Tool User Guide] () for usage.

ARM

  • Optimize the transpose performance in non-continuous situations, with a speedup of 1.3 under aarch64.
  • Arm platform supports elemwise of NHWC Int16 input and fp32 output.
  • Added support for linear upsample2 of nchw, nchw44+fp32, and nchw88+fp16, greatly optimizing the linear resize performance on ARM.
  • Optimize the implementation of channel wise conv, with a 1.5x speedup when the feature map is small.
  • conv added fp16 support of nchw88 format.
  • Optimize the non-continuous relayout kernel in the arm. When the record is turned on, the average inference time can be reduced by about 50% on the sdm660; the time-consuming ratio of the subtensor opr can be reduced by about 70%.
  • Optimize the broadcast situation of N1HW in Arm Elemwise, and the single calculation performance has been improved by more than 1 times.

X86

  • Added support for 6x16 matmul with reproduceable attribute under X86.

CUDA

  • BatchNorm operator supports nhwc format.

Release process

  • The naming rule of TracedModule node is changed, and GetAttr of expr is merged according to the purpose.
    Modify node to name and qualname. The usage of node._name remains unchanged, and node._orig_name needs to be modified to use node.qualname.

MegEngine Lite

Bug Fixes

  • Fix the problem that the running performance analysis data on the OpenCL platform is 0 when the enable_profile_performance interface is called.
  • Fix the problem that tensor, etc. cannot be used by other threads after the thread ends. Modify it to a global variable and lock it.
  • Fix the wrong type of tensor set by rknn in lite.
  • Fix the problem that MegEngineLite fails to compile midout.
  • Fix the compilation error of pure C interface in lite.
  • Fix the problem that the tensor shape of the deduced output is wrong after the MegEngine Lite model is loaded.
  • Fixed an error in the asynchronous execution of the callback function in the lite Python interface.

New Features

  • Add LITE_get_static_memory_alloc_info interface for static memory analysis and visualization.
  • Support Tensor Shape to get model output before execution.
  • Lite supports users to specify input and output memory addresses.
  • Load and run is refactored to Lite, and the original directory “sdk/load-and-run” is deleted. The document is being written and will be available in the official version.
  • The callback function of the C interface in Lite supports passing void* parameters.