Support for Recurrent layers for Quantization Aware Training.
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 25/100
- issue の種類
- 機能追加
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- keras, python, tensorflow
調査の方向性
まず、RNN のサポートが無効になっている default_8bit_quantize_registry.py の 159 行目付近を読み、報告された TensorFlow 2.15 の GRU ケースで quantize_apply の失敗を再現してください。カスタム QuantizeConfig と、その後に発生する H5 保存エラーを調査してください。recurrent layer が quantize_apply を通じてデフォルトの 8-bit 量子化をサポートし、量子化されたモデルを正常に保存できれば完了です。
索引モデルが issue の本文から書いたものです。
説明
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?
- 主要言語
- Python
- スター
- 1.6k
- フォーク
- 348
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
tensorflow/model-optimization のほかの issue
-
Broken pre-optimized models link in getting-started guide対応中かも @itzzdev09 が 20 日前に担当しました。 オープン
難易度 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 が 171 日前に担当しました。 オープンbug
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
tensorflow/model-optimization#1272 ·
-
bug
難易度 3/5 1〜2日 初心者へのやさしさ 50/100
tensorflow/model-optimization#1270 · コメント 2 件 ·
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 48/100
tensorflow/model-optimization#1241 ·
-
bug
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
tensorflow/model-optimization#1182 · コメント 1 件 ·
tensorflow/model-optimization の issue をすべて見る
似ている issue
-
needs-human needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
gke-labs/kube-agents#2400 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Device Details tables: FS/SF columns contradict each other (nfet_01v8 Vt row, pfet_01v8 Idsat row)オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
google/skywater-pdk#450 ·
-
Drained trajectory arrays are overwritten when the sequence buffer is reused対応中かも @sylvesterkaczmarek が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
google-deepmind/bsuite#56 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
LearningCircuit/local-deep-research#7206 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
chingu-voyages/V62-tier3-team-33#285 ·
メンテナーはふだん 1 日以内に返信