tensorflow / tensorflow/model-optimization

Any plans to support keras3?

Open
#1,119 5 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature request
Dominant language
Python
Stars
1.6k
Forks
349
Avg merge
3d 2h
Merged PRs (30d)
1

Description

System information

  • TensorFlow version (you are using): 2.12.0
  • Are you willing to contribute it (Yes/No): Yes

Motivation
Keras3 is the latest version and it supports multiple backends including Pytorch.

Describe the feature

Supporting keras3 when using different tfmot features including quanitization.
Are there any plans to provide support for keras3? and what needs to be done to support it?

Currently running

import keras
import tensorflow_model_optimization as tfmot

fails with


======================================================================
ERROR: test_qat (__main__.KerasImportTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "    import_utils/keras3_import_test.runfiles/nuro/learning/py_utils/import_utils/keras3_import_test.py", line 40, in test_qat
    import learning.quantization.quantize_layers.helper as qat_helper
  File "    import_utils/keras3_import_test.runfiles/nuro/learning/quantization/quantize_layers/helper.py", line 4, in <module>
    import tensorflow_model_optimization as tfmot
  File "    import_utils/keras3_import_test.runfiles/nuro/external/pypi__tensorflow_model_optimization_0_8_0/tensorflow_model_optimization/__init__.py", line 86, in <module>
    from tensorflow_model_optimization.python.core.api import clustering
  File "    import_utils/keras3_import_test.runfiles/nuro/external/pypi__tensorflow_model_optimization_0_8_0/tensorflow_model_optimization/python/core/api/__init__.py", line 16, in <module>
    from tensorflow_model_optimization.python.core.api import clustering
  File "    import_utils/keras3_import_test.runfiles/nuro/external/pypi__tensorflow_model_optimization_0_8_0/tensorflow_model_optimization/python/core/api/clustering/__init__.py", line 16, in <module>
    from tensorflow_model_optimization.python.core.api.clustering import keras
  File "    import_utils/keras3_import_test.runfiles/nuro/external/pypi__tensorflow_model_optimization_0_8_0/tensorflow_model_optimization/python/core/api/clustering/keras/__init__.py", line 19, in <module>
    from tensorflow_model_optimization.python.core.clustering.keras.cluster import cluster_scope
  File "    import_utils/keras3_import_test.runfiles/nuro/external/pypi__tensorflow_model_optimization_0_8_0/tensorflow_model_optimization/python/core/clustering/keras/cluster.py", line 22, in <module>
    from tensorflow_model_optimization.python.core.clustering.keras import cluster_wrapper
  File "    import_utils/keras3_import_test.runfiles/nuro/external/pypi__tensorflow_model_optimization_0_8_0/tensorflow_model_optimization/python/core/clustering/keras/cluster_wrapper.py", line 23, in <module>
    from tensorflow_model_optimization.python.core.clustering.keras import clustering_centroids
  File "    import_utils/keras3_import_test.runfiles/nuro/external/pypi__tensorflow_model_optimization_0_8_0/tensorflow_model_optimization/python/core/clustering/keras/clustering_centroids.py", line 22, in <module>
    from tensorflow_model_optimization.python.core.keras.compat import keras
  File "    import_utils/keras3_import_test.runfiles/nuro/external/pypi__tensorflow_model_optimization_0_8_0/tensorflow_model_optimization/python/core/keras/compat.py", line 41, in <module>
    keras = _get_keras_instance()
  File "    import_utils/keras3_import_test.runfiles/nuro/external/pypi__tensorflow_model_optimization_0_8_0/tensorflow_model_optimization/python/core/keras/compat.py", line 33, in _get_keras_instance
    version_fn = getattr(tf.keras, 'version', None)
  File "    import_utils/keras3_import_test.runfiles/nuro/external/org_tensorflow/tensorflow/python/util/lazy_loader.py", line 58, in __getattr__
    module = self._load()
  File "    import_utils/keras3_import_test.runfiles/nuro/external/org_tensorflow/tensorflow/python/util/lazy_loader.py", line 41, in _load
    module = importlib.import_module(self.__name__)
  File "external/local_config_python/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named 'keras.api'

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the failure in import_utils/keras3_import_test.py and trace the import through quantization/quantize_layers/helper.py and tensorflow_model_optimization/python/core/keras/compat.py. Map which tfmot features, including quantization, need Keras 3 support; done means the import test and the relevant features work with Keras 3 without the shown ModuleNotFoundError.

Written by the indexing model from the issue text.

Assessment

Tech stack
keras, python
Domain
machine-learning
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.