☰
CANN/ge 分组卷积分解Python示例
2026/10/15 23:05:49 网站建设 项目流程

DecomposeGroupedConvToSplitedPass Python Sample Usage Guide

【免费下载链接】geGE(Graph Engine)是面向昇腾的图编译器和执行器,提供了计算图优化、多流并行、内存复用和模型下沉等技术手段,加速模型执行效率,减少模型内存占用。 GE 提供对 PyTorch、TensorFlow 前端的友好接入能力,并同时支持 onnx、pb 等主流模型格式的解析与编译。项目地址: https://gitcode.com/cann/ge

Function Description

This directory provides apure Pythonversion ofpattern_base_pass/6_decompose_grouped_conv_to_splited_pass, with logic consistent with the C++ version:

  • op_types=["Conv2D"], only matchesConv2Dnodes in the original graph
  • meet_requirements()checksgroups != 1anddata_format == "NCHW"
  • replacement()constructs a replacement graph usingSplit(input) + Split(filter) + multiple Conv2D + Concat
  • Updates input/outputTensorDescfor eachConv2Din the replacement graph, settingFORMAT_NCHW/DT_FLOAT
  • ExecutesInferShapeon the replacement graph to complete shape inference

Directory Structure

python/ ├── README.md // Python sample documentation ├── CMakeLists.txt // Build script for generating Python ES API ├── src │ ├── python_decompose_pass.py // Python pass implementation file

Prerequisites

  • CANN environment variables have been set viasource ${ASCEND_PATH}/set_env.sh. For more details, refer to the environment variable configuration step in C++ Sample README
  • CANN software package installation, refer to Environment Preparation
  • Python dependencies for graph compilation installed:attrs,decorator,sympy,numpy,psutil,scipy

The run package already includes thege_pywheel required for GE Python runtime. There is no need to separately installge_py-*.whlin this section. Python pass runtime loads pre-compiled binary components based onpybind11. CANN package prioritizes products matching the current Python version; if no matching product exists, it automatically enters the fallback compilation process. Fallback compilation requirespybind11to be installed in the current Python environment. If execution prompts missing ES APIs such asConv2D, follow the "Handling Missing ES API (Optional)" section below to generate and loades_all.

Usage

The following commands are executed in the6_decompose_grouped_conv_to_splited_pass/pythondirectory by default.

  1. Set the Python pass plugin path:

    export ASCEND_GE_PY_PASS_PATH="$PWD/src/python_decompose_pass.py"
  2. Refer to the program execution section in C++ Sample README for verification. For offline scenarios, replace theatccommand in the C++ README withpyatc; both have identical command-line parameters, andpyatcruns within the current Python interpreter process.

  3. Notes:

    • This sample is not a standalone execution script; runningpython src/python_decompose_pass.pydirectly will not trigger pass execution
    • Expected output will be printed after GE compilation process actually loads this Python pass
    • If execution reports missing ES APIs such asConv2D, first generate and loades_allas described below, then rerun

Handling Missing ES API (Optional)

If execution reports missing ES APIs such asConv2D, you can generatees_allin the6_decompose_grouped_conv_to_splited_pass/pythondirectory:

cmake -S . -B build cmake --build build --target build_es_all -j$(nproc)

Install the generated Python package and make it accessible to the current Python process along with its dynamic libraries:

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 Logs

After successful execution, similar output will appear in the logs:

Define MeetRequirements for PythonDecomposeGroupedConvToSplitedPass Define Replacement for PythonDecomposeGroupedConvToSplitedPass

【免费下载链接】geGE(Graph Engine)是面向昇腾的图编译器和执行器,提供了计算图优化、多流并行、内存复用和模型下沉等技术手段,加速模型执行效率,减少模型内存占用。 GE 提供对 PyTorch、TensorFlow 前端的友好接入能力,并同时支持 onnx、pb 等主流模型格式的解析与编译。项目地址: https://gitcode.com/cann/ge

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询