Support for Recurrent layers for Quantization Aware Training.
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Anfängerfreundlichkeit
- 25/100
- Issue-Typ
- Feature
- Klarheit
- Größtenteils klar
- Aktivitätsstatus
- Veraltet
- Tech-Stack
- keras, python, tensorflow
- Bereich
- machine-learning
Rechercherichtung
Beginnen Sie mit dem Lesen von default_8bit_quantize_registry.py etwa ab Zeile 159, wo die RNN-Unterstützung deaktiviert ist, und reproduzieren Sie den quantize_apply-Fehler mit dem gemeldeten TensorFlow-2.15-GRU-Fall. Untersuchen Sie die benutzerdefinierte QuantizeConfig und den anschließenden H5-Speicherfehler. Als abgeschlossen gilt die Aufgabe, wenn rekurrente Layer die standardmäßige 8-Bit-Quantisierung über quantize_apply unterstützen und das quantisierte Modell erfolgreich gespeichert werden kann.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
System information
- TensorFlow version (you are using): 2.15
- Are you willing to contribute it (Yes/No): Yes
Motivation
I am trying to train RNN model with quantization aware training for embedded devices.
Describe the feature
I am looking for a way to train with default 8bit weights & activations quantization using quantize_apply API without passing in custom config.
Describe how the feature helps achieve the use case
Describe how existing APIs don't satisfy your use case (optional if obvious)
I tried to use quantize_apply API but I received this error.
RuntimeError: Layer gru:<class 'keras.src.layers.rnn.gru.GRU'> is not supported. You can quantize this layer by passing a `tfmot.quantization.keras.QuantizeConfig` instance to the `quantize_annotate_layer` API.
After using quantize_annotate_layer, I was able to train the model but Model fails to save with following error:
keras.models.save_model(model, filepath=model_filename, save_format="h5")
Traceback (most recent call last):
File "/workspaces/project-embedded/syntiant-ndp-model-converter/examples/train_audio_model.py", line 169, in <module>
keras.models.save_model(model, filepath=model_filename, save_format="h5")
File "/home/vscode/tf_venv/lib/python3.10/site-packages/keras/src/saving/saving_api.py", line 167, in save_model
return legacy_sm_saving_lib.save_model(
File "/home/vscode/tf_venv/lib/python3.10/site-packages/keras/src/utils/traceback_utils.py", line 70, in error_handler
raise e.with_traceback(filtered_tb) from None
File "/home/vscode/tf_venv/lib/python3.10/site-packages/h5py/_hl/group.py", line 183, in create_dataset
dsid = dataset.make_new_dset(group, shape, dtype, data, name, **kwds)
File "/home/vscode/tf_venv/lib/python3.10/site-packages/h5py/_hl/dataset.py", line 163, in make_new_dset
dset_id = h5d.create(parent.id, name, tid, sid, dcpl=dcpl, dapl=dapl)
File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
File "h5py/h5d.pyx", line 137, in h5py.h5d.create
ValueError: Unable to synchronously create dataset (name already exists)
I used following QuantizeConfig
class GruQuantizeConfig(tfmot.quantization.keras.QuantizeConfig):
# Configure how to quantize weights.
def get_weights_and_quantizers(self, layer):
return [
(
layer.cell.kernel,
LastValueQuantizer(
num_bits=8, symmetric=True, narrow_range=False, per_axis=False
),
),
(
layer.cell.recurrent_kernel,
LastValueQuantizer(
num_bits=8, symmetric=True, narrow_range=False, per_axis=False
),
),
]
# Configure how to quantize activations.
def get_activations_and_quantizers(self, layer):
return [
(
layer.cell.activation,
MovingAverageQuantizer(
num_bits=8, symmetric=False, narrow_range=False, per_axis=False
),
),
(
layer.cell.recurrent_activation,
MovingAverageQuantizer(
num_bits=8, symmetric=False, narrow_range=False, per_axis=False
),
),
]
def set_quantize_weights(self, layer, quantize_weights):
# Add this line for each item returned in `get_weights_and_quantizers`
# , in the same order
layer.cell.kernel = quantize_weights[0]
layer.cell.recurrent_kernel = quantize_weights[1]
def set_quantize_activations(self, layer, quantize_activations):
# Add this line for each item returned in `get_activations_and_quantizers`
# , in the same order.
layer.cell.activation = quantize_activations[0]
layer.cell.recurrent_activation = quantize_activations[1]
# Configure how to quantize outputs (may be equivalent to activations).
def get_output_quantizers(self, layer):
return []
def get_config(self):
return {}
I looked at the source code. It seems that the support for RNN is disabled here for some reason.
I was wondering if this can be enabled back?
- Vorherrschende Sprache
- Python
- Sterne
- 1.6k
- Forks
- 348
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus tensorflow/model-optimization
-
Broken pre-optimized models link in getting-started guideEvtl. vergeben @itzzdev09 hat das vor 35 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
tensorflow/model-optimization#1301 · 1 Kommentar ·
-
tensorflow-model-optimization fails to import in official tensorflow:2.15.0 Docker image due to TF_USE_LEGACY_KERAS=1 and missing tf_kerasEvtl. vergeben @JiwaniZakir hat das vor 186 Tagen übernommen. Offenbug
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 48/100
tensorflow/model-optimization#1272 ·
-
quantize_model() rejects a valid standalone Keras 3 Sequential modelEvtl. wieder frei @MoeenAsim hat das vor 84 Tagen übernommen, und es ist kein Pull Request offen. Offenbug
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 50/100
tensorflow/model-optimization#1270 · 2 Kommentare ·
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 48/100
tensorflow/model-optimization#1241 ·
-
First Conv2D layer in model cannot be pruned with structured sparsity (sparsity_m_by_n)Evtl. wieder frei @shoaib-niazi hat das vor 299 Tagen übernommen, und es ist kein Pull Request offen. Offenbug
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 35/100
tensorflow/model-optimization#1182 · 1 Kommentar ·
Alle Issues in tensorflow/model-optimization
Ähnliche Issues
-
documentation good first issue
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
selimfirat/pysad#379 ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
open-webui/open-webui#32805 ·
Maintainer antworten meist innerhalb von 1 Tag
-
fix: [bug description] HTML CVE metric table shows only the last CVE for each productEvtl. vergeben @Chris-wh233 hat das heute übernommen. Offenbug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 66/100
ossf/cve-bin-tool#5976 ·
Maintainer antworten meist innerhalb von 1 Tag
-
needs-triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
gke-labs/kube-agents#3615 ·
Maintainer antworten meist innerhalb von 1 Tag
-
deferred
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
Maintainer antworten meist innerhalb von 1 Tag