--external_weight

Applicable Products

All processors

Description

Sets whether to externalize the weights of the Const/Constant nodes on the original network and converts the node type to FileConstant when the offline model file (.om) is generated.

In offline scenarios, if the model weights are large and there are restrictions on the size of the offline model file, you are advised to enable external weights to store weights separately, reducing the size of the offline model file.

See Also

This option must be used together with --output. The generated weight file is saved in the weight directory at the same level as the offline model file (.om).

Arguments

  • 0 (default): The weights are not externalized and are directly saved in the offline model file (.om).
  • 1: The weights are externalized but not combined. The weight files of all Const/Constant nodes on the network are flushed to the disk, and their node types are converted to FileConstant. Weights of different nodes are stored in different files named weight_<hash>.
  • 2: The weights are externalized and combined. The weight files of all Const/Constant nodes on the network are flushed to the disk, and their node types are converted to FileConstant. All weights are saved in a file named File name specified by --output_weight_combined.

Suggestions and Benefits

None

Example

The following uses the ONNX network model as an example:

atc --framework=5 --model=$HOME/module/resnet50.onnx --output=$HOME/module/out/onnx_resnet50 --soc_version=<soc_version>  --external_weight=1

Dependencies and Restrictions

During inference application development and model loading in weight externalization scenarios:

  • If aclmdlLoadFromFile is called to load a model, the weight file must be stored in the weight directory at the same level as the offline model file (.om).
  • If aclmdlSetConfigOpt and aclmdlLoadWithConfig are called to load a model, there are no constraints on the directory for storing external weight files. When the model is loaded later, call aclmdlLoadWithConfig to specify the directory for storing external weight files.

For details about the APIs, see Model Loading and Unloading.