intel / neural-compressor

SOTA low-bit LLM quantization (INT8/FP8/INT4/FP4/NF4) & sparsity; leading model compression techniques on TensorFlow, PyTorch, and ONNX Runtime
https://intel.github.io/neural-compressor/
Apache License 2.0
2.14k stars 250 forks source link

AssertionError: Framework is not detected correctly from model format. #61

Closed johnsGuo closed 2 years ago

johnsGuo commented 2 years ago

when I use NIC to Quantization my tensorflow 2.x saved_model, it's occur error:

from neural_compressor.experimental import Quantization, common
quantizer = Quantization()
quantizer.model = "/data/home/dcn3_bt_2/models_new/origin_model"
q_model = quantizer.fit()

output:

2022-03-22 12:39:30 [WARNING] Force convert framework model to neural_compressor model.
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-36-ab40d8ad3e38> in <module>
      1 from neural_compressor.experimental import Quantization, common
      2 quantizer = Quantization()
----> 3 quantizer.model = "/data/home/dcn3_bt_2/models_new/origin_model"
      4 q_model = quantizer.fit()

~/anaconda3/lib/python3.8/site-packages/neural_compressor/experimental/component.py in model(self, user_model)
    358         if not isinstance(user_model, BaseModel):
    359             logger.warning("Force convert framework model to neural_compressor model.")
--> 360             self._model = Model(user_model)
    361         else:
    362             self._model = user_model

~/anaconda3/lib/python3.8/site-packages/neural_compressor/experimental/common/model.py in __new__(cls, root, **kwargs)
     39         """
     40         backend = get_backend()
---> 41         framework = get_model_fwk_name(root)
     42 
     43         if backend == 'engine':

~/anaconda3/lib/python3.8/site-packages/neural_compressor/model/model.py in get_model_fwk_name(model)
    199         if fwk_name != 'NA':
    200             break
--> 201     assert fwk_name != 'NA', 'Framework is not detected correctly from model format.'
    202 
    203     return fwk_name

AssertionError: Framework is not detected correctly from model format.
ftian1 commented 2 years ago

could you let me know which files there are in the folder "/data/home/dcn3_bt_2/models_new/origin_model"?

johnsGuo commented 2 years ago

could you let me know which files there are in the folder "/data/home/dcn3_bt_2/models_new/origin_model"? 链接: https://pan.baidu.com/s/1CyS9u7_2n2f9jd8M51rf9Q 提取码: xdzd

johnsGuo commented 2 years ago

Sorry, The file is too big, I have to use baiduYun Disk, I want to know If use NIC in tensorflow2.x's detail, If need convert the model first?

chensuyue commented 2 years ago

You just need to share us the file name under the origin_model folder.

johnsGuo commented 2 years ago

You just need to share us the file name under the origin_model folder.

image
ftian1 commented 2 years ago

hi, I don't understand why you met issue with this saved model.

I simulated your behavior by manually creating such fake files with same file name in my local. the code is also same with yours. it can identify the framework correctly.

INC code will check if there are 1 or two pb files with variables folder existing or not. it shouldn't raise any error here.

changwangss commented 2 years ago

I copied your model and followed your code to test, the code can pass this model and not raise the issue. could you share your environments? my environment: INC : 1.10.1(the master) python: 3.7 intel-tensorflow: 2.8.0

> /home2/changwa1/inc_for_ipex11/examples/tensorflow/image_recognition/SavedModel/quantization/ptq/main.py(48)run()
-> quantizer.model = self.args.input_graph
(Pdb) p self.args.input_graph
'/home2/changwa1/origin_model'
(Pdb) n
2022-03-22 15:08:38 [WARNING] Force convert framework model to neural_compressor model.
2022-03-22 15:08:39.112233: I tensorflow/core/platform/cpu_feature_guard.cc:151] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 AVX512F FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2022-03-22 15:08:39.119667: I tensorflow/core/common_runtime/process_util.cc:146] Creating new thread pool with default inter op setting:
2022-03-22 15:08:49 [WARNING] Output tensor names should not be empty.
2022-03-22 15:08:49 [WARNING] Input tensor names should not be empty.
> /home2/changwa1/inc_for_ipex11/examples/tensorflow/image_recognition/SavedModel/quantization/ptq/main.py(49)run()
-> q_model = quantizer.fit()
johnsGuo commented 2 years ago
image

I run with jupyter, but in python command it is ok! So, it's the jupyter‘s bug.