build_model

Applicable Products

All processors

Function Usage

Builds an input graph into an offline model adapted to the AI processor and saves the model to the memory buffer.

Prototype

1
build_model(graph: Graph, build_options: Optional[dict] = None) -> ModelBuffer

Parameters

Parameter

Input/Output

Description

graph

Input

Graph to be built.

build_options

Input

Graph-level configuration parameter.

A key-value dict mapping table, for the build configuration of the offline model. key indicates the parameter type, and value indicates the parameter value, both of type string.

For details about the configuration parameters supported by the dict, see aclgrphBuildModel Configuration Parameters.

Returns

(ModelBuffer) Buffer of the generated offline model

Restrictions

  • If graph is not of the Graph type, TypeError is thrown.
  • If build_options is not a valid string dict, TypeError is thrown.
  • If the build fails, RuntimeError is thrown.
  • For the same options build parameters passed to build_model and build_initialize, you need to configure them once only. If the same parameters are passed repeatedly, the parameters passed to build_model are used.
  • When the build_model API is used to pass the build_options parameter in the multi-graph scenario, and the input parameter is PRECISION_MODE or PRECISION_MODE_V2, the parameter values of these graphs must be the same.
  • The offline model built using the build_model API is stored in the memory buffer.
    • To save the offline model in the memory buffer as an .om file, call the save_model API to serialize the offline model and save it to the file. To perform inference, use the API for loading a model from a file, for example, aclmdlLoadFromFile, and then use the aclmdlExecute API to perform inference.
    • If the offline model is stored in the memory buffer, you need to call the API for loading the model from the memory, for example, aclmdlLoadFromMem, and then call aclmdlExecute to perform inference.

For details about the APIs, see Model Management.