ARTICLE DETAIL

建站实战干货

来自一线的建站与推广经验沉淀,每一条都经过真实交付验证。

昇腾CANN GE卷积格式转换Python融合通道示例

2026/9/10 3:04:43 拓冰建站 浏览量
昇腾CANN GE卷积格式转换Python融合通道示例 ConvTransFormatPass Python Example Usage Guide【免费下载链接】geGEGraph Engine是面向昇腾的图编译器和执行器提供了计算图优化、多流并行、内存复用和模型下沉等技术手段加速模型执行效率减少模型内存占用。 GE 提供对 PyTorch、TensorFlow 前端的友好接入能力并同时支持 onnx、pb 等主流模型格式的解析与编译。项目地址: https://gitcode.com/cann/geThis directory provides apure Pythonversion example ofgraph_base_pass/3_modify_conv_data_format_pass, main flow identical to CConvTransFormatPass:TraverseConv2D/Conv2DV2in graph, filter nodes withdata_format NCHW;Changedata_formattoNHWC;BFS from Conv output, matchTransposewithperm [0,2,3,1]and[0,3,1,2]in order, delete correspondingTransposeand perm constant output nodes and reconnect data edges.This example inheritsFusionBasePassand overridesrun(), completes modification viaGraph.remove_edge/add_data_edge/remove_nodeandNode.set_attr,does not useSubgraphRewriter.Differences from C VersionFull Graph Rollback: C uses backup graph to restore whenSetAttror edge deletion fails. Current PythonGraphdoes not support full graph deep copy. This example throws exception on failure,does not guaranteesame atomic rollback semantics as C.Reading Transpose perm: C usesGNode::GetInputConstData. Python side reads viavalueattribute ofConst/Constantnode at perm input (same as Const validation inpattern_base_pass/4_add_zero_pass). If perm in graph does not appear in this form, may not recognize and deleteTranspose, coverage may differ slightly from C.Directory Structurepython/ ├── README.md // Python example description ├── CMakeLists.txt // Build script for generating es_all Python ES API ├── src │ ├── python_modify_conv_data_format_pass.py // Python pass implementation filePrerequisitesCompleted CANN environment variable setup viasource ${ASCEND_PATH}/set_env.sh. For more guidance, refer to C Example README environment variable configuration stepCan import GE Python package (containsge.graph,ge.passesand pass loading chain)Python pass runtime loads precompiled binary components based onpybind11. CANN package prioritizes providing artifacts matching current Python version; if no matching artifact, automatically enters fallback compilation flow. Fallback compilation requirespybind11installed in current Python environment.UsageLet GE load this Python pass during compilation via environment variable (when in3_modify_conv_data_format_passdirectory):export ASCEND_GE_PY_PASS_PATH$PWD/python/src/python_modify_conv_data_format_pass.pyRefer to C Example README program execution chapter for validation.Expected ResultSimilar log output:PythonConvTransFormatPass is starting Remove output edges success Remove output edges success PythonConvTransFormatPass completedWhen comparing pbtxt exported byDUMP_GE_GRAPH, should see Convdata_formatisNHWCand targetTransposeremoved (consistent with C example description).【免费下载链接】geGEGraph Engine是面向昇腾的图编译器和执行器提供了计算图优化、多流并行、内存复用和模型下沉等技术手段加速模型执行效率减少模型内存占用。 GE 提供对 PyTorch、TensorFlow 前端的友好接入能力并同时支持 onnx、pb 等主流模型格式的解析与编译。项目地址: https://gitcode.com/cann/ge创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考