TrainingExtensions/tensorflow/src/python/aimet_tensorflow/common/connectedgraph.py
def _link_branch_op_to_multiple_ops(self, branch_op: Op, product_list: list,
                                        is_model_input: bool = False):
        """ Create new product with multiple consumers, linking branch op with children ops"""

        branch_op_product = Product(branch_op.name + '_to_' + 'multiple_ops', branch_op.output_shape)
        branch_op_product.is_model_input = is_model_input
        branch_op_product.producer = branch_op
        branch_op.output = branch_op_product

        # For each product from original op to multiple children, we must:
        # 1: Add each child op as a consumer of the new branch_op_product
        # 2: Append the old product's corresponding tf.Tensor to the new branch op product's tensor_list
        # 3: Add new branch_op_product as input for each child op
        # 4: Remove product from original op to child in child's inputs
        # 5: Remove product from self._products
        for product in product_list:
            assert len(product.consumers) == 1
            # item 1
            branch_op_product.add_consumer(product.consumers[0])
            # item 2
            assert len(product.tensor_dict.keys()) == 1
            branch_op_product.tensor_dict[product.consumers[0]] = product.tensor_dict[product.consumers[0]]
            # items 3 and 4
            # replace the old product with the new branch product, in the same index as the old product
            index = product.consumers[0].inputs.index(product)
            product.consumers[0].inputs[index] = branch_op_product
            # item 5
            del self._products[product.name]

        self._products[branch_op_product.name] = branch_op_product
 Create new product with multiple consumers, linking branch op with children ops
Create new product with multiple consumers, linking branch op with children ops
Create new product with multiple consumers linking branch op with children ops
def _link_branch_op_to_multiple_ops(self, branch_op: Op, product_list: list,
                                        is_model_input: bool = False):
        branch_op_product = Product(branch_op.name + '_to_' + 'multiple_ops', branch_op.output_shape)
        branch_op_product.is_model_input = is_model_input
        branch_op_product.producer = branch_op
        branch_op.output = branch_op_product
        for product in product_list:
            assert len(product.consumers) == 1
            branch_op_product.add_consumer(product.consumers[0])
            assert len(product.tensor_dict.keys()) == 1
            branch_op_product.tensor_dict[product.consumers[0]] = product.tensor_dict[product.consumers[0]]
            index = product.consumers[0].inputs.index(product)
            product.consumers[0].inputs[index] = branch_op_product
            del self._products[product.name]
        self._products[branch_op_product.name] = branch_op_product
def _link_branch_op_to_multiple_ops ( self , branch_op : Op , product_list : list , is_model_input : bool = False ) : branch_op_product = Product ( branch_op . name + '_to_' + 'multiple_ops' , branch_op . output_shape ) branch_op_product . is_model_input = is_model_input branch_op_product . producer = branch_op branch_op . output = branch_op_product for product in product_list : assert len ( product . consumers ) == 1 branch_op_product . add_consumer ( product . consumers [ 0 ] ) assert len ( product . tensor_dict . keys ( ) ) == 1 branch_op_product . tensor_dict [ product . consumers [ 0 ] ] = product . tensor_dict [ product . consumers [ 0 ] ] index = product . consumers [ 0 ] . inputs . index ( product ) product . consumers [ 0 ] . inputs [ index ] = branch_op_product del self . _products [ product . name ] self . _products [ branch_op_product . name ] = branch_op_product
Create new product with multiple consumers, linking branch op with children ops
Create new product with multiple consumers linking branch op with children ops
""" Create new product with multiple consumers, linking branch op with children ops""" # For each product from original op to multiple children, we must: # 1: Add each child op as a consumer of the new branch_op_product # 2: Append the old product's corresponding tf.Tensor to the new branch op product's tensor_list # 3: Add new branch_op_product as input for each child op # 4: Remove product from original op to child in child's inputs # 5: Remove product from self._products # item 1 # item 2 # items 3 and 4 # replace the old product with the new branch product, in the same index as the old product # item 5
self
branch_op
Op
product_list
list
is_model_input
bool