Skip to content

Conversation

@kaikaiyao
Copy link
Contributor

Type of Change

Feature addition: support Keras script-based model as keras_inc

Description

  • Enabled support of auto-quantizing Keras script-based model
  • Also enabled inc_auto as a default optimization for launcher and for API: our domain detector will detect whether the code is PT/TF/Keras/ONNX and choose default feature accordingly:
    • PyTorch: default dynamic quantization scheme
    • TensorFlow/Keras model based: default TensorFlow quantization scheme
    • Keras script-based: default Keras script-based static quantization scheme
    • ONNX: default dynamic quantization scheme
  • Also enabled "enable_only" -e mode/argument in neural_coder launcher for testing
  • Update docs accordingly

Expected Behavior & Potential Risk

Able to enable INC on Keras script-based model, for example this code

The current enabling pattern design is in accordance with the Keras example which was merged a few days ago, with key detection of model = keras.Sequential(xxx):

from neural_compressor.quantization import fit
from neural_compressor.config import PostTrainingQuantConfig
from neural_compressor.experimental import common
config = PostTrainingQuantConfig(backend='itex')
quantized_model = fit(MODEL_NAME, conf=config, calib_dataloader=DATALOADER_NAME, eval_func=eval_func)

Note that user needs to define a dataloader and eval_func as in the example.

How has this PR been tested?

Locally, can test on any machine with

# installation
git clone https://github.com/intel/neural-compressor.git
cd neural-compressor
git checkout neural_coder_enable_keras
python setup.py develop
cd ..
# test
python -m neural_coder -e neural-compressor/neural_coder/examples/keras/mnist.py

Dependency Change?

None

@kaikaiyao kaikaiyao marked this pull request as ready for review December 15, 2022 05:47
@kaikaiyao
Copy link
Contributor Author

@chensuyue hi Suyue, do you know why these checks are hang? Another PR is also same status. Thanks!

@chensuyue
Copy link
Contributor

/Azurepipeline run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@kaikaiyao kaikaiyao merged commit a456473 into master Dec 16, 2022
@kaikaiyao kaikaiyao deleted the neural_coder_enable_keras branch December 16, 2022 02:40
zehao-intel pushed a commit that referenced this pull request Dec 20, 2022
* Create keras_inc.yaml

* Update model.py

* Create mnist.py

* Update keras_inc.yaml

* Update interface.py

* Update __main__.py

* Update SupportMatrix.md

* Update PythonLauncher.md

* enable inc_auto feature

* Update domain.py

* enable "enable_only" in launcher

* hide remove patch in overwrite=True

Signed-off-by: zehao-intel <zehao.huang@intel.com>
VincyZhang added a commit that referenced this pull request Feb 12, 2023
yiliu30 pushed a commit that referenced this pull request Jul 22, 2025
This was referenced Dec 9, 2025
xin3he pushed a commit that referenced this pull request Jan 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants