拓冰建站拓冰建站
首页 / 资讯中心 / 正文

CANN/GE图融合Pass示例

MoveReluBeforeConcatPass Python Example Usage Guide【免费下载链接】geGEGraph Engine是面向昇腾的图编译器和执行器提供了计算图优化、多流并行、内存复用和模型下沉等技术手段加速模型执行效率减少模型内存占用。 GE 提供对 PyTorch、TensorFlow 前端的友好接入能力并同时支持 onnx、pb 等主流模型格式的解析与编译。项目地址: https://gitcode.com/cann/geThis directory provides apure Pythonversion example ofgraph_base_pass/2_move_relu_before_concat_pass, with logic identical to the C version:ScanConcatV2 - RelustructureBuild replacement subgraph (move Relu to each input of Concat)UseSubgraphBoundarySubgraphRewriter.replace()for subgraph replacementFusionBasePass vs PatternFusionPassThe pass in this example inherits FusionBasePass. Unlike PatternFusionPass, here pass logic is implemented by overridingrun()function.run()function input contains reference to graph object. In this example scenario, Concat node input count is not fixed, difficult to represent with fixed pattern. Inrun()function can dynamically build Boundary based on matched Concat node in target graph, achieving higher flexibility.Directory Structurepython/ ├── README.md // Python example description ├── CMakeLists.txt // Build script for generating es_all Python ES API ├── src │ ├── python_move_relu_before_concat_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 stepPython environment can import ES API (usually from run package/ops package):ge.es.math.ConcatV2ge.es.nn.Relu(if this symbol is unavailable, confirm ES Python API installation is complete)Can 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. If execution reports missingConcatV2,Reluetc. ES API, follow ES API Missing Handling (Optional) below to generate and loades_all.UsageThe following commands are executed in2_move_relu_before_concat_passdirectory by default.Configure environment variables:source ${ASCEND_PATH}/set_env.sh export DUMP_GE_GRAPH1 export ASCEND_GE_PY_PASS_PATH$PWD/python/src/python_move_relu_before_concat_pass.pyGenerate AIR model:cd cpp/data python es_gen_air.pyUsepyatcoffline compilation to trigger Python pass, modifysoc_versionper actual environment:pyatc --model./graph.air --framework1 --soc_versionxxx --output./model cd ../..Notes:pyatccommand line parameters are identical toatc, but run in current Python interpreter processIf execution reports missingConcatV2,Reluetc. ES API, first generate and loades_allper instructions below, then rerunES API Missing Handling (Optional)If execution reports missingConcatV2,Reluetc. ES API, can generatees_allviaCMakeLists.txtin this Python directory:cd python cmake -S . -B build cmake --build build --target build_es_all -j$(nproc)Install generated Python package and let current Python process find the package and corresponding dynamic library:pip install --force-reinstall --upgrade --target ./build/whl_package ./build/es_output/whl/es_all-1.0.0-py3-none-any.whl export PYTHONPATH$PWD/build/whl_package:${PYTHONPATH:-} export LD_LIBRARY_PATH$PWD/build/es_output/lib64:${LD_LIBRARY_PATH:-} cd ..Expected ResultSimilar log output:PythonMoveReluBeforeConcatPass Replacement of PythonMoveReluBeforeConcatPass succeeded【免费下载链接】geGEGraph Engine是面向昇腾的图编译器和执行器提供了计算图优化、多流并行、内存复用和模型下沉等技术手段加速模型执行效率减少模型内存占用。 GE 提供对 PyTorch、TensorFlow 前端的友好接入能力并同时支持 onnx、pb 等主流模型格式的解析与编译。项目地址: https://gitcode.com/cann/ge创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
分享:

看完干货,该让你的企业上线了

免费需求沟通 · 48 小时内出具建站方案 · 河南本地可上门