float16 quantization runs out of memory for LSTM model
@yyoon 已经在做这个了。
开始于 2023年8月31日。
评估
这个 Issue 还没有评估数据。
描述
No matter the size of the LSTM model, converting it with float16 optimization runs out of memory.
Code to reproduce the issue
The code snippet to reproduce the issue on Google Colab
Code:
import numpy as np
import tensorflow as tf
import tensorflow_model_optimization as tfmot
def create_model():
model = tf.keras.models.Sequential()
# For the model to later get converted, batch_size and sequence_length should be fixed.
# E.g., batch_input_shape=[None, 1] will throw an error.
# This is just a limitation when using RNNs. E.g., for FC or CNN we can have batch_size=None
model.add(tf.keras.layers.Embedding(
input_dim=5,
output_dim=1,
batch_input_shape=[1, 1]
))
model.add(tf.keras.layers.LSTM(
units=1,
return_sequences=False,
stateful=False
))
model.add(tf.keras.layers.Dense(5))
return model
model = create_model()
model.summary()
model.save("/content/model/")
representative_data = np.random.randint(0, 5, (200, 1)).astype(np.float32)
def representative_dataset():
for sample in representative_data:
sample = np.expand_dims(sample, axis=0) # batch_size = 1
yield [sample] # set sample as first (and only) input of the model
# float16 quantization
converter = tf.lite.TFLiteConverter.from_saved_model("/content/model/")
converter.optimizations = [tf.lite.Optimize.DEFAULT]
converter.target_spec.supported_types = [tf.float16]
# kernel runs out of memory and crashes in the following line
tflite_quant_model = converter.convert()
- 主要语言
- Python
- 星标
- 1.6k
- 派生
- 349
- 平均合并
- 3 天 2 小时
- 30 天内合并 PR
- 1
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
tensorflow/model-optimization 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 74/100
tensorflow/model-optimization#1301 · 1 条评论 ·
-
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
-
agent-ready documentation needs-triage
难度 1/5 1-3 小时 新手友好度 88/100
-
documentation
难度 1/5 1 小时以内 新手友好度 91/100
-
workflow-status page template still says reusable workflows are "triggered only by workflow_call:" 未关闭
难度 1/5 1 小时以内 新手友好度 92/100
-
instance instance add
难度 1/5 1 小时以内 新手友好度 72/100
searxng/searx-instances#939 · 1 条评论 ·
-
area-deployment area-integrations triage:bot-seen
难度 2/5 半天 新手友好度 86/100