quantize_model() rejects a valid standalone Keras 3 Sequential model
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 50/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Quiet
- Tech stack
- python
- Domain
- machine-learning
Research direction
Start with tfmot.quantization.keras.quantize_model and the compat-Keras Sequential type check described in the report. Reproduce the failure with the provided standalone Keras 3 model and environment, then verify that quantize_model accepts it or that the API clearly documents standalone Keras 3 as unsupported.
Written by the indexing model from the issue text.
Description
Describe the bug
tfmot.quantization.keras.quantize_model() rejects a valid standalone Keras 3 keras.Sequential model with:
ValueError: 'to_quantize' can only either be a keras Sequential or Functional model.
This appears to be a compatibility/type-check issue between standalone Keras 3 and TensorFlow Model Optimization Toolkit (TFMOT). The model is a real keras.Sequential instance, but TFMOT does not recognize it as a compatible Sequential model.
System information
TensorFlow version (installed from source or binary):
2.17.0 (installed from binary / pip wheel)
TensorFlow Model Optimization version (installed from source or binary):
0.8.0 (installed from binary / pip wheel)
Python version:
3.11.15
Describe the expected behavior
A valid standalone Keras 3 keras.Sequential model should be accepted by tfmot.quantization.keras.quantize_model() or the API/docs should clearly state that standalone Keras 3 models are unsupported.
Describe the current behavior
A standalone Keras 3 keras.Sequential model is created successfully, but calling:
tfmot.quantization.keras.quantize_model(model)
which primarily raises:
ValueError: 'to_quantize' can only either be a keras Sequential or Functional model.
In the same run:
isinstance(model, keras.Sequential)is True- the model type is
keras.src.models.sequential.Sequential - TFMOT’s compat-Keras type check does not recognize it as compatible
Code to reproduce the issue
import tensorflow as tf
import keras
from keras import layers
import tensorflow_model_optimization as tfmot
model = keras.Sequential(
[
keras.Input(shape=(100,)),
layers.Dense(10, activation="relu"),
layers.Dense(2, activation="sigmoid"),
]
)
print("TF:", tf.__version__)
print("Keras:", keras.__version__)
print("TFMOT:", tfmot.__version__)
print("Model type:", type(model))
print("isinstance(model, keras.Sequential):", isinstance(model, keras.Sequential))
quantized_model = tfmot.quantization.keras.quantize_model(model)
print(quantized_model)
Observed Output:
TF: 2.17.0
Keras: 3.13.2
TFMOT: 0.8.0
Model type: <class 'keras.src.models.sequential.Sequential'>
isinstance(model, keras.Sequential): True
ValueError: `to_quantize` can only either be a keras Sequential or Functional model.
Screenshots
N/A
Additional context
This does not appear to be GPU-specific. The same failure occurs before any actual GPU-dependent computation.
My environment during reproduction:
- keras==3.13.2
- tf_keras==2.17.0
- tensorflow==2.17.0
- tensorflow-model-optimization==0.8.0
- python==3.11.15
I also observed that the model is recognized as a standalone Keras Sequential model, but not as a TFMOT compat-Keras Sequential model. This suggests a type-identity mismatch between standalone Keras 3 and the Keras compatibility layer used inside TFMOT.
Point to be noted:
This looks like a bug in TFMOT type checking rather than a model construction bug in Keras.
More details about my environment:
OS: Linux
Install method: pip wheels
Reproducible: yes
GPU required: no
- Dominant language
- Python
- Stars
- 1.6k
- Forks
- 349
- Avg merge
- 3d 2h
- Merged PRs (30d)
- 1
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from tensorflow/model-optimization
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
tensorflow/model-optimization#1301 · 1 comment ·
-
bug
Difficulty 4/5 3-5 days Newbie friendliness 48/100
tensorflow/model-optimization#1272 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 48/100
tensorflow/model-optimization#1241 ·
-
bug
Difficulty 4/5 3-5 days Newbie friendliness 35/100
tensorflow/model-optimization#1182 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
tensorflow/model-optimization#1181 · 1 comment ·
All issues in tensorflow/model-optimization
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
anthropics/skills#1811 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
speaches-ai/speaches#678 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
datalayer/mcp-compose#42 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
conda-forge/spacy-feedstock#177 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
UKGovernmentBEIS/inspect_evals#2523 ·