MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / _InsertQuantOp

Function _InsertQuantOp

tensorflow/contrib/quantize/python/quantize.py:664–802  ·  view source on GitHub ↗

Inserts a quant op between a producer op and (multiple) consumer ops. Args: context: Context where producer and consumer operations are nested. name: Name for the new quantization op within the context. producer: Producer operation of the pairs where quantization will be inserte

(context,
                   name,
                   producer,
                   consumers,
                   is_training,
                   per_channel=False,
                   moving_avg=True,
                   init_min=-6.0,
                   init_max=6.0,
                   bits=8,
                   symmetric=False,
                   ema_decay=0.999,
                   quant_delay=None,
                   vars_collection=ops.GraphKeys.GLOBAL_VARIABLES,
                   narrow_range=False,
                   producer_scope=None,
                   consumer_scope=None,
                   use_qdq=False)

Source from the content-addressed store, hash-verified

662
663
664def _InsertQuantOp(context,
665 name,
666 producer,
667 consumers,
668 is_training,
669 per_channel=False,
670 moving_avg=True,
671 init_min=-6.0,
672 init_max=6.0,
673 bits=8,
674 symmetric=False,
675 ema_decay=0.999,
676 quant_delay=None,
677 vars_collection=ops.GraphKeys.GLOBAL_VARIABLES,
678 narrow_range=False,
679 producer_scope=None,
680 consumer_scope=None,
681 use_qdq=False):
682 """Inserts a quant op between a producer op and (multiple) consumer ops.
683
684 Args:
685 context: Context where producer and consumer operations are nested.
686 name: Name for the new quantization op within the context.
687 producer: Producer operation of the pairs where quantization will be
688 inserted.
689 consumers: Consumer operations of the pairs.
690 is_training: Whether quantizing training graph or eval graph.
691 moving_avg: Specifies whether to use exponential moving average or just
692 the last value seen.
693 init_min: Starting minimum value for the new quantization op.
694 init_max: Starting maximum value for the new quantization op.
695 bits: Number of bits to use for quantization, must be between 2 and 8.
696 symmetric: (Optional) If true, use symmetric quantization limits instead of
697 training the minimum and maximum of each quantization range separately.
698 ema_decay: (Optional) Float, EMA decay parameter. EMA is used to update
699 quantization intervals for quantizing activations (see here about EMA:
700 https://en.wikipedia.org/wiki/Moving_average#Exponential_moving_average).
701 quant_delay: (Optional, default None) Int, count of global steps for which
702 to delay quantization. This helps weights stabilize at the start of
703 training.
704 vars_collection: (Optional) Collection where to store the variables for
705 quantization interval ends.
706 narrow_range: Whether to use the narrow quantization range
707 [1; 2^bits - 1] or wide range [0; 2^bits - 1].
708 producer_scope: The restriction of producer scope. If not None, the new op
709 will be inserted only when the producer is in this scope.
710 consumer_scope: The restriction of consumer scope. If not None, the new op
711 will be inserted only when all the consumers are in this scope.
712 Raises:
713 ValueError: When producer operation is not directly connected to the
714 consumer operation.
715 """
716 if producer_scope and not producer.name.startswith(producer_scope):
717 logging.info(
718 '_InsertQuantOp ignores context="%s" name="%s" '
719 'because producer "%s" is not in scope "%s"',
720 context, name, producer.name, producer_scope)
721 return

Callers 2

QuantizeFunction · 0.85

Calls 7

_AddContextToNameFunction · 0.85
_FollowedByFakeQuantFunction · 0.85
infoMethod · 0.80
get_name_scopeMethod · 0.80
appendMethod · 0.45
condMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected