Cannot save pruned model with MultiHeadAttention Layer
Nobody has claimed this yet.
Assessment
This issue has not been assessed yet.
Description
Describe the bug
Trying to save a model that wraps a MultiHeadAttention layer in a PruneLowMagnitude, fails with duplicate dataset name.
System information
TensorFlow version (installed from source or binary): 2.13.0rc1
TensorFlow Model Optimization version (installed from source or binary): 0.7.5
Python version: 3.10
Describe the expected behavior
Successful model save.
Describe the current behavior
When saving a pruned model, I get a ValueError: Unable to create dataset (name already exists) on "mask:0".
Code to reproduce the issue
import tensorflow as tf
import tensorflow_model_optimization as tfmot
import tempfile
if __name__ == '__main__':
# model
inputs = tf.keras.layers.Input(shape=(28, 28, 3))
x = tf.keras.layers.Conv2D(filters=128, kernel_size=3, activation='relu')(inputs)
x = tf.keras.layers.MultiHeadAttention(num_heads=4, key_dim=128)(query=x, value=x, key=x)
outputs = tf.keras.layers.Flatten()(x)
model = tf.keras.Model(inputs=inputs, outputs=outputs)
model.compile(optimizer='adam', loss='mse')
# call model to initialize weights
model(tf.ones((1, 28, 28, 3)))
# prune model
pruning_params = {
'pruning_schedule': tfmot.sparsity.keras.PolynomialDecay(
initial_sparsity=0.5,
final_sparsity=0.9,
begin_step=0,
end_step=1,
frequency=1,
),
}
model_for_pruning = tfmot.sparsity.keras.prune_low_magnitude(model, **pruning_params)
with tempfile.TemporaryDirectory() as temp_dir:
model_for_pruning.save(temp_dir + '/model.h5') # <-- fails
Potentially related to #661 and #944.
- Dominant language
- Python
- Stars
- 1.6k
- Forks
- 349
- Avg merge
- 3d 2h
- Merged PRs (30d)
- 1
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from tensorflow/model-optimization
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
tensorflow/model-optimization#1301 · 1 comment ·
-
bug
Difficulty 4/5 3-5 days Newbie friendliness 48/100
tensorflow/model-optimization#1272 ·
-
bug
Difficulty 3/5 1-2 days Newbie friendliness 50/100
tensorflow/model-optimization#1270 · 2 comments ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 48/100
tensorflow/model-optimization#1241 ·
-
bug
Difficulty 4/5 3-5 days Newbie friendliness 35/100
tensorflow/model-optimization#1182 · 1 comment ·
All issues in tensorflow/model-optimization
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 75/100
-
hcocena Openpolicies-accepted pre-review precheck-passed
Difficulty 1/5 Under an hour Newbie friendliness 88/100
Bioconductor/BiocContributions#214 · 5 comments ·
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
TencentCloud/Octop#1169 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
521xueweihan/HelloGitHub#3778 ·
-
The version checker's trailing attribute region has no control for a less-than inside a quoted value Openarea: dashboard area: tests bug perceived difficulty: 2 python
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Nitjsefnie-Harness-Commons/daedalus#1105 · 1 comment ·