news 2026/9/10 4:42:50

CANN/GE ES图构建Transformer示例

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
CANN/GE ES图构建Transformer示例

Sample Usage Guide

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

1. Function Description

This sample constructs a transformer graph, aiming to help graph construction developers quickly get started with ES graph construction approach.

2. Directory Structure

python/ ├── src/ | └── make_transformer_graph.py // Sample file ├── run_sample.sh // Execution script ├── CMakeLists.txt // Build script ├── README.md // README file

3. Usage

3.1 Prepare CANN Package

  • Correctly installtoolkitandopspackages following the installation guide Environment Preparation
  • Set environment variables (assuming the package is installed in /usr/local/Ascend/)
source /usr/local/Ascend/cann/set_env.sh

3.2 Build and Execute

  • Note: Compared with C/C++ graph construction, Python graph construction requires additional LD_LIBRARY_PATH and PYTHONPATH settings (refer to the configuration in sample) Simply run the following command to clean up, generate interface, build graph and DUMP graph and execute sample file:
bash run_sample.sh -t sample_and_run_python

This command will:

  1. Automatically generate ES interface
  2. Compile sample program
  3. Generate dump graph and run the graph

After successful execution, you will see:

[Success] sample executed successfully, pbtxt dump has been generated in current directory. This file starts with ge_onnx_ and can be opened in netron for display
Output File Description

After successful execution, the following file will be generated in current directory:

  • ge_onnx_*.pbtxt- Protobuf text format of graph structure, can be viewed with netron

3.3 Log Printing

If log printing is needed during executable program execution to assist debugging, set the following environment variables before bash run_sample.sh -t sample_and_run_python to print logs to screen:

export ASCEND_SLOG_PRINT_TO_STDOUT=1 #Print logs to screen export ASCEND_GLOBAL_LOG_LEVEL=0 #Log level set to debug level

3.4 DUMP Graph During Graph Compilation

If DUMP graph is needed during executable program execution to assist graph compilation debugging, set the following environment variables before bash run_sample.sh -t sample_and_run_python to DUMP graph to execution path:

export DUMP_GE_GRAPH=2

4. Core Concept Introduction

4.1 Graph Construction Steps

  • Create graph builder (to provide context, workspace and build-related methods needed for graph construction)
  • Add starting nodes (starting nodes refer to nodes without input dependencies, usually including graph inputs (like Data nodes) and weight constants (like Const nodes))
  • Add intermediate nodes (intermediate nodes are computation nodes with input dependencies, usually generated by user graph construction logic, and connected using existing nodes as inputs)
  • Set graph output (explicitly specify graph output nodes as endpoints of computation results)

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

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

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/9/10 4:42:37

反指纹浏览器原理与实战:基于Firefox的camofox浏览器指纹伪装指南

1. 项目概述与需求拆解1.1 camofox-browser到底是什么先说结论:camofox-browser不是某个大厂出的现成软件,而是一个以隐私保护和反指纹追踪为核心目标的浏览器改造项目。名字拆开看就很直白,camo是伪装,fox指Firefox,合…

作者头像 李华
网站建设 2026/9/10 4:39:58

Django招聘数据分析系统:从环境搭建到ECharts可视化

简介:本资源是一套完整可用的Python毕业设计项目,基于Django框架构建招聘数据分析与可视化系统,面向计算机及相关专业本科生,助力毕业设计选题、开发与答辩全流程。项目已通过导师审核,评审得分98分,源码经…

作者头像 李华
网站建设 2026/9/10 4:34:33

嵌入式面试四大实战能力:硬件感知、资源博弈、系统穿透与现场还原

1. 这不是技术筛选,是嵌入式工程师的“现场压力测试”“面试老是挂”——这句话我听过不下两百遍,几乎每个来跟我聊职业发展的嵌入式新人,开口第一句就是这个。但真正让我警觉的,不是他们挂了,而是他们挂完之后说的下一…

作者头像 李华