ARTICLE DETAIL

资讯详情

深耕郑州网站建设与运营推广的一线实战洞察。

CANN/GE MatMul-Add融合Pass Python示例

CANN/GE MatMul-Add融合Pass Python示例 FuseMatMulAndAddPass Python Sample Usage Guide【免费下载链接】geGEGraph Engine是面向昇腾的图编译器和执行器提供了计算图优化、多流并行、内存复用和模型下沉等技术手段加速模型执行效率减少模型内存占用。 GE 提供对 PyTorch、TensorFlow 前端的友好接入能力并同时支持 onnx、pb 等主流模型格式的解析与编译。项目地址: https://gitcode.com/cann/geThis directory provides apure Pythonversion ofpattern_base_pass/1_fuse_matmul_add_pass, with logic consistent with CFuseMatMulAndAddPass:Pattern 0:MatMul(a, b)→Add(..., c), graph inputs0/1/2correspond toa/b/cPattern 1:BatchMatMulV2(a, b)→Add(..., c), same three-input topologyReplacement:GEMM(r_a, r_b, r_c, alpha1, beta1)(scalar1.0aligns with CCreateScalar(1))InheritsPatternFusionPass, implementspatterns()/meet_requirements()/replacement(); phase isBeforeInferShapeNo additional matcher configuration likeenable_const_value_match()enabled, consistent with C default matching behavior.Directory Structurepython/ ├── README.md // Python sample documentation ├── CMakeLists.txt // Build script for generating es_all Python ES API ├── src │ ├── python_fuse_matmul_add_pass.py // Python pass implementation filePrerequisitesCANN environment variables configured viasource ${ASCEND_PATH}/set_env.sh, see C sample README environment configuration stepsGE Python package importable (includesge.passesand pass loading chain)run package typically includesge_pywheel, no need to install separatege_py-*.whl. Python pass runtime loadspybind11-based precompiled binary components. CANN package provides artifacts matching current Python version; if no match, fallback compilation occurs automatically. Fallback compilation requirespybind11installed in current Python environment. If execution reports missingBatchMatMulV2,GEMMetc. ES API, follow ES API Missing Handling (Optional) below to generate and loades_all.UsageCommands below default to execution in1_fuse_matmul_add_pass/pythondirectory.Set environment variable for GE to load this Python pass during compilation:export ASCEND_GE_PY_PASS_PATH$PWD/src/python_fuse_matmul_add_pass.pyFollow C sample README program execution section for verification.Notes:This sample is not a standalone execution script, directly runningpython src/python_fuse_matmul_add_pass.pywont trigger pass executionIf execution reports missingBatchMatMulV2,GEMMetc. ES API, generate and loades_allfirst per below, then rerunES API Missing Handling (Optional)If execution reports missingBatchMatMulV2,GEMMetc. ES API, generatees_allvia this Python directorysCMakeLists.txt:cmake -S . -B build cmake --build build --target build_es_all -j$(nproc)Install generated Python package and ensure current Python process can 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:-}Expected BehaviorSimilar to C sample, when pattern/replacement invoked:Define pattern for FuseMatMulAndAddPass Define replacement for FuseMatMulAndAddPass【免费下载链接】geGEGraph Engine是面向昇腾的图编译器和执行器提供了计算图优化、多流并行、内存复用和模型下沉等技术手段加速模型执行效率减少模型内存占用。 GE 提供对 PyTorch、TensorFlow 前端的友好接入能力并同时支持 onnx、pb 等主流模型格式的解析与编译。项目地址: https://gitcode.com/cann/ge创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表