ARTICLE DETAIL

资讯详情

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

昇腾CANN/GE Python图构建示例

昇腾CANN/GE Python图构建示例 Sample Usage Guide【免费下载链接】geGEGraph Engine是面向昇腾的图编译器和执行器提供了计算图优化、多流并行、内存复用和模型下沉等技术手段加速模型执行效率减少模型内存占用。 GE 提供对 PyTorch、TensorFlow 前端的友好接入能力并同时支持 onnx、pb 等主流模型格式的解析与编译。项目地址: https://gitcode.com/cann/ge1. Function DescriptionThis sample demonstrates graph construction using Relu operator normal input, aimed at helping graph developers quickly understand normal input definition and usage of this type of operators in graph construction.2. Directory Structurepython/ ├── src/ | └── make_relu_add_graph.py // sample file ├── run_sample.sh // Execution script ├── CMakeLists.txt // Build script ├── README.md // README file3. Usage Instructions3.1. Prepare CANN PackageInstalltoolkitandopspackages correctly following Environment PreparationSet environment variables (assuming package is installed at /usr/local/Ascend/)source /usr/local/Ascend/cann/set_env.sh3.2. Build and ExecuteNote: Compared with C/C graph construction, Python graph construction requires additional LD_LIBRARY_PATH and PYTHONPATH settings (refer to configuration in sample)bash run_sample.sh -t sample_and_run_pythonThis command will:Automatically generate ES interfacesCompile sample programGenerate dump graph and run the graphAfter successful execution, you will see:[Success] sample execution successful, pbtxt dump generated in current directory. The file starts with ge_onnx_ and can be opened in netron for displayOutput File DescriptionAfter successful execution, the following files will be generated in current directory:ge_onnx_*.pbtxt- protobuf text format of graph structure, can be viewed with netron3.3. Log PrintingIf you need log printing to assist debugging during executable program execution, you can set the following environment variables beforebash run_sample.sh -t sample_and_run_pythonto print logs to screen:export ASCEND_SLOG_PRINT_TO_STDOUT1 # Print logs to screen export ASCEND_GLOBAL_LOG_LEVEL0 # Log level set to debug level3.4. DUMP Graph During Graph Compilation ProcessIf you need to DUMP graph to assist debugging graph compilation process during executable program execution, you can set the following environment variables beforebash run_sample.sh -t sample_and_run_pythonto DUMP graph to execution path:export DUMP_GE_GRAPH24. Core Concepts Introduction4.1. Graph Construction StepsCreate graph builder (provides context, workspace and construction-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 computation result endpoints)4.2. Normal InputConcept Explanation:Normal input refers to operator input that is mandatory input with fixed input count.Graph Construction API Features:Input type must match type constraint declared during operator registration, ES API will perform type checking during graph constructionFor example, Relu operator prototype is shown below, ES graph construction generated API isRelu(), supporting use in PythonREG_OP(Relu) .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16, DT_DOUBLE, DT_INT8, DT_INT32, DT_INT16, DT_INT64, DT_UINT8, DT_UINT16, DT_QINT8, DT_BF16})) .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_DOUBLE, DT_INT8, DT_INT32, DT_INT16, DT_INT64, DT_UINT8, DT_UINT16, DT_QINT8, DT_BF16})) .OP_END_FACTORY_REG(Relu)Its corresponding function prototype is:Function name: ReluParameters: 1 in total, which is xReturn value: output yPython API:Relu(x: TensorHolder) - TensorHolder:【免费下载链接】geGEGraph Engine是面向昇腾的图编译器和执行器提供了计算图优化、多流并行、内存复用和模型下沉等技术手段加速模型执行效率减少模型内存占用。 GE 提供对 PyTorch、TensorFlow 前端的友好接入能力并同时支持 onnx、pb 等主流模型格式的解析与编译。项目地址: https://gitcode.com/cann/ge创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表