save_prune_retrain_model
Applicability
Product |
Supported |
|---|---|
|
|
|
|
|
|
|
|
|
Note: For the Products marked with x, no error is reported when the API is called for the 2:4 structured sparsity feature, but the performance benefits cannot be obtained.
Description
Filter-level sparsity or 2:4 structured sparsity API. Only either of the two sparsity features can be enabled at a time.
- Filter-level sparsity: Generates a sparsity model that implements channel cropping based on the retrained model with the mask operator, and removes the mask operator.
- 2:4 structured sparsity: Generates the final sparsity model based on the retrained model with the 2:4 structured sparsity operator, and removes the structured sparsity operator.
Prototype
1 | save_prune_retrain_model(pb_model, outputs, record_file, save_path) |
Parameters
Parameter |
Input/Output |
Description |
|---|---|---|
pb_model |
Input |
.pb model for inference with sparse operators. The parameters are restored from the retraining checkpoint. A string. |
outputs |
Input |
Output of the user model A list of strings, for example, [output1,output2,...]. |
record_file |
Input |
Path (including the file name) of the file that records sparsity information. A string. |
save_path |
Input |
Model save path. Must include the prefix of the model name, for example, ./prune_model/*model. A string. |
Returns
None
Example
1 | amct.save_prune_retrain_model(masked_pb_path, [operation_name_1, operation_name_2], './tmp/record.txt', './pb_model/final_model') |
Flush file: .pb model for sparsity.