sony / mct_quantizers

Apache License 2.0
17 stars 8 forks source link

Fatal Python error: Segmentation fault #68

Closed Chizkiyahu closed 1 year ago

Chizkiyahu commented 1 year ago

When passing negative channel axis to WeightsSymmetricInferableQuantizer and calling the func get_quantized_weights you get an error Fatal Python error: Segmentation fault

Colab link

import tensorflow as tf
from mct_quantizers.keras.quantizers import WeightsSymmetricInferableQuantizer
from mct_quantizers import KerasQuantizationWrapper

def test_per_channel_neg_axis(channel_axis):
    input_shape = (3, 34, 14)
    keras_input = tf.keras.Input(input_shape)
    out = tf.keras.layers.Conv2D(kernel_size=(1, 2), filters=14)
    kwargs = {"num_bits": 8, "threshold": [1.] * 14, "per_channel": True,
              "channel_axis": channel_axis, "input_rank": 4}
    k_q = WeightsSymmetricInferableQuantizer(**kwargs)
    out = KerasQuantizationWrapper(out, weights_quantizers={"kernel": k_q})
    out = out(keras_input)
    model = tf.keras.Model(inputs=keras_input, outputs=out)
    model.layers[1].get_quantized_weights()

test_per_channel_neg_axis(channel_axis=2) # ok
test_per_channel_neg_axis(channel_axis=-2) # Fatal Python error: Segmentation fault

logs

Fatal Python error: Segmentation fault

Thread 0x00000001f7956080 (most recent call first):
  File "/path/to/env/lib/python3.9/site-packages/tensorflow/python/eager/execute.py", line 53 in quick_execute
  File "/path/to/env/lib/python3.9/site-packages/tensorflow/python/ops/gen_array_ops.py", line 11932 in transpose_eager_fallback
  File "/path/to/env/lib/python3.9/site-packages/tensorflow/python/ops/gen_array_ops.py", line 11907 in transpose
  File "/path/to/env/lib/python3.9/site-packages/tensorflow/python/ops/array_ops.py", line 2193 in transpose
  File "/path/to/env/lib/python3.9/site-packages/tensorflow/python/util/dispatch.py", line 1176 in op_dispatch_handler
  File "/path/to/env/lib/python3.9/site-packages/tensorflow/python/util/traceback_utils.py", line 150 in error_handler
  File "/path/to/env/lib/python3.9/site-packages/tensorflow/python/ops/array_ops.py
Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)