optimum icon indicating copy to clipboard operation
optimum copied to clipboard

Quantizing from cli using config file fails

Open jens-f opened this issue 2 years ago • 1 comments

I'm running

onnxruntime quantize --onnx_model ONNX_MODEL --c ort_config.json  -o ONNX_MODEL_quantized

and this fails with

Traceback (most recent call last):
  File "/opt/homebrew/Caskroom/miniconda/base/envs/rag/bin/optimum-cli", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/opt/homebrew/Caskroom/miniconda/base/envs/rag/lib/python3.12/site-packages/optimum/commands/optimum_cli.py", line 163, in main
    service.run()
  File "/opt/homebrew/Caskroom/miniconda/base/envs/rag/lib/python3.12/site-packages/optimum/commands/onnxruntime/quantize.py", line 99, in run
    qconfig = ORTConfig.from_pretained(self.args.config).quantization
              ^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: type object 'ORTConfig' has no attribute 'from_pretained'. Did you mean: 'from_pretrained'?

It looks like there's a typo in quantize.py. But unfortunately, even when fixing the misspelled function name, the command fails:

  File "/opt/homebrew/Caskroom/miniconda/base/envs/rag/lib/python3.12/site-packages/optimum/commands/optimum_cli.py", line 163, in main
    service.run()
  File "/opt/homebrew/Caskroom/miniconda/base/envs/rag/lib/python3.12/site-packages/optimum/commands/onnxruntime/quantize.py", line 102, in run
    q.quantize(save_dir=save_dir, quantization_config=qconfig)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/rag/lib/python3.12/site-packages/optimum/onnxruntime/quantization.py", line 310, in quantize
    use_qdq = quantization_config.is_static and quantization_config.format == QuantFormat.QDQ
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'dict' object has no attribute 'is_static'

After investigating this further, the problem seems to be that the quantize( function is expecting a QuantizationConfig but instead a dict object is supplied. I didn't see a straight forward way how to convert the loaded dict into the required QuantizationConfig

jens-f avatar Apr 27 '24 19:04 jens-f

looking into it !

IlyasMoutawwakil avatar May 22 '24 08:05 IlyasMoutawwakil