quantize_model() rejects a valid standalone Keras 3 Sequential model
@MoeenAsim 已经在做这个了。
开始于 2026年7月28日。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 50/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 冷清
- 技术栈
- python
调研方向
从 tfmot.quantization.keras.quantize_model 和报告中描述的 compat-Keras Sequential 类型检查开始。使用提供的独立 Keras 3 模型和环境重现该故障,然后验证 quantize_model 接受它,或者 API 明确将独立 Keras 3 记录为不受支持。
由索引模型根据 Issue 内容生成。
描述
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
- 主要语言
- Python
- 星标
- 1.6k
- 派生
- 348
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
tensorflow/model-optimization 的其他 Issue
-
Broken pre-optimized models link in getting-started guide可能已有人在做 @itzzdev09 于 27 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 74/100
tensorflow/model-optimization#1301 · 1 条评论 ·
-
tensorflow-model-optimization fails to import in official tensorflow:2.15.0 Docker image due to TF_USE_LEGACY_KERAS=1 and missing tf_keras可能已有人在做 @JiwaniZakir 于 178 天前认领。 未关闭bug
难度 4/5 3-5 天 新手友好度 48/100
tensorflow/model-optimization#1272 ·
-
bug
难度 2/5 1-3 小时 新手友好度 48/100
tensorflow/model-optimization#1241 ·
-
First Conv2D layer in model cannot be pruned with structured sparsity (sparsity_m_by_n)可能重新可做 @shoaib-niazi 于 291 天前认领,目前没有进行中的 PR。 未关闭bug
难度 4/5 3-5 天 新手友好度 35/100
tensorflow/model-optimization#1182 · 1 条评论 ·
-
难度 4/5 3-5 天 新手友好度 35/100
tensorflow/model-optimization#1181 · 1 条评论 ·
查看 tensorflow/model-optimization 的全部 Issue
相似的 Issue
-
area: agents area: docs good first issue
难度 2/5 1-3 小时 新手友好度 88/100
openapi/gknowledge#23 ·
-
get() for StrEnum可能已有人在做 @FeJo5952 今天认领。 未关闭good first issue
难度 2/5 1-3 小时 新手友好度 72/100
collective/icalendar#1921 · 1 条评论 ·
维护者通常 1 天内回复
-
Improvement Python Spans
难度 2/5 1-3 小时 新手友好度 68/100
getsentry/sentry-python#7994 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
alphagov/notifications-api#5004 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
equinor/radix-flux#3922 ·
维护者通常 1 天内回复