aclgrphBuildModel
产品支持情况
产品 |
是否支持 |
---|---|
|
√ |
|
√ |
|
√ |
|
√ |
|
√ |
功能说明
编译生成离线模型并保存到内存缓冲区。
- 输入模型为切片模型(切片模型是指将大型模型使用TP(Tensor Parallelism)切分后生成的多个子模型):
支持将多个graphs根据graph之间的relation编译成一个flowmodel,其中graphs之间的关系通过options中的MODEL_RELATION_CONFIG配置文件指定。
该功能与使用ATC命令中的--distributed_cluster_build(配置为1)参数,并配置了--shard_model_dir和--model_relation_config功能相同。
使用该接口会校验ge.distributed_cluster_build /ge.cluster_config/ge.offline_model_relation是否配置正确。
函数原型

数据类型为string的接口后续版本会废弃,建议使用数据类型为非string的接口。
- 输入模型为非切片模型:
1 2
graphStatus aclgrphBuildModel(const ge::Graph &graph, const std::map<std::string, std::string> &build_options, ModelBufferData &model) graphStatus aclgrphBuildModel(const ge::Graph &graph, const std::map<AscendString, AscendString> &build_options, ModelBufferData &model)
- 输入模型为切片模型:
1 2
graphStatus aclgrphBuildModel(const std::vector<ge::Graph> &graphs, const std::map<std::string, std::string> &build_options, ModelBufferData &model) graphStatus aclgrphBuildModel(const std::vector<ge::Graph> &graphs, const std::map<AscendString, AscendString> &build_options, ModelBufferData &model)
参数说明
参数名 |
输入/输出 |
说明 |
||
---|---|---|---|---|
graph/graphs |
输入 |
|
||
build_options |
输入 |
graph级别配置参数。 配置参数map映射表,key为参数类型,value为参数值,均为字符串格式,用于描述离线模型编译配置信息。 map中的配置参数请参见aclgrphBuildModel支持的配置参数。 |
||
model |
输出 |
编译生成的离线模型缓存,模型保存在内存缓冲区中。详情请参见ModelBufferData。
其中data指向生成的模型数据,length代表该模型的实际大小。 |
返回值说明
参数名 |
类型 |
说明 |
---|---|---|
- |
graphStatus |
GRAPH_SUCCESS:成功。 其他值:失败。 |
约束说明
- 对于aclgrphBuildModel和aclgrphBuildInitialize中重复的编译配置参数,建议不要重复配置,如果设置重复,则以aclgrphBuildModel传入的为准。
- 使用aclgrphBuildModel接口传入options参数时,多张图场景下,如果传入的参数为ge::ir_option::PRECISION_MODE或者ge::ir_option::PRECISION_MODE_V2,多张图设置的参数值需要相同。
- 如果输入模型为切片后的模型,应保证切片后的模型数量大于1,且options中应配置DISTRIBUTED_CLUSTER_BUILD和MODEL_RELATION_CONFIG参数。
- 使用aclgrphBuildModel接口编译的离线模型,保存在内存缓冲区中:
- 如果希望将内存缓冲区中的模型保存为离线模型文件xx.om,则需要调用aclgrphSaveModel接口,序列化保存离线模型到文件中。后续使用AscendCL接口进行推理业务,需要使用从文件中加载模型的接口,例如aclmdlLoadFromFile,然后使用aclmdlExecute接口执行推理。
- 如果离线模型保存在内存缓冲区:
后续使用AscendCL接口进行推理业务时,需要使用从内存中加载模型的接口,例如aclmdlLoadFromMem,然后使用aclmdlExecute接口执行推理。