@ -86,7 +86,7 @@ class ImperativeQuantAware(object):
' moving_average_abs_max ' , the static quantization scale will be calculated
during training and used in inference .
moving_rate ( float ) : the parameter for ' moving_average_abs_max ' quantization .
quantizable_ op _type( list [ str ] ) : List the type of layers that will be quantized .
quantizable_ layer _type( list [ str ] ) : List the type of layers that will be quantized .
Default is [ ' Conv2D ' , ' Linear ' ] . The quantizable_op_type in
QuantizationFreezePass and ConvertToInt8Pass must be the same as this .
weight_preprocess_layer ( paddle . nn . Layer , optional ) : A paddle Layer that defines how to preprocess
@ -229,7 +229,17 @@ class ImperativeQuantAware(object):
" ' abs_max ' or ' moving_average_abs_max ' or ' channel_wise_abs_max ' now. "
% ( str ( weight_quantize_type ) ) )
self . _quant_layers_map = { ' Conv2D ' : Conv2D , ' Linear ' : Linear }
self . _quant_layers_map = {
' Conv2D ' : Conv2D ,
' Linear ' : Linear ,
' Pool2D ' : Pool2D ,
' ReLU ' : ReLU ,
' LeakyReLU ' : LeakyReLU ,
' ReLU6 ' : ReLU6 ,
' Softmax ' : Softmax ,
' Tanh ' : Tanh ,
' Swish ' : Swish
}
self . _quantizable_layer_type = tuple (
self . _quant_layers_map [ layer ]
if layer in self . _quant_layers_map else layer
@ -262,7 +272,6 @@ class ImperativeQuantAware(object):
for i in range ( len ( scopes ) - 1 ) :
obj = getattr ( parent , scopes [ i ] )
parent = obj
quant_layer = self . _get_quantized_counterpart ( layer )
setattr ( quant_layer , " layer_name " , layer . full_name ( ) )
setattr ( obj , target , quant_layer )
@ -285,7 +294,12 @@ class ImperativeQuantAware(object):
layer . full_name ( ) ) )
sys . exit ( - 1 )
quantized_layer = quant_nn . __dict__ [ quantized_counterpart [ index ] ] (
layer_with_weight = [ ' QuantizedConv2D ' , ' QuantizedLinear ' ]
if quantized_counterpart [ index ] not in layer_with_weight :
quant_layer_class_name = ' QuantizedNoweightLayer '
else :
quant_layer_class_name = quantized_counterpart [ index ]
quantized_layer = quant_nn . __dict__ [ quant_layer_class_name ] (
layer , self . _weight_bits , self . _activation_bits , self . _moving_rate ,
self . _weight_quantize_type , self . _activation_quantize_type ,
self . _weight_pre_layer , self . _act_pre_layer ,