Incorrect inputs reordering inside `ModelTransformer._get_layers` during pattern matchin
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 45/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- keras, python, tensorflow
- Domain
- machine-learning
Research direction
Start at ModelTransformer._match_layer_with_inputs and _get_layers, then run the supplied quantize_model reproduction with the two-input concatenation model. Trace the layer names and returned layers to confirm the declared input order is preserved; done means quantization produces the concatenation inputs in the same order as input_layer_names.
Written by the indexing model from the issue text.
Description
ModelTransformer._match_layer_with_inputs calls self._get_layers(input_layer_names). input_layer_names have strict order, i. e. _get_layers's result in this case must have same order of tensors as in input_layer_names.
Current implementation is:
def _get_layers(self, layer_names):
return [
layer for layer in self._config['layers']
if layer['config']['name'] in layer_names
]
I. e. when first input is declared later than the second one, result would have incorrect order. The simple model to reproduce bug:
import tf_keras as K
import tf_keras.layers as L
a = K.Input(10)
b = L.Dense(10)(a)
c = K.Input(20)
m = K.Model([a, c], L.concatenate([c, b], -1))
Then quantize_model(m) would yield incorrect order for concatenation operation.
My suggestion would be to replace it with something like:
def _get_layers(self, layer_names):
name_to_layer = {layer['config']['name']: layer for layer in self._config['layers']}
return [name_to_layer[name] for name in layer_names]
which preserves order of layer_names
This also seems to be the problem behind #1061
- 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
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
stephrobert/dsoxlab#238 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
sublimehq/package_control#1780 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
nwg-piotr/nwg-displays#145 ·