Sample Usage Guide
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 install
toolkitandopspackages 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:
- Automatically generate ES interface
- Compile sample program
- 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)