auto_channel_prune_search

Applicability

Product

Supported

Atlas 350 Accelerator Card

Atlas A3 training product/Atlas A3 inference product

Atlas A2 training product/Atlas A2 inference product

Atlas 200I/500 A2 inference product

Atlas inference product

Atlas training product

Description

Calculates the sparsity sensitivity (affecting accuracy) and sparsity gain (affecting performance) of each channel based on the user model. Then, the search policy searches for the optimal layer-wise channel sparsity ratio based on the input to balance accuracy and performance. Finally, a configuration file is generated.

Prototype

1
auto_channel_prune_search(graph, output_nodes, config, input_data, output_cfg, sensitivity, search_alg)

Parameters

Parameter

Input/Output

Description

graph

Input

tf.Graph training graph to be sparsified, which contains automatic differentiation.

A tf.Graph.

output_nodes

Input

Name of the model output node.

A list of strings.

config

Input

Path of the configuration file for auto channel pruning search.

The simplified configuration file is generated based on AutoChannelPruneConfig in the basic_info.proto file. The *.proto file is stored in /amct_tensorflow/proto/ under the AMCT installation directory.

For details about the parameters in the *.proto file and the generated auto channel pruning search configuration file, see Simplified Configuration File for Auto Channel Pruning Search.

A string.

input_data

Input

Calibration data provided by the user.

A list. The content is the corresponding feed_dict data.

output_cfg

Input

Path of the output channel pruning configuration file.

A string.

sensitivity

Input

Sensitivity calculation method.

A string or

subclass of SensitivityBase. The string is an existing method of AMCT, which can be set to TaylorLossSensitivity. The subclass of SensitivityBase can be instantiated and defined by the user. Defaults to TaylorLossSensitivity.

search_alg

Input

Method of searching for channels to be sparsified.

A string or

subclass of SearchChannelBase. The string is an existing method of AMCT, which can be set to GreedySearch. The subclass of SearchChannelBase can be instantiated and defined by the user. The default value is GreedySearch.

Returns

None

Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
import amct_tensorflow as amct
# Construct feed_dict data.
input_data = np.random.uniform(-10, 10, (2, 14, 14, 64)).astype(np.str_)
feed_dict = [{'input:0': input_data}]

amct.auto_channel_prune_search(
     graph=graph, 
     output_nodes=[operation_name_1, operation_name_2],
     config='./tmp/sample.cfg', 
     input_data=feed_dict,  
     output_cfg='./tmp/output.cfg', 
     sensitivity='TaylorLossSensitivity', 
     search_alg='GreedySearch')

Flush file: auto channel pruning configuration file, which needs to be passed to the channel pruning API for subsequent services.