aclgrphBundleSaveModel【免费下载链接】geGEGraph Engine是面向昇腾的图编译器和执行器提供了计算图优化、多流并行、内存复用和模型下沉等技术手段加速模型执行效率减少模型内存占用。 GE 提供对 PyTorch、TensorFlow 前端的友好接入能力并同时支持 onnx、pb 等主流模型格式的解析与编译。项目地址: https://gitcode.com/cann/ge产品支持情况产品是否支持Atlas A3 训练系列产品 / Atlas A3 推理系列产品√Atlas A2 训练系列产品 / Atlas A2 推理系列产品√头文件/库文件头文件#include ge/ge_ir_build.h库文件libge_compiler.so功能说明将离线模型序列化并保存到指定文件中。与aclgrphSaveModel接口的区别是该接口适用于权重更新场景且通过该接口生成的模型如果要使用acl进行推理需要使用aclmdlBundleLoadFromFile或aclmdlBundleLoadFromMem接口加载模型接口详细介绍请参见《应用开发指南 (Python)》。通过aclgrphBundleBuildModel接口生成离线模型缓存后才可以使用aclgrphBundleSaveModel接口落盘。函数原型graphStatus aclgrphBundleSaveModel(const char_t *output_file, const ModelBufferData model)参数说明参数名输入/输出说明model输入aclgrphBundleBuildModel生成的离线模型缓冲数据。详情请参见ModelBufferData。struct ModelBufferData { std::shared_ptruint8_t data nullptr; uint32_t length; };其中data指向生成的模型数据length代表该模型的实际大小。output_file输入保存离线模型的文件名。生成的离线模型文件名会自动以.om后缀结尾例如ir_build_sample.om或者ir_build_sample_linux_x86_64.om若om文件名中包含操作系统及架构则该om文件只能在该操作系统及架构的运行环境中使用。返回值说明参数名类型说明-graphStatusGRAPH_SUCCESS(0)成功。其他值失败。约束说明若生成的om模型文件名中含操作系统及架构但操作系统及其架构与模型运行环境不一致时需要与OPTION_HOST_ENV_OS、OPTION_HOST_ENV_CPU参数配合使用设置模型运行环境的操作系统类型及架构。参数具体介绍请参见aclgrphBuildInitialize支持的配置参数。调用示例// 包含的头文件 #include ge_ir_build.h #include ge_api_types.h // 1.生成Graph Graph origin_graph(Irorigin_graph); GenGraph(origin_graph); // 2.创建完Graph以后通过aclgrphBuildInitialize接口进行系统初始化并申请资源 std::mapAscendString, AscendString global_options; auto status aclgrphBuildInitialize(global_options); // 3. 生成权重可更新的图包括三部分权重初始化图权重更新图推理图 // 权重初始化是可选步骤根据业务场景由用户判断是否需要包含权重初始化图不包含的情况下可节省模型加载所需的Device内存 WeightRefreshableGraphs weight_refreshable_graphs; std::vectorAscendString const_names; const_names.emplace_back(AscendString(const_1)); const_names.emplace_back(AscendString(const_2)); status aclgrphConvertToWeightRefreshableGraphs(origin_graph, const_names, weight_refreshable_graphs); if (status ! GRAPH_SUCCESS) { cout aclgrphConvertToWeightRefreshableGraphs failed! endl; aclgrphBuildFinalize(); return -1; } // 4.将权重可更新的图编译成离线模型并保存在内存缓冲区中 std::mapAscendString, AscendString options; std::vectorge::GraphWithOptions graph_and_options; // 推理图 graph_and_options.push_back(GraphWithOptions{weight_refreshable_graphs.infer_graph, options}); // 权重初始化图 graph_and_options.push_back(GraphWithOptions{weight_refreshable_graphs.var_init_graph, options}); // 权重更新图 graph_and_options.push_back(GraphWithOptions{weight_refreshable_graphs.var_update_graph, options}); ge::ModelBufferData model; status aclgrphBundleBuildModel(graph_and_options, model); if (status ! GRAPH_SUCCESS) { cout aclgrphBundleBuildModel failed endl; aclgrphBuildFinalize(); return -1; } // 5.将内存缓冲区中的模型保存为离线模型文件 const char *file./xxx ; status aclgrphBundleSaveModel(file, model); if (status ! GRAPH_SUCCESS) { cout aclgrphBundleSaveModel failed endl; aclgrphBuildFinalize(); return -1; } // 6.构图进程结束释放资源 aclgrphBuildFinalize();【免费下载链接】geGEGraph Engine是面向昇腾的图编译器和执行器提供了计算图优化、多流并行、内存复用和模型下沉等技术手段加速模型执行效率减少模型内存占用。 GE 提供对 PyTorch、TensorFlow 前端的友好接入能力并同时支持 onnx、pb 等主流模型格式的解析与编译。项目地址: https://gitcode.com/cann/ge创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考