nncf icon indicating copy to clipboard operation
nncf copied to clipboard

AssertionError: Multiple post-hooks for a single NNCFGraph node are not supported!

Open luoyger opened this issue 3 years ago • 6 comments

Load tensorflow saved module exported by tf2, and run nncf compress code below, error occured: AssertionError: Multiple post-hooks for a single NNCFGraph node are not supported!

What's wrong with my code or model ? Is there any suggestion ?

my code to compress tf model:

import tensorflow as tf
from nncf import NNCFConfig
from nncf.tensorflow import create_compressed_model, register_default_init_args

model = tf.keras.models.load_model("../pctr3.2/")
nncf_config = NNCFConfig.from_json("pctr_int8.json")

representative_dataset = tf.data.TFRecordDataset("eval_processed_data.tfrecords")
nncf_config = register_default_init_args(nncf_config, representative_dataset, batch_size=1)

compression_ctrl, compressed_model = create_compressed_model(model, nncf_config)
compression_ctrl.export_model("compressed_model.pb", save_format='frozen_graph')

nncf debug code:

 for post_hook_ip in allowed_post_hook_insertion_points:
            target_node_name_vs_post_hook_ips[post_hook_ip.target_node_name].add(post_hook_ip)
            if len(target_node_name_vs_post_hook_ips[post_hook_ip.target_node_name]) > 1:
                print("post_hook_ip.target_node_name:", post_hook_ip.target_node_name)

logs:

these target_node_name have more than one post_hook_ip

post_hook_ip.target_node_name: dense_input
post_hook_ip.target_node_name: sparse_wgt_input
post_hook_ip.target_node_name: sparse_ids_input
post_hook_ip.target_node_name: seq_50_input
post_hook_ip.target_node_name: Identity
post_hook_ip.target_node_name: args_0
post_hook_ip.target_node_name: args_0_1
post_hook_ip.target_node_name: Identity
post_hook_ip.target_node_name: Identity_1
post_hook_ip.target_node_name: args_0
post_hook_ip.target_node_name: args_0_2
post_hook_ip.target_node_name: args_0_1
post_hook_ip.target_node_name: Identity
post_hook_ip.target_node_name: Identity_1
post_hook_ip.target_node_name: Identity_2
post_hook_ip.target_node_name: Identity_3
post_hook_ip.target_node_name: Identity_4
post_hook_ip.target_node_name: Identity_5
post_hook_ip.target_node_name: Identity_6
post_hook_ip.target_node_name: Identity_7
post_hook_ip.target_node_name: Identity_8
post_hook_ip.target_node_name: Identity_9
post_hook_ip.target_node_name: Identity_10
post_hook_ip.target_node_name: args_0
post_hook_ip.target_node_name: args_0_1
post_hook_ip.target_node_name: Identity
post_hook_ip.target_node_name: args_0
post_hook_ip.target_node_name: args_0_1
post_hook_ip.target_node_name: args_0_4
post_hook_ip.target_node_name: args_0_3
post_hook_ip.target_node_name: args_0_2
post_hook_ip.target_node_name: args_0_5
post_hook_ip.target_node_name: Identity
post_hook_ip.target_node_name: args_0
post_hook_ip.target_node_name: args_0_1
post_hook_ip.target_node_name: Identity
post_hook_ip.target_node_name: args_0
post_hook_ip.target_node_name: args_0_1
post_hook_ip.target_node_name: Identity
post_hook_ip.target_node_name: args_0
post_hook_ip.target_node_name: args_0_1
post_hook_ip.target_node_name: Identity
Traceback (most recent call last):
  File "test_tf.py", line 16, in <module>
    compression_ctrl, compressed_model = create_compressed_model(model, nncf_config)
  File "/root/nncf/nncf/tensorflow/helpers/model_creation.py", line 94, in create_compressed_model
    compressed_model = builder.apply_to(model)
  File "/root/nncf/nncf/tensorflow/api/compression.py", line 62, in apply_to
    transformation_layout = self.get_transformation_layout(model)
  File "/root/nncf/nncf/tensorflow/quantization/algorithm.py", line 393, in get_transformation_layout
    self._quantizer_setup = self._get_quantizer_setup(model)
  File "/root/nncf/nncf/tensorflow/quantization/algorithm.py", line 445, in _get_quantizer_setup
    model)
  File "/root/nncf/nncf/tensorflow/quantization/algorithm.py", line 586, in _get_quantizer_propagation_solution
    [qn.node.node_name for qn in quantizable_weighted_layer_nodes])
  File "/root/nncf/nncf/common/insertion_point_graph.py", line 168, in __init__
    assert len(post_hook_ips) == 1, "Multiple post-hooks for a single NNCFGraph node are not supported!"
AssertionError: Multiple post-hooks for a single NNCFGraph node are not supported!

luoyger avatar Apr 01 '22 12:04 luoyger

@alexsu52 , @negvet , @andrey-churkin , can someone of you investigate it?

MaximProshin avatar Apr 05 '22 15:04 MaximProshin

Same issue here loading a mobilenet v3 small

eolivares avatar Jul 14 '22 11:07 eolivares

Hello @luoyger! The provided code looks pretty good. Could you share with me model and pctr_int8.json file to reproduce on my side?

alexsu52 avatar Jul 28 '22 11:07 alexsu52

Same issue here loading a mobilenet v3 small

Hello @eolivares! What source are you using the mobilenet v3 small model from? Could you provide a link to the model?

alexsu52 avatar Jul 28 '22 12:07 alexsu52

Hello @alexsu52, I am using a custom mobilenet trained from https://tfhub.dev/google/imagenet/mobilenet_v3_small_100_224/classification/5

eolivares avatar Jul 28 '22 14:07 eolivares

Hello @alexsu52, I am using a custom mobilenet trained from https://tfhub.dev/google/imagenet/mobilenet_v3_small_100_224/classification/5

Hello @eolivares,

NNCF does not support the quantization of the tensorflow_hub.KerasLayer, because it contains a compiled graph of the model. I would like to recommend using the same model from the Keras application https://www.tensorflow.org/api_docs/python/tf/keras/applications/mobilenet_v3.

Just for your information,

  • quantization algorithm supports models which are created using Sequential or Functional Keras API and are consisted from the built-in Keras layers.
  • experimental_quantization algorithm supports all types of models, such as sequential, functional, and subclassed models, and supports both built-in Keras layers and custom layers. The only exception is layers that contain already compiled subgraphs such as tensorflow_hub.KerasLayer. Also, note that this algorithm is experimental and some TensorFlow operations may not yet be supported.

alexsu52 avatar Jul 31 '22 14:07 alexsu52