TrainingExtensions/tensorflow/src/python/aimet_tensorflow/quantsim.py
def check_accumulator_overflow(sess: tf.Session, quant_bw: int, accum_bw: int):
    """
    Checks for any potential for accumulator overflow across all the layers of the given model
    :param sess: Tensorflow session
    :param quant_bw: Bitwidth the layers are quantized at
    :param accum_bw: Bitwidth of the accumulator
    :return: Name of the layer with the most accumulator range used and range used
    """

    most_accum_range_used = 0
    most_accum_range_used_layer = None

    for op in sess.graph.get_operations():
        if op.type == 'Conv2D':
            weights = utils.op.conv.WeightTensorUtils.get_tensor_as_numpy_data(sess, op)
            weights = np.transpose(weights, (3, 2, 0, 1))       # Reshape from HWIO to OIHW
            was_accum_range_exceeded, accum_range_used = get_conv_accum_bounds(weights, quant_bw, accum_bw)
            if accum_range_used > most_accum_range_used:
                most_accum_range_used = accum_range_used
                most_accum_range_used_layer = op.name

            if was_accum_range_exceeded:
                _logger.info('Possible accumulator overflow for layer: %s', op.name)

    if most_accum_range_used < 1:
        _logger.info('No overflow detected. Layer %s had the most accumulator range used: %f%%',
                     most_accum_range_used_layer, most_accum_range_used * 100)
    else:
        _logger.info('Overflow detected. Layer %s had the most accumulator range used: %f%%',
                     most_accum_range_used_layer, most_accum_range_used * 100)

    return most_accum_range_used_layer, most_accum_range_used

    Checks for any potential for accumulator overflow across all the layers of the given model
    :param sess: Tensorflow session
    :param quant_bw: Bitwidth the layers are quantized at
    :param accum_bw: Bitwidth of the accumulator
    :return: Name of the layer with the most accumulator range used and range used
    
Checks for any potential for accumulator overflow across all the layers of the given model
Checks for any potential for accumulator overflow across all the layers of the given model
def check_accumulator_overflow(sess: tf.Session, quant_bw: int, accum_bw: int):
    most_accum_range_used = 0
    most_accum_range_used_layer = None
    for op in sess.graph.get_operations():
        if op.type == 'Conv2D':
            weights = utils.op.conv.WeightTensorUtils.get_tensor_as_numpy_data(sess, op)
            weights = np.transpose(weights, (3, 2, 0, 1))       
            was_accum_range_exceeded, accum_range_used = get_conv_accum_bounds(weights, quant_bw, accum_bw)
            if accum_range_used > most_accum_range_used:
                most_accum_range_used = accum_range_used
                most_accum_range_used_layer = op.name
            if was_accum_range_exceeded:
                _logger.info('Possible accumulator overflow for layer: %s', op.name)
    if most_accum_range_used < 1:
        _logger.info('No overflow detected. Layer %s had the most accumulator range used: %f%%',
                     most_accum_range_used_layer, most_accum_range_used * 100)
    else:
        _logger.info('Overflow detected. Layer %s had the most accumulator range used: %f%%',
                     most_accum_range_used_layer, most_accum_range_used * 100)
    return most_accum_range_used_layer, most_accum_range_used
def check_accumulator_overflow ( sess : tf . Session , quant_bw : int , accum_bw : int ) : most_accum_range_used = 0 most_accum_range_used_layer = None for op in sess . graph . get_operations ( ) : if op . type == 'Conv2D' : weights = utils . op . conv . WeightTensorUtils . get_tensor_as_numpy_data ( sess , op ) weights = np . transpose ( weights , ( 3 , 2 , 0 , 1 ) ) was_accum_range_exceeded , accum_range_used = get_conv_accum_bounds ( weights , quant_bw , accum_bw ) if accum_range_used > most_accum_range_used : most_accum_range_used = accum_range_used most_accum_range_used_layer = op . name if was_accum_range_exceeded : _logger . info ( 'Possible accumulator overflow for layer: %s' , op . name ) if most_accum_range_used < 1 : _logger . info ( 'No overflow detected. Layer %s had the most accumulator range used: %f%%' , most_accum_range_used_layer , most_accum_range_used * 100 ) else : _logger . info ( 'Overflow detected. Layer %s had the most accumulator range used: %f%%' , most_accum_range_used_layer , most_accum_range_used * 100 ) return most_accum_range_used_layer , most_accum_range_used
Checks for any potential for accumulator overflow across all the layers of the given model
Checks for any potential for accumulator overflow across all the layers of the given model
"""
    Checks for any potential for accumulator overflow across all the layers of the given model
    :param sess: Tensorflow session
    :param quant_bw: Bitwidth the layers are quantized at
    :param accum_bw: Bitwidth of the accumulator
    :return: Name of the layer with the most accumulator range used and range used
    """ # Reshape from HWIO to OIHW
Name of the layer with the most accumulator range used and range used
Name of the layer with the most accumulator range used and range used
sess
tf.Session
None
quant_bw
int
Bitwidth the layers are quantized at
Bitwidth the layers are quantized at
accum_bw
int
Bitwidth of the accumulator
Bitwidth of the accumulator